Jump to content
  • Advertisement

luckyyyyyy

Member
  • Content Count

    116
  • Joined

  • Last visited

Everything posted by luckyyyyyy

  1. luckyyyyyy

    Loading 3ds Model (MultiObjects)

    I can successfully read and load the objects like ur code. But I am unable to read Color info.. means color of objects that we reading from the file. actually there are many ways to read 3DS chunks on the internet but in our way how can we read color info ? U can see my code here.. //OBJ_TRIMESH //TRI_VERTEXL //TRI_FACEL1 //TRI_MAPPINGCOORS case 0xa020: // diffuse color if(1) { case 0×0010: // Color F fread (&red, sizeof(float), 1, l_file); fread (&green, sizeof(float), 1, l_file); fread (&blue, sizeof(float), 1, l_file); //if (!ReadFloat(fp, red)) return FALSE; //if (!ReadFloat(fp, green)) return FALSE; //if (!ReadFloat(fp, blue)) return FALSE; break; case 0×0011: // Color 24 fread (&red, sizeof(float), 1, l_file); fread (&green, sizeof(float), 1, l_file); fread (&blue, sizeof(float), 1, l_file); //if (!ReadUByte(fp, tmp)) return FALSE; //red = (float) tmp / (float) 255.0; //if (!ReadUByte(fp, tmp)) return FALSE; //green = (float) tmp / (float) 255.0; //if (!ReadUByte(fp, tmp)) return FALSE; //blue = (float) tmp / (float) 255.0; break; } break; Think of Design with Dimensions http://real3d.pk [/quote]
  2. haha.. NO i dont have any issue now... working like charm.. thanks to u. Think of Design with Dimensions http://real3d.pk[/quote]
  3. I want to get the mouse click position in 3D. Below is my code, its simple, I am not doing wrong in it but I don't know why I am always getting X and Y values are wrong. I think Maximum X = 0.072345664 and Y = 0.04124355 . something like this. where I am doing wrong.. ? Why I am not getting the exact values of x and y ? Z value is OK. Only issue with X and Y. any idea ? Thanks void glPerspective() { glViewport(0, 0, WINDOW_SIZE_W, WINDOW_SIZE_H); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLdouble)WINDOW_SIZE_W / (GLdouble)WINDOW_SIZE_H, 0.1, 100000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, m_zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glPerspective(); // perspective view Some_rotation_and_translation(); Render_Triangular_model(); glPopMatrix(); swapbuffer(); } GLpoint GetOGLMousePos(GLint x, GLint y) { GLdouble winX = 0.0, winY = 0.0, winZ = 0.0; GLdouble posX = 0.0, posY = 0.0, posZ = 0.0; GLint OGLMviewport[4]; //stores viewport information GLdouble OGLMmodelview[16]; GLdouble OGLMprojection[16]; glGetDoublev( GL_PROJECTION_MATRIX, OGLMprojection ); glGetDoublev( GL_MODELVIEW_MATRIX, OGLMmodelview ); glGetIntegerv( GL_VIEWPORT, OGLMviewport ); //transfers viewport info into viewport array. winX = (float)x; winY = (float)OGLMviewport[3] - (float)y; // invert winY so that down lowers value glReadPixels( x, GLint(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, OGLMmodelview, OGLMprojection, OGLMviewport, &posX, &posY, &posZ); return GLpoint(posX, posY, posZ); } Output 3D coordinates (top right section of the OpenGL display screen): -0.000810418, 0.0011706, 99.9 0.00288149, 0.00126065, 99.9 0.00981506, 0.00144074, 99.9 0.0157581, 0.00171088, 99.9 0.0249429, 0.00171088, 99.9 0.0367389, 0.00180093, 99.9 0.0468241, 0.00180093, 99.9 0.0557387, 0.00225116, 99.9 0.065914, 0.00243125, 99.9 -0.000990511, 0.0105354, 99.9 -0.0013507, 0.017379, 99.9 -0.0013507, 0.0225116, 99.9 -0.00171088, 0.0268338, 99.9 -0.00171088, 0.0313362, 99.9 -0.00207107, 0.0380896, 99.9 0.0724874, 0.0404308, 99.9 0.0744684, 0.0411512, 99.9 // top right corner Think of Design with Dimensions http://real3d.pk [/quote]
  4. Thanks for your precious time. Now its solved. I mention the problem below. Usually we used to ignore (float or double) variables during programming, I think we should not. GLpoint GetOGLMousePos(GLint x, GLint y) { GLfloat winX = 0.0, winY = 0.0, winZ = 0.0; // never ever make a mistake between float and double. I wasted my 4 days to solve this and the problem was, I was using GLdouble here instead of GLfloat. Try GLdouble here you will see a hell difference in output values. GLdouble posX = 0.0, posY = 0.0, posZ = 0.0; winX = (float)x; winY = (float)OGLMviewport[3] - (float)y; // invert winY so that down lowers value glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, OGLMmodelview, OGLMprojection, OGLMviewport, &posX, &posY, &posZ); return GLpoint(posX, posY, -posZ); // invert z value } Think of Design with Dimensions http://real3d.pk [/quote]
  5. haha.. I like the way u teaching.. ;) I got your point.. i do not want any kind of line intersection of whatever. I just want that when I click on model I get 3D coordinates. I did what u said at the end. But didn't get this ? (when want to click) change perspective to 'nicest z_near/z_far aspect ratio) now tell me where I am doing wrong? void glPerspective() { glViewport(0, 0, WINDOW_SIZE_W, WINDOW_SIZE_H); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLdouble)WINDOW_SIZE_W / (GLdouble)WINDOW_SIZE_H, 0.1, 10000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, m_zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPerspective(); glPushMatrix(); glTranslatef(screenX, 0.0, 0.0); glTranslatef(0.0, screenY, 0.0); glRotatef(spin_y, 1.0, 0.0, 0.0); glRotatef(spin_x, 0.0, 1.0, 0.0); glRotatef(spin_z, 0.0, 0.0, 1.0); glGetDoublev( GL_MODELVIEW_MATRIX, OGLMmodelview ); glGetDoublev( GL_PROJECTION_MATRIX, OGLMprojection ); glGetIntegerv( GL_VIEWPORT, OGLMviewport ); Render_Triangular_model(); glPopMatrix(); glutSwapBuffers(); } GLpoint GetOGLMousePos(GLint x, GLint y) { GLdouble winX = 0.0, winY = 0.0, winZ = 0.0; GLdouble posX = 0.0, posY = 0.0, posZ = 0.0; winX = (float)x; winY = (float)OGLMviewport[3] - (float)y - 1; // invert winY so that down lowers value glReadPixels( x, GLint(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, OGLMmodelview, OGLMprojection, OGLMviewport, &posX, &posY, &posZ); return GLpoint(posX, posY, posZ); } Think of Design with Dimensions http://real3d.pk [/quote]
  6. I have tried everything but not getting the exact X and Y values. I am applying glPerspective() in real-time (display function) thats why I think I have to apply it with a specific matrix but i dont know which matrix. I do not want to select vertex or something like that I just need 3D coordinates at the click position. Think of Design with Dimensions http://real3d.pk [/quote]
  7. I am rendering lines over 3D triangular mesh in order to visualize the mesh triangles. Well-known feature of every 3D modeling software right? but I am drawing the line with glVertex3f, How can I draw with vertex buffer or vertex array. and how can i optimize this code.. because with this code, i am getting very low FPS... just 15.. any idea ? void RenderModelMeshAsLines(GLpoint *P, GLFace *T, int nbF) { if(nbF > 0) { glLineWidth(2.0); // Set The Line Width GLfloat r=0.0f, g=0.0f, b=0.0f; glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT); glPushMatrix(); glBegin(GL_LINE); for (int i=0; i<nbF; i++) { DrawLine(P[T.v1], P[T.v2], r,g,b); DrawLine(P[T.v2], P[T.v3], r,g,b); DrawLine(P[T.v3], P[T.v1], r,g,b); } glEnd(); glPopMatrix(); glPopAttrib(); glLineWidth(1.0); // Set The Line Width } } Draw a line... void DrawLine(GLpoint a, GLpoint b, float R, float G, float B) { glPushMatrix(); glDisable(GL_LIGHTING); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); glColor3f(R, G, B); glVertex3f(a.x, a.y, a.z); glVertex3f(b.x, b.y, b.z); glEnd(); glPopMatrix(); }
  8. I don't know what's wrong here, everything is working fine except normals. When I use vertex array, model looks perfect but when I switch to VBO, model looks worse because of vertex normals. I spent a lot of time to fix it but do not know what's wrong. VBO generation seems perfect. but still do not know. any idea? #define BUFFER_OFFSET(i) ((char *)NULL + (i)) void InitVBO() { glGenBuffers(1, &vboNormID); glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, VertNormals); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); glGenBuffers(1, &vboVertID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, p_VERTICES); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glGenBuffers(1, &indexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(GLFace)*nb_Faces, p_indices); //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, p_indices, GL_DYNAMIC_DRAW);} Rendering code is followed. (VBO + Vertex Array). Vertex array is working perfect. I can see the perfect shape of model with vertex normals, but with VBO there is some issue with vertex normals. I think I am doing something wrong with BUFFER_OFFSET(12). void RenderTringularModel(GLvoid) { if(VertNormals && !MESH_SMOOTH) { glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glPopClientAttrib(); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } else { //glShadeModel (GL_FLAT); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), p_VERTICES); glNormalPointer(GL_FLOAT, sizeof(GLpoint), VertNormals); glDrawElements(GL_TRIANGLES, 3*nb_Faces, GL_UNSIGNED_INT, p_indices); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glPopClientAttrib(); }
  9. Actually I can zoom in and zoom out with both projections.. but the issue is.. i am unable to manage the similar zoom with glortho.. i mean to say the model must be at the same location when i switch to glortho.. zooming should be equal in glPerspective and glortho.. my switch function.. glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(ortho) { double left = -(double)WIN_WIDTH/2.0; double right = (double)WIN_WIDTH/2.0; double bottom = -(double)WIN_HEIGHT/2.0; double top = (double)WIN_HEIGHT/2.0; float scale = 0.005; glOrtho(left*scale*(m_zoom+60.0), right*scale*(m_zoom+60.0), bottom*scale*(m_zoom+60.0), top*scale*(m_zoom+60.0), -10000.0, 10000.0); gluLookAt(0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } else { gluPerspective(45.0, aspect, 0.1, 10000.0); gluLookAt(0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } in perspective case... i use glTranslatef for zoom in and out... guide me how can i make same zoom with both..
  10. actually my function is working perfectly with both projections if you take individually. but the issue is that when i switch from gluPerspective to glOrtho the model move little far. not at the same position as in perspective view. I don't why but at zoom factor = 60 the model keeps same position in both projections. In my observation, if the zoom factor in gluPerspective mode is 75 then it must be 45 in the glOrho. but if zoom factor 75 in gluPerspective then the model look bigger but in glOrtho the model moves far... but i want that whatever the situation is the model must be at same zoom level when i press swich mode from gluPers to glOrtho OR glOrtho to gluPerspective. I need a relationship between both projections, by using that i can have what i want. means how must i need to scale in glOrtho that i can achieve same zoom as in gluPerspective.
  11. No I am not talking about gluPerspective.... I can zoom in and out with above function.. but I want that the model position should be the same when i switch one to another. I am using glTranslatef on the object.. so i can zoom in and zoom out ... I want the relationship between glortho and gluPerspective in which whatever i select i just see the effect of projection. but now at this time.. when i press the glOrtho the object moves little bit far but in perspective it moves to near .. it must be at same position. right?
  12. Solved.. I have done it. Now i can import stl and can export ply or obj.
  13. Actually, I want to convert *.stl file format into *.ply or *.obj. The reason is that, stl file doesn't contain the triangles information. its just contains vertices. (normals is not an issue here..). But I want the triangular information like *.ply or *.obj has. triangular means..*ply or *obj file format vertex 0 0 0 vertex 0 1 0 vertex 1 1 0 vertex 1 0 0 face 1 2 3 face 1 2 4 above code has two triangles and 4 vertices. right? but *stl file doesn't contain any kind of face information. I don't have any issue to read *stl or write *stl ... I can even render the 3D stl model. My issue is I just want to convert this *.stl file format into *.ply or *obj. I spent too much time on net but didn't find any kind of code or idea relevant to this. Kindly give me some idea that how can I convert it. How can i extract face information from stl ? thanks.
  14. Its really simple... I want to load the *.stl vertices and faces into my *.obj or *.ply data structures. Following is the data structure that can be used with *.obj or *.ply. But we can not use this data structure for *.stl. For *.stl we do not know the indices information. I want to extract that information. for example triangle (indic1, indic2, indic3). So this the issue to use the same data structure for *.stl. struct GLpoint { float x, y, z; }; GLpoint *Vertices; struct GLface { unsigned int v1, v2, v3; }; GLface *indinces; Thanks.
  15. Actually i don't have any problem in calculating the vexter normal vector.. I have done it by average adjucent faces normal approach. But the issue is, I have a model that contains 119995 triangles, very large number of triangles, I need to change the vertices position of model in the real-time. for example I am rotating the model vertices. So, by changing the vertices position, face and vertex normal vector must be calculated again. When I enable the face normal, obtained FPS is 59 but when toggled to Vertex normal FPS goes down to 1 FPS, in every single frame two loops are running, vertices position updating and vertex normal calculating, because of large number of trinagles, I think computer processor give up... Is there any method to speed up the vertex normal calculations? by using GPU ? or any suggestions? yea one more thing I am also using FBO but no results. I think the issue is loop running by vertex normal calculation. am i right? At this stage I am running my simulation by using face normals but I wish I can use vertex normal in real-time. What to do ? void RotateMeshByComputingRotationMatrix(float XRotAngle) { for (int i=0; i<N_Vertices; i++) { Rotate_Model_Vertices(i, XRotAngle); } for (int i=0; i<N_Trinagles; i++) { ComputeFaceNormals(i); } for (int i=0; i<N_Trinagles; i++) { ComputeVerticeNormals(i); } } Thanks. Lucky
  16. OK this is my code... this code is working 100% perfectly in order to visualize the cutting section by a tool.. actually you can have an idea like a CNC machine. there is a tool that cut the surface of a model. you can see in the below code I am rotating the model in X-direction and then I update the vertex normal by making another loop. that loop is a making a problem in FPS. and if I don't update the vertex normal vector after "rotating and cutting of the surface" then offcourse I can not see the good visualization of the cutting section. so how can i update the vertex normal in this kind of situation.. ? thanks void RotateMeshByComputingRotationMatrix(float XRotAngle) // glutIdleFunc { float mat16[16]; float vec4[4]; for (int i=0; i<nb_Vertices; i++) { vec4[0] = getVertexPos(i).x; vec4[1] = getVertexPos(i).y; vec4[2] = getVertexPos(i).z; vec4[3] = 1; matrixRotateX(XRotAngle, mat16); // get rotation matrix along Y-axis VMatMult(mat16, vec4); p_VERTICES.set(vec4[0], vec4[1], vec4[2]); // rotation of vertex normal but this isn't working // when vertices change their position, vertex normal must be calculated again. With the rotation of vertices, vertex normals rotate too. //vec4[0] = VertNormals.x; //vec4[1] = VertNormals.y; //vec4[2] = VertNormals.z; //vec4[3] = 1; //VMatMult(mat16, vec4); //VertNormals.set(vec4[0], vec4[1], vec4[2]); } // when vertices change their position, face normal must be calculated again. for (int i=0; i<nb_Faces; i++) ComputeFaceNormal(&FaceNormals); // when vertices change their position, vertex normal must be calculated again. for (int ix = 0; ix<nb_Vertices; ix++) // compute the vertices normal of each vertex ComputeVerticeNormal(ix); } void UpdateVerticesPositionByBoundingBoxOfCuttingTOOL() // // glutDisplayFunc { for (int i=0; i<nb_Faces; i++) { if( IsCollision()) updatevertex(i); // update x , y, z } }
  17. Hi guys.. I am stuck at this point... I couldn't figure it out how to calculate the feedrate and how can I impliment. I have tried alot but now don't know what to do.. Actually the problem is .. I want to translate one object that will cover 5.555 mm in 1 sec.. so it means that 100mm in 18 sec.. I have obtained the results that is 100mm in 18sec but when the fps is 59... but when I start my simulation, the fps goes to 14... then the object moves very slowly, it does not covers 100mm in 18 sec.. it takes too much time.. my code is.. void ModelRotation_IdleFunc(void) { CurrentTime = clock(); float timeInterval = CurrentTime - PreviousTime; C_TOOL_X += (5.5555f/(1000.0*3.24*timeInterval*0.001f)); if(C_TOOL_X > 100.0) C_TOOL_X = C_TOOL_X - 100.0; PreviousTime = CurrentTime; glutPostRedisplay(); } kindly guide me how can i do this... I think fps must be considered in my code.. but how ?
  18. Realy Thanks... Actually, in simulation, each vertex position must be updated at every single updated frame, so thats why, manual rotation is required instead of OpenGL rotation glRotatef(). yes its working.. I couldn't understand, why i didn't think of it.. to rotate the normals with the same rotation of the model vertices.
  19. Hello. I have spent too much time on this topic but got failed.. actually I just want to capture the screen shoot of OpenGL window in real time rendering. I mean to say in Display() function of OpenGL. I tried with glReadPixels but I every time got the full black screen. for example: if(SKIP_FRAMES == 40) { CaptureScreenShoot(CapImg1, 512, 512); glBindTexture(GL_TEXTURE_2D, BMPimageTexture[0]); Sleep(1000); } if(SKIP_FRAMES == 60) { CaptureScreenShoot(CapImg2, 512, 512); glBindTexture(GL_TEXTURE_2D, BMPimageTexture[1]); Sleep(1000); } so on....................... this method is not working... I got full black screen. But when I capture the screen using manual method for example by pressing key in Keyboard(unsigned char key, int x, int y) function... it works,, but in Display() function it does not work.. I mean in real-time. why is it so ? what should i do for capturing the screen in real-time. already hanging around many libraries but couldn't find any ?
  20. yea i am talking about glReadPixel anyways the problem has been solved. the mistake was, I was capturing the image before the projection of texture. after disabling the texture, now i am able to capture the screens in the real-time. Thanks
  21. luckyyyyyy

    Real-time OpenGL screen capture

    Hello Stevus... Actually, I think this topic is little bit complicated and difficult . i have studied many thing and tried to implement but couldn't get success. I just want to capture the some images and capturing can be after some delay. I don't want to make real-time video, so did you get the answer how can we capture the images in Display() function (real-time rendering). kindly visit my this post you will know what i have done and what is wrong with my code. Thanks. Capture OpenGL window screen in Real-time ?
  22. what is the smoothest parameters for texturing with multi-sampling mode. I mean to say I am using GL_LINEAR, GL_CLAMP, and GL_MODULATE. What should I choose here to get smoothest and high quality texture. can you recommend me any other parameters for making texture high quality. we I don't use these paramaters then there is no difference in visual but the pixel values changes when we draw the graph of "U (horizontal coord)" and intensity of the image. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!