View Full Version : 3DS Translation (Center)
07-23-2002, 08:30 PM
This is most a mathematic than 3DS question...
Pretend an object was built so that center is (200.0, 195.0, 5.0 ), so when I will need to rotate the vertex (Object), the rotation
will be done aroud this point and not around the world center (0.0, 0.0, 0.0 )
If I read the MESH (Object) matrix this 3DS object, could I replace it to the world center (0.0, 0.0, 0.0 ) ?
I thought to substract the vertices points of my object, at the points of translation of his matrix. But that really don't work...
Only one object are replace correctly to the world center (0.0, 0.0, 0.0), the others one moves anywhere around...
Anyone could help me ?
Thanks in advance http://www.opengl.org/discussion_boards/ubb/smile.gif
PS : Just like that, somebody know what
the chunk MAT_TWO_SIDE means? Faces
normals calculated for both side and
texture put inside and outside ???
07-24-2002, 05:23 AM
If you want an object to rotate around a center of 200.0, 195.0, 5.0 you do something like so...
Translate that point to 0, 0, 0.
Do your rotation.
Translate it back.
Code for this looks like so.
glTranslatef(200.0, 195.0, 5.0); // translate back
glRotatef(ang, x, y, z); // do your rotation
glTranslatef(-200.0, -195.0, -5.0); // Translate to 0, 0, 0
Note that the actual order of the glTranslate calls is backwards of how I described the solution. That is because the way the matrices are multiplied in OpenGL gives the effect that the last matrix multiplied is the first one performed.
07-24-2002, 12:10 PM
Thanks Deiussum, but that doesn't anwser my question. I know how rotate an object. My problem is how to translate it to
(0.0, 0.0, 0.0) with the MESH matrix ???
When we read a 3DS files, we can get the matrix of the object being reading. So this matrix is compose of 3 axis(X, Y, Z) vector and position (X, Y, Z) at index  , , . You know what I mean ?
I try to substract the vertex position of the object TO the X, Y and Z position value into the matrix object. So this is suppose the replace the object to the world center
(0.0, 0.0, 0.0 )...
But, only one object are replaced correctly to the world center (0.0, 0.0, 0.0), the others, reading after, moves anywhere around... How could I do that ?
07-24-2002, 01:54 PM
Ok, I'm not entirely sure I understand what it is you want. I think you're asking if there is a way to extract the elements from the 3ds Model's matrix and then apply them to OpenGL's matrix. If that's the case, you may just be able to use glMultMatrix. (Though, you may have to transpose the matrix depending on how the data is stored. I haven't worked explicitly with the 3ds format much.)
07-24-2002, 06:12 PM
Not exactly. No relationship with the OpenGL matrix. The operations are made directly on the object matrix and his vertex.
Pretend I extract an object matrix as:
Matrix = 1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
280.0 0.0 10.0
So the three first line are the direction vector of the object. Now the object is aligned with the world axis. The last line is the position of the object in the space. So as you can see, the object was built at
X = 280.0
Y = 0.0
Z = 10.0
So, If I apply a rotation on each vertex of the object, the rotation will be done around this pivot, and not aroud the world center (0.0, 0.0, 0.0). I don't want to use glRotated or glTranslated, I WANT TO modify directly the object vertex. So to make a rotation I will proceed as...
for (int j = 0; j <Obj->Count; j++)
rX, rY, rZ );
By the same way, I want to replace, all the objects into the world center. Of course I said ALL objects, because a MESH is often compose of more than one object objects. So use the 3 position values of the object matrix and then subtract it to the vertex list of his object, and this one will suppose to move to (0.0, 0.0, 0.0). But I got some problem with the others one...
Do you know what I mean now ?
[This message has been edited by Erakis (edited 07-24-2002).]
07-25-2002, 05:24 AM
I'm still confused by what exactly you are having problems with. Possibly you are confused by the order in which matrices are applied?
Take your object at 280, 0, 10 as an example. Do you want to rotate it at that location? Then just apply the object matrix, then do the rotate.
Do you want it to rotate around 0,0,0? Then do your rotate and then apply your object matrix.
I'm also confused when you say you want to "replace all the objects into the world center." If I understand you correctly, you just don't need to apply your object matrices.
I believe the mesh matrix is the space in which the model "lives".
Try making a glmultmatrix with it and then send down the polygons (remember about transposing and that the coordinate system is different than in gl).
If this doesn't work, try building a matrix that'll make that pivot point rotation instead of making it vertex by vertex.
When you say other objects don't get transformed are you talking about object hierarchies? Maybe you should propagate transformations among children objects (glpushmatrix/glpopmatrix)
About MAT_TWO_SIDE, I guess it is similar to gl's two-sided lighting with equal material properties in both sides.
PS: I've such complex transformations in .3ds so this is just me thinking http://www.opengl.org/discussion_boards/ubb/smile.gif
07-27-2002, 05:36 AM
I really new at opengl, but beleave that this code could be help.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.