Results 1 to 15 of 15

Thread: Dirext x 8 , moving the camera (z might know the answer)

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Dirext x 8 , moving the camera (z might know the answer)

    Ok i know how to do loads of things with direct graphics in Dx 8 but how can i make my camera move.. i know how to rotate it but moving it is not known to me :S can anybody help me with that?
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    How are you creating your camera in the first place? D3DX functions?

    The D3DXMatrixLookAt*H functions are the easiest to use (use the LH version if you are using a left handed coordinate system, RH if right handed, I use LH, personally). The pEye parameter is a vector containing the position of the camera, the pAt parameter contains the point the camera should be looking at. To move the camera, simply recalculate the view matrix with the new data, and re set it, D3DDevice.SetTransform(...).

    Z.

  3. #3

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    aha yeah just found it out hehe but now i get it much better can you also help me with how to position object? like moving them? only got them on the 0 , 0 , 0 standard place yet :S
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    D3DXMatrixTranslation() to generate a translation (position) matrix, then SetTransform to change the world matrix, then render the object. You do that for each object you want to move.

    Z.

  5. #5

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    D3DXMatrixTranslation() to generate a translation (position) matrix, and use the object or something ? :S can you provide a little code example? only the d3dxmatrixtranslation should be fine
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  6. #6

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    this doesnt seem to work


    Public Sub model_move(index As Integer, x As Single, y As Single, z As Single)
    D3DXMatrixTranslation objectmodel(index), x, y, z
    End Sub


    but what should the MOUT be :S
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    D3DMATRIX m
    Dim i as long
    For i = 0 to numObjects - 1
      D3DXMatrixTranslation m, Objects(i).pos.x, Objects(i).pos.y, Objects(i).pos.z
      D3DDevice.SetTransform D3DTS_WORLD, m
      Draw Object(i)
    Next i
    Simple enough...

    Z.

  8. #8

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    ok help me out here plz

    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Compile error:

    Variable not defined
    ---------------------------
    OK Help
    ---------------------------
    \/
    D3DMATRIX m

    as what should i define that and numObjects should be? :S trying to figure it out but need some help though :S

    this is what i have up to now

    Public Sub model_move(index As Integer, x As Single, y As Single, z As Single)
    D3DMATRIX m
    Dim i As Long


    For i = 0 To numObjects - 1
    D3DXMatrixTranslation m, x, y, z
    D3DDevice.SetTransform matWorld, m
    Next i

    End Sub

    i hope matworld is correct that declared as

    Private matWorld As D3DMATRIX
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Whoops... C++ style variable declarations =).

    should have been

    Dim m as D3DMATRIX

    You function should look like this:
    Code:
    Public Sub model_move(x As Single, y As Single, z As Single)
      D3DMATRIX m
      D3DXMatrixTranslation m, x, y, z
      D3DDevice.SetTransform matWorld, m
    End Sub
    And you would call it for each object you have, and render that object after calling it.

    Z.

  10. #10

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    VB Code:
    1. Public Sub model_move(index As Integer, x As Single, y As Single, z As Single)
    2.  
    3.   D3DXMatrixTranslation objectmodel(index).matpos, x, y, z
    4.   D3DDevice.SetTransform matWorld, objectmodel(index).matpos
    5.  
    6.  
    7. End Sub
    is what i have now.. the first line works perfectly though the second one fails at the matworld

    this is how i declared it all

    VB Code:
    1. Private matWorld As D3DMATRIX '//How the vertices are positioned
    2. Private matView As D3DMATRIX '//Where the camera is/where it's looking
    3. Private matProj As D3DMATRIX '//How the camera projects the 3D world onto the 2D screen
    4. Private matTemp As D3DMATRIX
    5.  
    6. Private screenwidth As Long
    7. Private screenheight As Long
    8. '////////////////////////////////////////////////////////////////////////////MODELING
    9. Private Type smodel
    10.  Mesh As D3DXMesh
    11.  MeshMaterials(100) As D3DMATERIAL8   ' Mesh Material data
    12.  MeshTextures(100) As Direct3DTexture8 ' Mesh Textures
    13.  nMaterials As Long 'How may materials/textures we have....
    14.  used As Boolean
    15.  
    16.  matpos As D3DMATRIX
    17. End Type
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  11. #11
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    Public Sub model_move(index As Integer, x As Single, y As Single, z As Single)
    
      D3DXMatrixTranslation objectmodel(index).matpos, x, y, z
      D3DDevice.SetTransform D3DTS_WORLD, objectmodel(index).matpos
    End Sub
    Though if you are going to store the matrix in the object itself, you can just use that second line right before you draw the object.

    Z.

  12. #12

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    WOOHOO GOT IT WORKING

    any idea why i get this error?
    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Compile error:

    Forward reference to user-defined type
    ---------------------------
    OK Help
    ---------------------------

    with this code?
    VB Code:
    1. Private Type smodel
    2.  Mesh As D3DXMesh
    3.  MeshMaterials(100) As D3DMATERIAL8   ' Mesh Material data
    4.  MeshTextures(100) As Direct3DTexture8 ' Mesh Textures
    5.  nMaterials As Long 'How may materials/textures we have....
    6.  used As Boolean
    7.  position As poss ' right here (Seems to work normally)
    8.  matpos As D3DMATRIX
    9. End Type
    10.  
    11. Private Type poss
    12.  x As Single
    13.  y As Single
    14.  z As Single
    15. End Type

    never had problems with a type in a type
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  13. #13

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    oh well nevermind that i got it all working.. but now i am working on camera movement.. but it keeps looking at a certain point how do i make my camera like a first person shooter has? looking up down etc etc and not looking at a certain object or something
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Store the angles that the camera is looking, and use those to convert to lookat vector (look up spherical coordinates on google, use 1.0 for r).

    Z.

  15. #15

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    ok will look for that tommorow right now i am tired as hell :P thanks zaei , you always seemed to help me out

    oh 1 other thing the fps is always at 60 fps no matter windowed fullscreen nor the resolution (1600x1200x32) i have a ati radeon 9700 pro. is it the fact that it is limited or something? tried changing this but that doesnt seem to work

    D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC '//We'll refresh when the monitor does
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width