|
|
????????????????? http://blog.csdn.net/hardVB/archive/2005/08/10/449922.aspx
????????????????
?????????????????????????????????????????????????????????????????
???????VC6.0?OpenGL????????

?????
????????OpenGL?????????????????????????????
???????????c++??,????????????????????????????
?????
????3D????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????poser 5.0????????3d max ???????????3ds??????????????????3d max???????????????????????????3ds?????????????????????????????????????????????(body)???????????3ds???????:
???? BODY.3DS
?? HEAD.3DS
?? LSHOULDER.3DS
?? RSHOULDER.3DS
??? LELBOW.3DS
??? RELBOW.3DS
??? LTHIGH.3DS
??? RTHIGH.3DS
??? LFEET.3DS
??? RFEET.3DS
????????????????????????
???????????????
???????????????????????????????????
??ID
??????????r_x,r_y,r_z
??????????????????????????????PID,CID
????????????????????
??3ds?????file_name_3ds
3ds??????????????????????????????????????????????????????????????? (-0.2,-1,0)
?????????:
class bone
{
public:
int y;
int x;
int r_z; //????z??
int r_y;
int r_x;
int rotated_X; //??????
int rotated_Y;
int is_marked; //??????
int PID; //???
int CID; //????????????????
float start_arc_x,end_arc_x; //??????x ??????????
float start_arc_y,end_arc_y; //??????y ??????????
float start_arc_z,end_arc_z; //??????z ??????????
double LengthRatio;
char name[80]; //??
char file_name_3ds[180]; //3ds????
int ID;
bone(int ID,char *name,int PID);
virtual ~bone();
float bone_init_x,bone_init_y,bone_init_z; //??????????,3d max ??
};
???????????
????bone????????????skeleton?????????????????
obone = bone (2,"head",1); //????bone
strcpy(obone.file_name_3ds,"head.3DS"); //????3ds???
obone.bone_init_x = 0; //??????????
obone.bone_init_y = 1;
obone.bone_init_z = 0;
bonevec.push_back (obone); //??vector??,?????STL??????vector
???????????
skelecton::skelecton()
{
float fy = 0.56f ;
float ftx = 0.19f;
float ffx = 0.08f;
bone obone = bone (1,"neck",0);
bonevec.push_back (obone);
obone = bone (2,"head",1);
strcpy(obone.file_name_3ds,"head.3DS");
obone.bone_init_x = 0;
obone.bone_init_y = 1;
obone.bone_init_z = 0;
bonevec.push_back (obone);
obone = bone (3,"rShoulder",1);
bonevec.push_back (obone);
obone = bone (4,"lShoulder",1);
bonevec.push_back (obone);
obone = bone (5,"rElbow",3);
strcpy(obone.file_name_3ds,"rShoulder.3DS");
obone.bone_init_x = fy;
obone.bone_init_y = -1;
obone.bone_init_z = 0;
obone.CID = 7;
bonevec.push_back (obone);
obone = bone (6,"lElbow",4);
strcpy(obone.file_name_3ds,"lShoulder.3DS");
obone.bone_init_x = -fy;
obone.bone_init_y = -1;
obone.bone_init_z = 0;
obone.CID = 8;
bonevec.push_back (obone);
//.............??????????..........................
}
??????3ds????CLoad3DS???????????
??????????????CLoad3DS??????????open source??????http://scourge.sourceforge.net
http://scourge.sourceforge.net/api/3ds_8h-source.html
??????????????????????????????????????????
??????OpenGL?????????????????
CLoad3DS* m_3ds;
int OpenGL: oad3DS(int ID, char *filename)
{
if(m_3ds!=NULL) m_3ds->Init(filename,ID);
return 0;
}
?????????
int OpenGL::show3ds(int ID)
{
m_3ds->show3ds(ID,0,0,0,2);
return 0;
}
?????????????????
???????????????????????????????????????????????
????????????
?????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????openGL???glPushMatrix();glPopMatrix();?????????????????glPushMatrix();glPopMatrix();???????
//????3d??
int skelecton::Render_skeleton_3D(int ID)
{
glPushMatrix(); //??????
joint_point = pgl->get_joint_point(ID); //??????
glTranslatef(joint_point.x,joint_point.y,joint_point.z); //????????
pgl->rotate_bone (vt1,vt2,vto); //??????????
glTranslatef(-joint_point.x,-joint_point.y,-joint_point.z);//?????
pgl->show3ds(ID); //????
//?????
for (theIterator = bonevec.begin(); theIterator != bonevec.end();
theIterator++)
{
pbone = theIterator;
if((pbone-> ID == ID) )
{
Render_skeleton_3D(pbone->ID); //????
}
}
glPopMatrix(); //??????
}
????????????????????
???????
???????? get_joint_point(ID)???????????????????????????????????????????????????????????????????????????????????????????????,??????????????????Cload3ds????????
Vector3f CLoad3DS::get_joint_point(int j0)
{
CVector3 LastPoint;
Vector3f vect;
LastPoint.y = -1000 ;
if(j0==2) LastPoint.y = 1000 ;//??????
// ??????????
for(int l = 0; l < g_3DModel[j0].numOfObjects; l++)
{if(g_3DModel[j0].pObject.size() <= 0) break;// ?????????0????
t3DObject *pObject = &g_3DModel[j0].pObject[l];// ?????????
for(int j = 0; j < pObject->numOfFaces; j++) // ??????
{
for(int tex = 0; tex < 3; tex++) // ?????????
{
int index = pObject->pFaces[j].vertIndex[tex]; // ??????????
if(j0==2)
{
if(pObject->pVerts[index].y < LastPoint.y )
LastPoint = pObject->pVerts[index];
}
else
{
if(pObject->pVerts[index].y > LastPoint.y )
LastPoint = pObject->pVerts[index];
}
}
}
}
vect.x = LastPoint.x ;
vect.y = LastPoint.y ;
vect.z = LastPoint.z ;
return vect;
}
?????????????????????????????
?????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????,???????????????????????????????????????????????????????????http://www.gameres.com/Articles/Program/Visual/Other/shiliang.htm
???????????????????????????????????????????????????????????????????????????????????????????????
int OpenGL::rotate_bone(Vector3f vVector1, Vector3f vVector2, Vector3f vVectorOrgin)
{
Vector3f vt1 = Vector3f(vVector1.x,vVector1.y,vVector1.z);
Vector3f vt2 = Vector3f(vVector2.x,vVector2.y,vVector2.z);
Vector3f vt4 = vt2-vt1;
double arc12 = AngleBetweenVectors(vVectorOrgin,vt4);
double rarc12 = 180*arc12/pi;
float len= Distance(vt1,vt2);
Vector3f vt3 = Cross(vVectorOrgin,vt4);
glRotatef ((float)rarc12,vt3.x,vt3.y,vt3.z);
return 0;
}
???????????????????????????????????????????????????????????????????????????????????????????
?????
|
|