游戏开发论坛

 找回密码
 立即注册
搜索
查看: 5972|回复: 5

????????????????

[复制链接]

52

主题

155

帖子

160

积分

注册会员

Rank: 2

积分
160
发表于 2005-8-11 12:39:00 | 显示全部楼层 |阅读模式
????????????????? 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-&gtID == 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;

}

???????????????????????????????????????????????????????????????????????????????????????????

?????


89

主题

4036

帖子

4132

积分

论坛元老

Rank: 8Rank: 8

积分
4132
发表于 2005-8-11 22:54:00 | 显示全部楼层

Re:????????????????

????

52

主题

155

帖子

160

积分

注册会员

Rank: 2

积分
160
 楼主| 发表于 2005-8-16 13:27:00 | 显示全部楼层

Re:????????????????

???????????
????????????????
http://pickup.mofile.com/6046027775229542

2

主题

4

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2009-9-24 00:03:00 | 显示全部楼层

Re:????????????????

??????

28

主题

73

帖子

73

积分

注册会员

Rank: 2

积分
73
发表于 2009-10-24 22:39:00 | 显示全部楼层

Re:????????????????

????

4

主题

33

帖子

33

积分

注册会员

Rank: 2

积分
33
发表于 2009-10-25 13:30:00 | 显示全部楼层

Re:????????????????

MARK
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-17 13:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表