NeHe Tutorials OpenGL
 X5. OpenGL

. Visual Studio Professional 2010. , Visual Studio, 7- .

 

LessonsGLCode_2010 X5 LessonX5 BoxMan, X5_BoxManDrawInit.cpp.

 

, InitGL:

 

int InitGL_X5(GLvoid) // All Setup For OpenGL Goes Here

{

CheckMyDir();

 

glShadeModel(GL_SMOOTH); // Enable Smooth Shading

glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //Black Background

glClearDepth(1.0f); //Depth Buffer Setup

glEnable(GL_DEPTH_TEST); // Enables Depth Testing

glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

 

quadric=gluNewQuadric(); // // Lesson 18

gluQuadricNormals(quadric, GLU_SMOOTH); // // Lesson 18

gluQuadricTexture(quadric, GL_TRUE); // // Lesson 18

 

//TestMessageBox("InitGL_X5\n1\n");

m_pCurCamera = new CMyCamera;

m_pCurCamera->SetCamera(Vector_3D(0, 3,20), Vector_3D(0, 0, 0), Vector_3D(0, 1, 0));

LightPosition[0]= 10;

LightPosition[1]= 100;

LightPosition[2]= 50;

glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);

IitLight1();

OpenGLSceneFmTxtFile("BoxData/Ring.txt");

OpenGLSceneFmTxtFile("BoxData/BoxMan.txt");

 

CMyGLObject * pGl = GetGLObjectOfNameGL("BoxMan");

if(pGl != NULL)

{

m_pBoxMan = pGl;

CMyAction * pA = new CMyAction;

pA->m_Name = "Step";

for(int i = 0; i < 4; i++)

pA->AppendSceneFmFile("BoxData/Step_" + strFormat("%02d.txt",i+1));

pGl->m_actionList.AddTail(pA);

pGl->m_pCurAction = pA;

 

pA = new CMyAction;

pA->m_Name = "rStraight";

for(int i = 0; i < 2; i++)

pA->AppendSceneFmFile("BoxData/rStraight_" + strFormat("%02d.txt",i+1));

pGl->m_actionList.AddTail(pA);

 

pA = new CMyAction;

pA->m_Name = "lStraight";

for(int i = 0; i < 2; i++)

pA->AppendSceneFmFile("BoxData/lStraight_" + strFormat("%02d.txt",i+1));

pGl->m_actionList.AddTail(pA);

 

pA = new CMyAction;

pA->m_Name = "lKick";

for(int i = 0; i < 3; i++)

pA->AppendSceneFmFile("BoxData/lKick_" + strFormat("%02d.txt",i+1));

pGl->m_actionList.AddTail(pA);

 

pA = new CMyAction;

pA->m_Name = "rKick";

for(int i = 0; i < 3; i++)

pA->AppendSceneFmFile("BoxData/rKick_" + strFormat("%02d.txt",i+1));

pGl->m_actionList.AddTail(pA);

 

}

scaleValue = 1.0;

return TRUE; // Initialization Went OK

}

 

BoxData/Ring.txt BoxData/BoxMan.txt OpenGLSceneFmTxtFile.

 

, . BoxData/BoxMan.txt, :

 

<GLObject>

<style>SPHERE_OBJ

<name> <Left_Shoulder_Joint>

<pos> 0.00 2.30 -1.50

<ang> 4.00 0.00 4.00

<angMin> -40.00 0.00 0.00

<angMax> 180.00 0.00 180.00

<cfnt> 1.00 1.00 1.00

<lbh> 0.50 0.50 0.50

<Material>

<ambient> 0.25 0.25 0.25 0.80

<diffuse> 0.50 0.50 0.00 1.00

<specular> 0.00 0.00 0.00 0.00

<emission> 0.20 0.20 0.20 0.00

<shininess> 1.00

<numChilds> 1

<GLObject>

<style>CYLINDER_OBJ

<name> <Forearm>

<pos> 0.00 -1.30 0.00

<ang> 0.00 90.00 0.00

<angMin> 0.00 0.00 0.00

<angMax> 0.00 0.00 0.00

<cfnt> 1.00 1.00 1.00

<lbh> 0.40 1.50 1.50

<Material>

<ambient> 0.25 0.25 0.25 0.80

<diffuse> 0.50 0.50 0.00 1.00

<specular> 0.00 0.00 0.00 0.00

<emission> 0.20 0.20 0.20 0.00

<shininess> 1.00

<numChilds> 1

<GLObject>

<style>SPHERE_OBJ

<name> <Ulnar_Joint>

<pos> 0.00 -0.70 0.00

<ang> 0.00 0.00 0.00

<angMin> -150.00 0.00 -150.00

<angMax> 0.00 0.00 0.00

<cfnt> 1.00 1.00 1.00

<lbh> 0.50 0.50 0.50

<Material>

<ambient> 0.25 0.25 0.25 0.80

<diffuse> 0.50 0.50 0.00 1.00

<specular> 0.00 0.00 0.00 0.00

<emission> 0.20 0.20 0.20 0.00

<shininess> 1.00

<numChilds> 1

<GLObject>

<style>CYLINDER_OBJ

<name> <Arm>

<pos> 0.00 -1.30 0.00

<ang> 0.00 0.00 0.00

<angMin> 0.00 0.00 0.00

<angMax> 0.00 0.00 0.00

<cfnt> 1.00 1.00 1.00

<lbh> 0.40 1.50 1.50

<Material>

<ambient> 0.25 0.25 0.25 0.80

<diffuse> 0.50 0.50 0.00 1.00

<specular> 0.00 0.00 0.00 0.00

<emission> 0.20 0.20 0.20 0.00

<shininess> 1.00

<numChilds> 1

<GLObject>

<style>SPHERE_OBJ

<name> <Fist>

<pos> 0.00 -1.00 0.00

<ang> 0.00 90.00 0.00

<angMin> 0.00 0.00 0.00

<angMax> 0.00 0.00 0.00

<cfnt> 1.00 1.00 1.00

<lbh> 0.70 0.70 0.70

<Material>

<ambient> 0.25 0.25 0.25 0.80

<diffuse> 0.25 0.00 0.00 1.00

<specular> 0.00 0.00 0.00 0.00

<emission> 0.20 0.20 0.20 0.00

<shininess> 1.00

<numChilds> 0

</GLObject><Fist>

</GLObject><Arm>

</GLObject><Ulnar_Joint>

</GLObject><Forearm>

</GLObject><Left_Shoulder_Joint>

 

, .

 

AppendSceneFmFile . , 3- BoxData/rKick_01.._03.

 

BoxData/ rKick_02.txt, o :

 

<name> <Left_Shoulder_Joint>

<pos> 0.00 2.30 -1.50

<ang> 23.00 0.00 23.00

<numChilds> 1

<name> <Forearm>

<pos> 0.00 -1.30 0.00

<ang> 0.00 90.00 0.00

<numChilds> 1

<name> <Ulnar_Joint>

<pos> 0.00 -0.70 0.00

<ang> -150.00 0.00 0.00

<numChilds> 1

<name> <Arm>

<pos> 0.00 -1.30 0.00

<ang> 0.00 0.00 0.00

<numChilds> 1

<name> <Fist>

<pos> 0.00 -1.00 0.00

<ang> 0.00 90.00 0.00

<numChilds> 0

 

.. .

 

, DrawGLScene:

 

int DrawGLScene_X5(GLvoid) // Here's Where We Do All The Drawing

{

glDisable(GL_LIGHTING);

glTranslatef(0, 0, -30); // Move Into The Screen 30.0

int nCount = 0;

for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL; nCount++)

{

CMyGLObject * pGl = (CMyGLObject*)m_glObjList.GetNext(pos);

pGl->drawGLObject();

 

}//for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL;)

if(m_bRot) yrot+=0.2f; // Lesson 06

return TRUE; // Everything Went OK

}

 

m_glObjList , CMyGLObject. :

 

class CMyGLObject : public CObject //

{

public:

CMyGLObject();

virtual ~CMyGLObject();

Vector_3D pos; //

Vector_3D vel; //

Vector_3D ang; //

Vector_3D angMin; // .

Vector_3D angMax; // .

 

 

Vector_3D rot; //

Vector_3D lbh; //

Vector_3D cfnt; //

GLUquadricObj *m_pQuad; // .

CPlaneBox * m_pBx; // , 蠠

int m_style; // (, , )

CMaterial material; //

int m_frame; //

BOOL m_bHit; //

int m_nTick; //

 

CString m_NameGL; // -

CString m_NameGLrus; // -

 

Matrix m_glMatrix; //

 

CMyGLObject * m_pParentGL; //

 

CObList m_glObjectList; //

CObList m_actionList; //

CObList m_actionStack; //

CMyAction * m_pCurAction; //

int m_nScene; //

 

:

 

void CMyGLObject::drawGLObject( void)

{

 

glMatrixMode( GL_MODELVIEW );

glPushMatrix();

BOOL B_DEPTH_TEST = glIsEnabled(GL_DEPTH_TEST);

BOOL B_LIGHTING = glIsEnabled(GL_LIGHTING);

BOOL B_AUTO_NORMAL = glIsEnabled(GL_AUTO_NORMAL);

BOOL B_BLEND = glIsEnabled(GL_BLEND);

BOOL B_TEXTURE_2D = glIsEnabled(GL_TEXTURE_2D);

 

glEnable(GL_DEPTH_TEST);

glEnable(GL_LIGHTING);

glEnable(GL_AUTO_NORMAL);

glEnable(GL_NORMALIZE);

 

 

::glTranslatef( pos.x, pos.y, pos.z);

::glRotatef(ang.y , 0.0f, 1.0f, 0.0f);

::glRotatef(ang.x, 1.0f, 0.0f, 0.0f);

::glRotatef(ang.z , 0.0f, 0.0f, 1.0f);

glScalef(cfnt.x, cfnt.y, cfnt.z);

glColor3f(1,1,1);

material.SetMaterial(GL_FRONT_AND_BACK);

::glGetFloatv(GL_MODELVIEW_MATRIX, &m_glMatrix.x[0][0]);

drawObjectOfType();

 

B_BLEND ? glEnable(GL_BLEND): glDisable(GL_BLEND) ;

B_DEPTH_TEST ? glEnable(GL_DEPTH_TEST): glDisable(GL_DEPTH_TEST) ;

B_LIGHTING ? glEnable(GL_LIGHTING): glDisable(GL_LIGHTING) ;

B_AUTO_NORMAL ? glEnable(GL_AUTO_NORMAL): glDisable(GL_AUTO_NORMAL) ;

B_TEXTURE_2D ? glEnable(GL_TEXTURE_2D): glDisable(GL_TEXTURE_2D) ;

 

for(POSITION pos = m_glObjectList.GetHeadPosition(); pos != NULL;)

{

CMyGLObject * pGl = (CMyGLObject *)m_glObjectList.GetNext(pos);

pGl->m_pParentGL = this;

pGl->drawGLObject();

}//for(position pos = m_glObjectList.GetHeadPosition(); pos != NULL;)

 

glMatrixMode( GL_MODELVIEW );

glPopMatrix();

}

 

::glTranslatef, ::glRotatef, glScalef , , CMyGLObject::drawGLObject. OpenGL .

 

Update_X5:

 

void Update_X5(DWORD milliseconds)

{

 

if(!m_Cadr)

for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL; )

{

CMyGLObject * pGl = (CMyGLObject*)m_glObjList.GetNext(pos);

pGl->NextGLScene();

}//for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL;)

m_Cadr++;

m_Cadr %= MAX_CADR;

 

for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL; )

{

CMyGLObject * pGl = (CMyGLObject*)m_glObjList.GetNext(pos);

pGl->UpdateCadr();

}//for(POSITION pos = m_glObjList.GetHeadPosition(); pos != NULL;)

 

 

}

25 (MAX_CADR) , , .

 

, , , . BoxData, , , BoxMan.

 

, X4, .

 

 

LessonsCode_2010.7z (5.09 Mb)


petrov@msun.ru

PMG  17 2013