|
-
Feb 18th, 2003, 02:23 PM
#1
Thread Starter
Frenzied Member
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?
-
Feb 18th, 2003, 04:05 PM
#2
Frenzied Member
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.
-
Feb 18th, 2003, 04:06 PM
#3
Thread Starter
Frenzied Member
-
Feb 18th, 2003, 04:15 PM
#4
Frenzied Member
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.
-
Feb 18th, 2003, 04:16 PM
#5
Thread Starter
Frenzied Member
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
-
Feb 18th, 2003, 04:27 PM
#6
Thread Starter
Frenzied Member
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
-
Feb 18th, 2003, 04:28 PM
#7
Frenzied Member
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.
-
Feb 18th, 2003, 04:35 PM
#8
Thread Starter
Frenzied Member
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
-
Feb 18th, 2003, 04:43 PM
#9
Frenzied Member
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.
-
Feb 18th, 2003, 04:50 PM
#10
Thread Starter
Frenzied Member
VB 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 matWorld, objectmodel(index).matpos
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:
Private matWorld As D3DMATRIX '//How the vertices are positioned
Private matView As D3DMATRIX '//Where the camera is/where it's looking
Private matProj As D3DMATRIX '//How the camera projects the 3D world onto the 2D screen
Private matTemp As D3DMATRIX
Private screenwidth As Long
Private screenheight As Long
'////////////////////////////////////////////////////////////////////////////MODELING
Private Type smodel
Mesh As D3DXMesh
MeshMaterials(100) As D3DMATERIAL8 ' Mesh Material data
MeshTextures(100) As Direct3DTexture8 ' Mesh Textures
nMaterials As Long 'How may materials/textures we have....
used As Boolean
matpos As D3DMATRIX
End Type
-
Feb 18th, 2003, 04:58 PM
#11
Frenzied Member
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.
-
Feb 18th, 2003, 05:05 PM
#12
Thread Starter
Frenzied Member
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:
Private Type smodel
Mesh As D3DXMesh
MeshMaterials(100) As D3DMATERIAL8 ' Mesh Material data
MeshTextures(100) As Direct3DTexture8 ' Mesh Textures
nMaterials As Long 'How may materials/textures we have....
used As Boolean
position As poss ' right here (Seems to work normally)
matpos As D3DMATRIX
End Type
Private Type poss
x As Single
y As Single
z As Single
End Type
never had problems with a type in a type
-
Feb 18th, 2003, 05:31 PM
#13
Thread Starter
Frenzied Member
-
Feb 18th, 2003, 05:45 PM
#14
Frenzied Member
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.
-
Feb 18th, 2003, 05:49 PM
#15
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|