• Advertisement
Sign in to follow this  

shadow for ms3d file format

This topic is 3872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi ///////////////////////////////////////////////////////////////////// I have this class for ms3d models : ///////////////////////////////////////////////////////////////////// class Model { public: double m_totalFrames,m_FPS; // Mesh struct Mesh { int m_materialIndex; int m_numTriangles; int *m_pTriangleIndices; }; // Material properties struct Material { float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4]; float m_shininess; GLuint m_texture; char *m_pTextureFilename; }; // Triangle structure struct Triangle { float m_vertexNormals[3][3]; float m_s[3], m_t[3]; int m_vertexIndices[3]; }; // Vertex structure struct Vertex { char m_boneID; // for skeletal animation float m_location[3]; }; // { NEW } // Animation keyframe information struct Keyframe { int m_jointIndex; float m_time; // in milliseconds float m_parameter[3]; }; // Skeleton bone joint struct Joint { float m_localRotation[3]; float m_localTranslation[3]; Matrix m_absolute, m_relative; int m_numRotationKeyframes, m_numTranslationKeyframes; Keyframe *m_pTranslationKeyframes; Keyframe *m_pRotationKeyframes; int m_currentTranslationKeyframe, m_currentRotationKeyframe; Matrix m_final; int m_parent; }; // { end NEW } public: /* Constructor. */ Model(); /* Destructor. */ virtual ~Model(); /* Load the model data into the private variables. filename Model filename */ virtual bool loadModelData( const char *filename ) = 0; /* Draw the model. */ void draw(int start_f,int end_f,bool looping); /* Called if OpenGL context was lost and we need to reload textures, display lists, etc. */ void reloadTextures(); protected: // { NEW } /* Set the values of a particular keyframe for a particular joint. jointIndex The joint to setup the keyframe for keyframeIndex The maximum number of keyframes time The time in milliseconds of the keyframe parameter The rotation/translation values for the keyframe isRotation Whether it is a rotation or a translation keyframe */ void setJointKeyframe( int jointIndex, int keyframeIndex, float time, float *parameter, bool isRotation ); /* Setup joint matrices. */ void setupJoints(); /* Set looping factor for animation. *///--<i changed it move from protukted to pablic(by sadegh) void setLooping( bool looping ) { m_looping = looping; } /* Advance animation by a frame. */ void advanceAnimation(int start_f ,int end_f,bool looping); /* Restart animation. */ void restart(); // { end NEW } protected: // Meshes used int m_numMeshes; Mesh *m_pMeshes; // Materials used int m_numMaterials; Material *m_pMaterials; // Triangles used int m_numTriangles; Triangle *m_pTriangles; // Vertices Used int m_numVertices; Vertex *m_pVertices; // { NEW } // Joint information int m_numJoints; Joint *m_pJoints; // Timer variable Timer *m_pTimer; // Total animation time double m_totalTime; // Is the animation looping? bool m_looping; // { end NEW } }; #endif // ndef MODEL_H //////////////////////////////////////////////////////////////////////// AND THIS FOR CAST SAHDOW : (in other file ) For a text file (shadow lesson in nehe) //////////////////////////////////////////////////////////////////////// void CastShadow(glObject *o, float *lp){ unsigned int i, j, k, jj; unsigned int p1, p2; sPoint v1, v2; float side; //set visual parameter for (i=0;i<o->nPlanes;i++){ // chech to see if light is in front or behind the plane (face plane) side = o->planes.PlaneEq.a*lp[0]+ o->planes.PlaneEq.b*lp[1]+ o->planes.PlaneEq.c*lp[2]+ o->planes.PlaneEq.d*lp[3]; if (side >0) o->planes.visible = TRUE; else o->planes.visible = FALSE; } glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glColorMask(0, 0, 0, 0); glStencilFunc(GL_ALWAYS, 1, 0xffffffff); // first pass, stencil operation decreases stencil value glFrontFace(GL_CCW); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); for (i=0; i<o->nPlanes;i++){ if (o->planes.visible) for (j=0;j<3;j++){ k = o->planes.neigh[j]; if ((!k) || (!o->planes[k-1].visible)){ // here we have an edge, we must draw a polygon p1 = o->planes.p[j]; jj = (j+1)%3; p2 = o->planes.p[jj]; //calculate the length of the vector v1.x = (o->points[p1].x - lp[0])*100; v1.y = (o->points[p1].y - lp[1])*100; v1.z = (o->points[p1].z - lp[2])*100; v2.x = (o->points[p2].x - lp[0])*100; v2.y = (o->points[p2].y - lp[1])*100; v2.z = (o->points[p2].z - lp[2])*100; //draw the polygon glBegin(GL_TRIANGLE_STRIP); glVertex3f(o->points[p1].x, o->points[p1].y, o->points[p1].z); glVertex3f(o->points[p1].x + v1.x, o->points[p1].y + v1.y, o->points[p1].z + v1.z); glVertex3f(o->points[p2].x, o->points[p2].y, o->points[p2].z); glVertex3f(o->points[p2].x + v2.x, o->points[p2].y + v2.y, o->points[p2].z + v2.z); glEnd(); } } } // second pass, stencil operation increases stencil value glFrontFace(GL_CW); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); for (i=0; i<o->nPlanes;i++){ if (o->planes.visible) for (j=0;j<3;j++){ k = o->planes.neigh[j]; if ((!k) || (!o->planes[k-1].visible)){ // here we have an edge, we must draw a polygon p1 = o->planes.p[j]; jj = (j+1)%3; p2 = o->planes.p[jj]; //calculate the length of the vector v1.x = (o->points[p1].x - lp[0])*100; v1.y = (o->points[p1].y - lp[1])*100; v1.z = (o->points[p1].z - lp[2])*100; v2.x = (o->points[p2].x - lp[0])*100; v2.y = (o->points[p2].y - lp[1])*100; v2.z = (o->points[p2].z - lp[2])*100; //draw the polygon glBegin(GL_TRIANGLE_STRIP); glVertex3f(o->points[p1].x, o->points[p1].y, o->points[p1].z); glVertex3f(o->points[p1].x + v1.x, o->points[p1].y + v1.y, o->points[p1].z + v1.z); glVertex3f(o->points[p2].x, o->points[p2].y, o->points[p2].z); glVertex3f(o->points[p2].x + v2.x, o->points[p2].y + v2.y, o->points[p2].z + v2.z); glEnd(); } } } glFrontFace(GL_CCW); glColorMask(1, 1, 1, 1); //draw a shadowing rectangle covering the entire screen glColor4f(0.0f, 0.0f, 0.0f, 0.4f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glPushMatrix(); glLoadIdentity(); glBegin(GL_TRIANGLE_STRIP); glVertex3f(-0.1f, 0.1f,-0.10f); glVertex3f(-0.1f,-0.1f,-0.10f); glVertex3f( 0.1f, 0.1f,-0.10f); glVertex3f( 0.1f,-0.1f,-0.10f); glEnd(); glPopMatrix(); glDisable(GL_BLEND); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); glEnable(GL_LIGHTING); glDisable(GL_STENCIL_TEST); glShadeModel(GL_SMOOTH); } #endif // _3DOBJECT_H_ ///////////////////////////////////////////////////////////////////////// NOW I WANT send a pointer as milkshape model class to castshadow function to show shadow ,where of cast shadow most be changed ? ////////////////////////////////////////////////////////////////////////// static Model *pModel CastShadow(&pModel, lp);

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement