I've been trying to build a structure that can define 3D models made of 3 point polygons and figure out the position of all of the vertices during rotations and movements. It can only rotate on the Y and Z axis, I'm not sure how I would go about making it rotate on an axis defined by any two points yet. Am I heading down the right path here, I'm not really sure how too render in directX or openGL yet so I'm not sure if this would be compatible.
Code:
#include "math.h"
#include "stdlib.h"
const double PI = 3.14159265358979;
typedef struct Tvertice{
float x;
float y;
float z;
} Tvertice;
typedef struct Tpos{
float x;
float y;
float z;
} Tpos;
typedef struct Tvector{
unsigned int x;
unsigned int y;
unsigned int z;
} Tvector;
typedef struct Tpolygon{
Tvertice vertice[3];
} Tpolygon;
typedef struct Trender{
Tvertice vertice[3];
} Trender;
typedef struct Tobject{
Tpolygon polygon[100];
Tpos pos;
Tvector vector;
float spinZ;
float spinY;
float spinvZ;
float spinvY;
Trender render[100];
} Tobject;
Tobject object;
float timeinterval;
int moveobject(void){
int ctr;
int ctr1;
object.vector.x = (object.vector.x)*(timeinterval);
object.vector.y = (object.vector.y)*(timeinterval);
object.vector.z = (object.vector.z)*(timeinterval);
object.spinvY = (object.spinvY)*(timeinterval);
object.spinvZ = (object.spinvZ)*(timeinterval);
object.pos.x = object.pos.x + object.vector.x;
object.pos.y = object.pos.y + object.vector.y;
object.pos.z = object.pos.z + object.vector.z;
object.spinZ = fmod(float (object.spinZ + object.spinvZ), float (2*PI));
object.spinY = fmod(float (object.spinY + object.spinvY), float (2*PI));
for(ctr= 0; ctr<100; ctr++)
{
for(ctr1 = 0; ctr1 <3; ctr1 ++)
{
object.render[ctr].vertice[ctr1].x = (((object.polygon[ctr].vertice[ctr1].x)(cos(object.spinZ)))-(object.polygon[ctr].vertice[ctr1].y(sin(object.spinZ)))+(object.pos.x));
object.render[ctr].vertice[ctr1].y = (((object.polygon[ctr].vertice[ctr1].x)(sin(object.spinZ)))+(object.polygon[ctr].vertice[ctr1].y(cos(object.spinZ)))+(object.pos.y));
object.render[ctr].vertice[ctr1].z = (((object.polygon[ctr].vertice[ctr1].x)(sin(object.spinY)))+(object.polygon[ctr].vertice[ctr1].z(cos(object.spinY)))+(object.pos.z));
}
}
}