Jump to content
  • Advertisement

Hdjo

Member
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

133 Neutral

About Hdjo

  • Rank
    Member
  1. So i have finally managed to import Ply and Obj files and implement them the right way in my code , but there's a visual detail that i would like to fix; When an object is selected , i try to display its wire-frame on top of the model. The thing is , it works great with glut object(glutWiredTeapot for example) , but for the imported object as obj or ply , you can see and the triangular faces that do not look very good (especially from a certain distance , the density of the wireframe makes the object look white) i would like to know if there's anyway i could delete those diagonal lines in the faces , just to display the wire-frame as Quads instead of triangles ; here's the code i've used : void MeshObj::WireFrameMode() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(0,GL_FLOAT,0,vertice); glNormalPointer(GL_FLOAT,0,normals); glDrawArrays(GL_LINES,0,n_data); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); }
  2. Thanks again Haegarr ; i don't know if the PLY format still plays a role , but i was asked to implement it (see this more like an academic task to be done). I will take a look at assImp and the link you sent me for more details !
  3. Hi everyone , i'm still working on my 3D app with openGL 2.1 ; and now i need to export files from the current scene , to various 3D format (3 to be precise) which are the following : Obj , VRML , and PLY. I need to also implement file loaders for these 3 formats (which means i will be creating a kind of 3D conversion program ). Anyway , i have some questions :   1)in my code i'm using some Glut built-in methods and function to create object such as glutSolidTeapot() , glutSolidCube() etc .. I would like to know if i can "export" them to one of the formats named up above. If not , should i build my own functions to display them , so i can have the vertices position and save them in the files.   2)i'm already done with the obj parsing , but i have no clue on how the PLY and VRML files behave , i could use a little help here please , thanks !
  4. Hi , Finally solved the problem ; Thanks a lot for the help @Haegarr , it was all based on what you said ; i just committed few mistakes that i corrected , and that i'm going to explain if someone needs this one day : first , the infinit spinning was due to the R matrix receiving a new value each frame (Rn := Dn * Rn-1) and being passed to the stack ; i added a boolean to control that so only the first transformation is passed (The first transformation when i choose the rotation axis) Then , the second big mistake i made was to call the glMultMatrix() INSIDE my RotatedX , RotatedY and RotatedZ methods , which was in a way going back to the  Rn := Z( cn ) * Y( bn ) * X( an ) .. here's the final code of my teapot : void Teapot::PrintObj() { glLoadName(_NameStack); glPushMatrix(); Translated(axeX,axeY,axeZ); RotatedX(Qy.getAngle()); RotatedY(Qx.getAngle()); RotatedZ(Qz.getAngle()); glMultMatrixd(dArray); glScaled(ObjSize.x,ObjSize.y,ObjSize.z); glColor3ub(_Color.red,_Color.green,_Color.blue); glutSolidTeapot(2); if(_Selected){WiredTeapot();Guizmo();} glPopMatrix(); }; And here's my final RotatedX() method (the method charged with the rotation) void Object3D::RotatedX(double angle) { Qx.FromAxis(glm::vec3(1,0,0),Qx.getAngle()); Qx.normalise(); if(ActivateX) {R=R*Qx.getMatrix();ActivateX=false;} const float *pSource = (const float*)glm::value_ptr(R); for (int i = 0; i < 16; ++i) dArray[i] = pSource[i]; } ActivateX is the boolean i was talking about , it takes True when the user hits X to activate the X axis rotation . Again , Thanks a lot for the help :D
  5. thanks for your answers , i'm getting a head ache with this , the teapot is still constantly spinning , i even changed the method to test something and i got the same result : here's the method that passes the angles from the mouse event to the angles.x , angles.y and angles.z attribute of the teapot : void Scene::ProjRotation(SDL_MouseMotionEvent &event,int X,int Y,int Z) { int a; int b; int c; for(_compt=_OjebctScene.begin();_compt!=_OjebctScene.end();_compt++) { if ((*_compt)->IsSelected()) { if(X==1 && Y==0 && Z==0) { a=event.y % 360; if(a % 5 == 0) { (*_compt)->setAlpha(a); } } else if(Y==1 && X==0 && Z==0) { b=event.y % 360; if(b % 5 == 0) { (*_compt)->setBeta(b); } } else if(Z==1 && Y==0 && X==0) { c=event.y % 360; if(c % 5 == 0) { (*_compt)->setGamma(c); } } } } } the ObjScene attribute is a vector in a class named Scene ,that contains all the objects in the scene; i first check if the object is selected , then if it is , i select the Axis around which i want to rotate , and send the coordinates of the mouse the my rotation methods as an angle; i'm really struggling here nothing seems to work , i tried multiple version and multiple methods but all lead to the same result : either infinit spinning , or rotation around the Global axis (as if i used 3 consecutive  glrotated() ).
  6.   Yes , i initialized the R matrix to identity in the constructor , this way , whenever i enter that method the first time it's Id , but then its value changes following that equation.   I understand that i need to load the matrix and not multiply it because the stack automatically multiplies matrices passed by glMultMatrix() ; so i tried to glloadmatrix() the R matrix i computed , but the result is really weird ! is my code up above really correct ? here's a screen of what it looks like :      yes , that is the Teapot taking all the screen :p . 
  7. i wrote this bit of code based on what you said (or based on what i understood to be more precise :P ) void Object3D::RotatedX(double angle) { float mat[16]; vector_normalize(rotX);//rotx is (1,0,0) quaternion Q=make_rotation_quaternion_from_axis_and_angle(rotX,angle);// i created a quaternion from the axis and angle quaternion_fill_opengl_rotation_matrix(Q,mat);// i converted it to a matrix , now i have the D( pn, dn ) you were talking about ( i guess ?) glm::mat4 vecMat=glm::make_mat4(mat);//using the glm to do the maths R = vecMat * R; // R is the recurrence matrix , i initialized it to the Id matrix in the constructor; double dArray[16]; const float *pSource = (const float*)glm::value_ptr(R); for (int i = 0; i < 16; ++i) dArray[i] = pSource[i]; // conversion of the R matrix to a double matrix[16] glMultMatrixd(dArray);// i apply the changes; } well , after doing this , it is still not working , the teapot is now constantly spinning , it doesn't stop ; i don't know if the problem is still here or somewhere else though :P.
  8. Thanks a lot for the quick replay  .         So basically , from what i understood , every time i call one of my rotatedX() , rotatedY() or rotatedZ() method , i need to calculate the adequate matrix right ? for example if i'm the rotatedX() function , it means that the angles.x is varying (but here again i'm using angles huh ?) so i need to calculate this matrix :   |1     0        0      0| |0 cos(a) -sin(a) 0| |0 sin(a) cos(a)  0| |0      0     0        1|   Where a is my angles.x in the case , then i need to just glMultMatrix() this matrix to the stack ? EDIT : isn't that what already happens when i call the glrotated() ? i don't really understand how i can get rid of the angles by the way :/
  9. Hi everyone; I have this project for school where i need to create a software that manipulates 3D objects , i'm using OpenGL 2.1 along side with SDL 1.2. I'm now trying to implement some kind of rotation on the objects , this way : The user selects the needed object , once it's done , he can access the rotation mode by hitting "R" , then he hits X ,Y or Z to select the desired rotation axis; at first i went with something like this :  glrotated(angles.x,1,0,0); glrotated(angles.y,0,1,0); glrotated(angles.z,0,0,1); //Drawing my object but of course it didn't work; the first rotations worked ok , but then it started to turn around an invisible axis every time ( i think it is the axis of the universe , the global one). Let me show you the video i have taken , to illustrate what i'm saying : . after looking on the net for a while , i found that quaternion could solve my problem ... Here's what my code looks like now :   The method that displays my teapot to the screen : void Teapot::PrintObj() { glLoadName(_NameStack); glPushMatrix(); Translated(axeX,axeY,axeZ); RotatedX(angles.x); RotatedY(angles.y); RotatedZ(angles.z); glScaled(ObjSize.x,ObjSize.y,ObjSize.z); glColor3ub(_Color.red,_Color.green,_Color.blue); glutSolidTeapot(2); if(_Selected){WiredTeapot();Guizmo();} glPopMatrix(); }; the angles.x , angles.y and angles.z are stored within the class ; they are modified by an other method this way : void Scene::ProjRotation(SDL_MouseMotionEvent &event,int X,int Y,int Z) { int a; int b; int c; for(_compt=_OjebctScene.begin();_compt!=_OjebctScene.end();_compt++) { if ((*_compt)->IsSelected()) { if(X==1 && Y==0 && Z==0) { a=event.y % 360; if(a % 5 == 0) { (*_compt)->setAlpha(a); } } else if(Y==1 && X==0 && Z==0) { b=event.y % 360; if(b % 5 == 0) { (*_compt)->setBeta(b); } } else if(Z==1 && Y==0 && X==0) { c=event.y % 360; if(c % 5 == 0) { (*_compt)->setGamma(c); } } } } } the ObjScene vector contains pointers to all the objects on the scene , i first try to find the selected item ; then with an event on the mouse , i send the input to the angles.x , angles.y or angles.z;   all of this leads us now to the RotatedX() , RotatedY() and RotatedZ() methods , that are charged with handling the rotation ; here's the code of RotatedX() to show you what i have done : void Object3D::RotatedX(double angle) { rotZ=vector_normalize(rotZ);//I normalize the 3 vectors : rotX , rotY and rotZ are the 3 axis , stored in the class too rotX=vector_normalize(rotX); rotY=vector_normalize(rotY); rotX.x=1; rotX.y=0; rotX.z=0; quaternion Q = make_rotation_quaternion_from_axis_and_angle(rotX,angle);// I create a quaternion based on the axis and angle quaternion_fill_opengl_rotation_matrix(Q,mat);// i create the equivalent matrix to the quaternion glm::mat4 RotationMatrix = glm::make_mat4(mat); glm::vec4 vecRoty = glm::vec4(rotY.x,rotY.y,rotY.z,0)*RotationMatrix ;// i rotate the rotY vector , so next time the rotation won't be done around the (0,1,0) vector , but around the new position of Y; rotY.x = vecRoty[0]; rotY.y = vecRoty[1]; rotY.z = vecRoty[2];// I update the new value of rotY so it is stored; rotY=vector_normalize(rotY);// i think this is useless , but just to be cautious glm::vec4 vecRotz = glm::vec4(rotZ.x,rotZ.y,rotZ.z,0)*RotationMatrix; // same thing with the Z axis , i rotate it to get a rotation around the new position of Z , not the (0,0,1) axis; rotZ.x = vecRotz[0]; rotZ.y = vecRotz[1]; rotZ.z = vecRotz[2];// I store the new value in rotZ; rotZ=vector_normalize(rotZ);//same , normalizing rotZ; glMultMatrixf(mat); // then i apply the rotation to the scene to update the displaying of the teapot } i hope all of this is clear for you , i'm just getting started with openGL and had till yesterday no idea about quaternions , i don't know if the algorithm behind my code is wrong , but there's obviously something i am missing.
  10. Thanks you , i have used the GlRenderMode method and it seems to work nicely. Now i have another problem , i would like to move objects and rotate them using the mouse , could you please explain to me how to do this using OpenGL ? thank you :)
  11. Hi everyone. I'm doing this project for school which is an app that handles and manipulate 3D objects . I'm learning all about OpenGL myself but here i'm facing a little problem , which is Selection. I have used the Gluunproject function that is provided by OpenGl to accomplish this task , which does a wonderful job of giving me the coordinates (x,y,z) of the first object that intersect the "Ray" shot by the click : if(event.button.button == SDL_BUTTON_MIDDLE) { SDL_GetMouseState(&mouseX, &mouseY); glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix); glGetDoublev(GL_PROJECTION_MATRIX, projmatrix); realY = viewport[3] - (GLint) mouseY - 1; glReadPixels(mouseX, realY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, depth); gluUnProject((GLdouble) mouseX, (GLdouble) realY, depth[0], mvmatrix, projmatrix, viewport, &wx, &wy, &wz); } The coordinates of the intersection of the ray with the object are stored in the wx , wy and wz variables , so i added this bit of code : glPointSize(10); glBegin(GL_POINTS); glColor3f(0, 1, 0); glVertex3f(wx, wy, wz); glEnd(); Which draws a little dot on the object under my click , but i don't know what to do to "get" that object , should i detect the color of the dot on the object ? is there any way i can get the name or the position of the desired object in the scene using this method ? Thanks ! EDIT: i'm really struggling here , so i will add this image if it can help you understand better : The scene contains a cube and a teapot , the Green dot is the result of the ray projected by the click (so theoretically , the teapot should be selected ) I have thought about getting the 2D coordinates of all the objects in the scene , and test every time if the green dot is in the interval of those coordinates , but i don't know how to do that too , I'm just getting started with openGL and already lost :/.
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!