Results 1 to 8 of 8

Thread: 3DS Translation (Center)

  1. #1
    Member Newbie
    Join Date
    Apr 2001
    Posts
    36

    3DS Translation (Center)

    Hello.
    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
    Martin

    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 ???

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: 3DS Translation (Center)

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Member Newbie
    Join Date
    Apr 2001
    Posts
    36

    Re: 3DS Translation (Center)

    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 [09] , [10], [11]. 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 ?

    Thanks
    Martin

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: 3DS Translation (Center)

    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.)
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Member Newbie
    Join Date
    Apr 2001
    Posts
    36

    Re: 3DS Translation (Center)

    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:
    Code :
       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

    Code :
    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...

    Code :
    for (int j = 0; j <Obj->Count; j++)
    {
     ... 
     VectorRotation( Obj->p_Vertex[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 ?
    Thanks
    Martin


    [This message has been edited by Erakis (edited 07-24-2002).]

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: 3DS Translation (Center)

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  7. #7
    Member Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: 3DS Translation (Center)

    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

    Good luck!

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Recife - PE - Brazil
    Posts
    13

    Re: 3DS Translation (Center)

    I really new at opengl, but beleave that this code could be help.
    http://romka.demonews.com/opengl/dem.../3dsloader.zip

Similar Threads

  1. Center of the screen
    By leanfrei in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-29-2012, 06:52 PM
  2. Zoom to center
    By hockeyman in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-16-2012, 03:49 AM
  3. where's the center
    By jp185088 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-06-2010, 01:28 AM
  4. Center on point
    By MBonevil in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-02-2004, 07:01 AM
  5. center xyz in glulookat
    By JPH in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-24-2000, 01:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean