/* * Matrix operand to add a 2D shear matrix to the tail of * the module’s list. */ void Module_shear2D(Module *md, double shx, double shy) { Matrix m; Element *e; Matrix_identity(&m); Matrix_translate2D(&m, shx, shy); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
// Matrix operand to add a 3D translation to the Module. void Module_translate(Module *md, double tx, double ty, double tz) { Matrix m; Element *e; Matrix_identity(&m); Matrix_translate(&m, tx, ty, tz); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
// Matrix operand to add a rotation that orients to the orthonormal axes u,v,w void Module_rotateXYZ(Module *md, Vector *u, Vector *v, Vector *w) { Matrix m; Element *e; Matrix_identity(&m); Matrix_rotateXYZ(&m, u, v, w); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
// Matrix operand to add a 3D scale to the Module. void Module_scale(Module *md, double sx, double sy, double sz) { Matrix m; Element *e; Matrix_identity(&m); Matrix_scale(&m, sx, sy, sz); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
// Matrix operand to add a rotation about the Y-axis to the Module. void Module_rotateY(Module *md, double cth, double sth) { Matrix m; Element *e; Matrix_identity(&m); Matrix_rotateY(&m, cth, sth); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
Foot* Foot_create(GLUquadricObj* qobj, Position pos) { Foot* self = (Foot*)malloc(sizeof(Foot)); float defPos[3] = {0.0, 0.25, -0.6}; self->pos=pos; Element_init((Element*)self, defPos); Element* elem = (Element*)self; elem->onUpdate = Foot_onUpdate; self->list = glGenLists(1); glNewList(self->list, GL_COMPILE); gluCylinder(qobj, 0.5, 0.25, 0.7, 16, 16); glEndList(); return self; }
Hip* Hip_create(GLUquadricObj* qobj) { Hip* self = (Hip*)malloc(sizeof(Hip)); float defPos[3] = {0.0, 0.0, -3.25}; Element_init((Element*)self, defPos); Element* elem = (Element*)self; elem->onUpdate = Hip_onUpdate; self->list = glGenLists(1); glNewList(self->list, GL_COMPILE); gluCylinder(qobj, 2.5, 1.5, 3.0, 16, 16); glEndList(); self->pelvis = Pelvis_create(qobj); Element_addChild(elem, (Element*)self->pelvis); return self; }
Finger4* Finger4_create(GLUquadricObj* qobj, Position pos) { Finger4* self = (Finger4*)malloc(sizeof(Finger4)); self->pos=pos; float defPos[3] = {-0.22, 0.0, -0.8}; if(pos==LEFT) defPos[0]*=-1; Element_init((Element*)self, defPos); Element* elem = (Element*)self; elem->onUpdate = Finger4_onUpdate; self->list = glGenLists(1); glNewList(self->list, GL_COMPILE); gluCylinder(qobj, 0.07, 0.15, 0.8, 16, 16); glEndList(); return self; }
// Adds p to the tail of the module’s list. void Module_circle(Module *md, Circle *c) { Element *e = Element_init(ObjCircle, c); Module_insert(md, e); }
/* * Object that sets the current transform to the identity, * placed at the tail of the module’s list. */ void Module_identity(Module *md) { Matrix m; Matrix_identity(&m); Element *e = Element_init(ObjIdentity, &m); Module_insert(md, e); }
// Adds a pointer to the Module sub to the tail of the module’s list. void Module_module(Module *md, Module *sub) { Element *e = Element_init(ObjModule, sub); Module_insert(md, e); }
Pelvis* Pelvis_create(GLUquadricObj* qobj) { Pelvis* self = (Pelvis*)malloc(sizeof(Pelvis)); float defPos[3] = {0.0, 0.0, 0.0}; Element_init((Element*)self, defPos); Element* elem = (Element*)self; elem->onUpdate = Pelvis_onUpdate; //Créer le bassin self->list = glGenLists(1); glNewList(self->list, GL_COMPILE); //Créer le cercle glBegin(GL_TRIANGLE_FAN); uint32_t i; glVertex3f(0.0, 0.0, 0.0); for(i=0; i < PELVIS_NB_EDGE+1; i++) { float pos[] = {PELVIS_RADIUS*(float)cos(i*2*PI/PELVIS_NB_EDGE), PELVIS_RADIUS*(float)sin(i*2*PI/PELVIS_NB_EDGE), 0.0f}; glVertex3f(pos[0], pos[1], pos[2]); } glEnd(); //Créer le rectangle glBegin(GL_POLYGON); glVertex3f(0.25, -0.5, -1.0); glVertex3f(-0.25, -0.5, -1.0); glVertex3f(-0.25, 0.5, -1.0); glVertex3f(0.25, 0.5, -1.0); glEnd(); //Les relier. Le rectangle créera un défaut au niveau de ses coins (car ce n'est pas un cercle) glBegin(GL_QUADS); for(i=0; i < PELVIS_NB_EDGE+1; i++) { float pos1[] = {PELVIS_RADIUS*(float)cos(i*2*PI/PELVIS_NB_EDGE), PELVIS_RADIUS*(float)sin(i*2*PI/PELVIS_NB_EDGE), 0.0f}; float pos2[] = {PELVIS_RADIUS*(float)cos((i+1)*2*PI/PELVIS_NB_EDGE), PELVIS_RADIUS*(float)sin((i+1)*2*PI/PELVIS_NB_EDGE), 0.0f}; float pos3[3]; float pos4[3]; if(i == PELVIS_NB_EDGE/4) { pos3[0] = 0.25; pos3[1] = 0.5; pos3[2] = -1.0; pos4[0] = -0.25; pos4[1] = 0.5; pos4[2] = -1.0; } else if(i==3*PELVIS_NB_EDGE/4) { pos4[0] = 0.25; pos4[1] = -0.5; pos4[2] = -1.0; pos3[0] = -0.25; pos3[1] = -0.5; pos3[2] = -1.0; } else if(i < PELVIS_NB_EDGE/4 || i > 3*PELVIS_NB_EDGE/4) { pos3[0] = -0.25; if(i == 3*PELVIS_NB_EDGE/4+1) pos3[1] = 0.5; else pos3[1] = pos2[1]*1.0/PELVIS_RADIUS; pos3[2] = -1.0; pos4[0] = -0.25; if(i == PELVIS_NB_EDGE/4-1) pos4[1] = 0.5; else pos4[1] = pos1[1]*1.0/PELVIS_RADIUS; pos4[2] = -1.0; } else { pos3[0] = 0.25; if(i==PELVIS_NB_EDGE/4+1) pos3[1]=-0.5; else pos3[1] = pos2[1]*1.0/PELVIS_RADIUS; pos3[2] = -1.0; pos4[0] = 0.25; if(i==3*PELVIS_NB_EDGE/4-1) pos4[1] = -0.5; else pos4[1] = pos1[1]*1.0/PELVIS_RADIUS; pos4[2] = -1.0; } glVertex3f(pos1[0], pos1[1], pos1[2]); glVertex3f(pos2[0], pos2[1], pos2[2]); glVertex3f(pos3[0], pos3[1], pos3[2]); glVertex3f(pos4[0], pos4[1], pos4[2]); } glEnd(); glEndList(); self->rightThigh = Thigh_create(qobj, RIGHT); self->leftThigh = Thigh_create(qobj, LEFT); Element_addChild(elem, (Element*)self->leftThigh); Element_addChild(elem, (Element*)self->rightThigh); return self; }
void Module_texture(Module *md, Texture *tex) { Element *e = Element_init(ObjTexture, tex); Module_insert(md, e); }
// Adds the surface color value to the tail of the module’s list. void Module_surfaceColor(Module *md, Color *c) { Element *e = Element_init(ObjSurfaceColor, c); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_point(Module *md, Point *p) { Element *e = Element_init(ObjPoint, p); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_polygon(Module *md, Polygon *p) { Element *e = Element_init(ObjPolygon, p); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_polyline(Module *md, Polyline *p) { Element *e = Element_init(ObjPolyline, p); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_line(Module *md, Line *l) { Element *e = Element_init(ObjLine, l); Module_insert(md, e); }
// Adds the body color value to the tail of the module’s list. void Module_bodyColor(Module *md, Color *c) { Element *e = Element_init(ObjBodyColor, c); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_sphere(Module *md, Sphere *s) { Element *e = Element_init(ObjSphere, s); Module_insert(md, e); }
// Adds the specular coefficient to the tail of the module’s list. void Module_surfaceCoeff(Module *md, float coeff) { Element *e = Element_init(ObjSurfaceCoeff, &coeff); Module_insert(md, e); }
// Adds p to the tail of the module’s list. void Module_plane(Module *md, Plane *p) { Element *e = Element_init(ObjPlane, p); Module_insert(md, e); }