rotation in 3d

This is a discussion on rotation in 3d within the Game Programming forums, part of the General Programming Boards category; Well, the past hour or so has been a very exciting time for me. I managed to get texture mapping ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    Question rotation in 3d

    Well, the past hour or so has been a very exciting time for me.

    I managed to get texture mapping for my 3d models to work, and not only that, I am now able to move my models around the screen using my wrapper class MODEL_DTP.

    However, there is still one function I am working on implementing, and it has me baffled.

    The function is RotateMesh ( ). It is a function that I am trying to write for my wrapper class.

    The objective of RotateMesh is to rotate a certain mesh specified by a variable meshID a certain number of radians on an axis specified by axisID.

    Now, this function has a larger scope than rotating a single mesh. It is also called by the RotateModel function. The RotateModel function rotates the entire 3d model a certain amount of radians on a certain axis specified by axisID.

    I am unsure of how to implement the RotateMesh function.

    I cannot use glRotatef() because that rotates the entire scene, does it not?

    Therefore, I would be rotating my entire landscape in the process of doing a glRotatef().

    I just want to rotate each single individual mesh, and in some cases, the entire model, but never the entire scene.

    Anybody have any idea how I would accomplish this?
    My Website

    "Circular logic is good because it is."

  2. #2
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    youd need to do something like this:


    // draw everything else


    glPushMatrix();

    // rotation here

    // drawing here

    glPopMatrix();


    the rotation done after the push matrix would only apply to the objects within that push/pop block
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You need to rotate your model in local space realtive to the x,y,z axes. This must be done prior to transforming your vertexes to world and view space.

    I'm not sure how to do it in OpenGL because I don't use it. But your rotational matrices should not change - what they hold will.

    First rotate, scale, and translate your model in local space. Transform it to world space. Rotate, scale, and translate in world space and then clear all matrices back to the indentity matrix. Now rotate, scale, and translate into view space. Perform perspective transformation on the view space vertexes to get screen space.

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    ...'s reply was exactly what i needed.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. 3D rotation problem, help please!
    By GOBLIN-85 in forum Game Programming
    Replies: 22
    Last Post: 03-13-2009, 04:37 PM
  3. A 3D rotation problem
    By GOBLIN-85 in forum C++ Programming
    Replies: 0
    Last Post: 03-08-2009, 07:17 AM
  4. Image rotation - doesn't always work
    By ulillillia in forum C Programming
    Replies: 12
    Last Post: 05-03-2007, 12:46 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21