Thread: moving objects in d3d...

  1. #1
    Unregistered
    Guest

    Unhappy moving objects in d3d...

    i don't seem to be getting much help w/ this on the gamedev boards so i'm going to post it here:

    i'm trying to get objects within a 3d room i've created to move, but i can't seem to get it to work. the object class i'm writing initializes 4 vertices ( a square object ) and the square's x,y, and z world coordinates. here is the world transformation function:

    void MakeWorldMatrixStripObject4(D3DXMATRIX *pMatWorld, stripObject4 &pObject)
    {
    D3DXMATRIX MatZ,MatX,MatY,MatTemp;
    D3DXMATRIX MatRot;

    D3DXMatrixIdentity(&MatRot);

    D3DXMatrixRotationZ(&MatTemp, pObject.zRot);
    D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

    D3DXMatrixRotationX(&MatTemp, pObject.xRot);
    D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

    D3DXMatrixRotationY(&MatTemp, pObject.yRot);
    D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

    D3DXMatrixTranslation(pMatWorld,
    pObject.xPosWorld,
    pObject.yPosWorld,
    pObject.zPosWorld);

    D3DXMatrixMultiply(pMatWorld, &MatTemp, pMatWorld);
    }

    and i do this where i want to move the object:

    theSquare->xPosWorld += 1.0f;

    this only causes the entire world to move, however. what am i doing wrong? ... does each vertice need it's own world space coordinates? thanks to anyone that can help.

  2. #2
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    D3DXMatrix MatRot;
    D3DXMatrixIdentity(&MatRot);

    D3DXMatrixRotationZ(&MatTemp, pObject.zRot);
    D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
    This wastes time, just do this :
    Code:
    D3DXMatrixRotationZ(&MatRot,pObject.zRot);
    .
    .
    .
    Generally, the code's too slow since it creates a matrix for each axis rotation. You should write a function that creates a rotation matrix directly (without calling D3DX) ( I have one, I'll post it later, cause I don't quite have it right now).

    Anyway,
    this only causes the entire world to move, however. what am i doing wrong?
    You possibly did the following :
    1 - You set this rotation matrix as a world matrix
    2 - Render your object
    3 - Render the rest of the world (with the same matrix set)

    which is wrong, If you did this, change it to the following :
    1 - Set this rotation matrix as a world matrix
    2 - Render your object
    3 - Set the world matrix as an identity matrix
    4 - Render the rest of the world.

    The world matrix you created is specifically created for the object supplied, if you keep it set, it's going to rotate all the other objects too (and thus your world will get moved/rotated)
    Muhammad Haggag

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving objects with mouse in 3D.
    By psychopath in forum Game Programming
    Replies: 15
    Last Post: 07-10-2011, 04:20 PM
  2. Moving Objects in D3D?
    By VertexBuffer in forum Game Programming
    Replies: 3
    Last Post: 01-18-2007, 04:21 AM
  3. moving objects in a window
    By axr0284 in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2006, 07:23 PM
  4. moving objects
    By condorx in forum Game Programming
    Replies: 2
    Last Post: 02-22-2002, 02:05 PM
  5. Moving Objects on the Screen
    By BigSter in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2001, 10:37 PM