Transformations

ThePentiumGuy

Well-known member
Joined
May 21, 2003
Messages
1,113
Location
Boston, Massachusetts
Matrix Translations in D3D

hey, im a little hazy about the subject of matrix transformations,
im trying to develop a (3d) racing game.
i have a mesh class which has an instance of a camera class, so my car and my platform mesh bothj have their own "cameras" (or you could say their own vector3s for Position, Target, and .. well the Up vector is the same for all of them - i have instances for each mesh so i can use them for world translatiion purposes)

ok,
my (skimmed down) render loop looks like this(in pseudocode as i dont really have a computer and im trying to figure this out)

BeginScene


Platform.SetupWorld
Platform.Render

Car.SetupWorld
Car.Render


EndScene
Present (i dont remmeber whether its present before Endscene or endsene before present lol but that doesnt matter ;))

my setup world sets up a LookAtLH view matrix and a perspectiveFOVLH projection matrix for each of htem

my dillema is this:

in order to get the effect that the car is moving (for example) forwards, i have to make the platform move backwards...
thats all said and done becuase whjen i push up i move the platforms camera down..etc

however, i want to be able to get the cars actual position and be able to do a mesh.intersect with it, for that ill need the cars "real" position,

i tried doing this

platform.setupworld becusae the platform moves
platform.render

car.render dotn move the car just rendfer it

and when i push(for example) space, the platform moves down, and the car moves up

but it gets confusing when i have to do Mesh.Intersect becuase the car is really 2x further into the platform then it thinks it is..

---

im sorta confusing myself here as i write this
my real plea is - can someone clarify matrix Transformations for me please
and tell me the best way to render my objects

pent
 
Last edited by a moderator:
My suggesting:
If your game is a first person game, you may simply alter the user camera view vectors and the object (car) vector at the same time, so you get the effect of moving, because any other objects (e.g. the world) is not moving.
Thats how i did it for my program anyway.
 
hey dude i just thought of something,
and i think this is where my confusion is comign in

if i change the View camera with the car camera it should look like this when i push up
view.movecamera(3)
car.movecam(3)

thats all said and done

but also

if i render

identity
platform.setupworld
paltform.render

car.setupworld
car.render

d3ddev.transform.world = matrix.LookatLH(Camera.pos,camera.target, v3(0,1,0)

im pretty sure that last lines not gonna have any effect becuase it wont "change its position" like that in the last minute(you know what i mean?)
-
see the thing is, i got how to render the objects in a different position, but now - how would i change the view in which i see the objects?

in that case, would i have to change the Projectoin matrix? or the World matrix?

basically what i mean to say is -
after youve rendered all the objects, how wuold you change the "View" camera so that you see your scene from a different angle(in my case, behind the car)
 
Last edited by a moderator:
Youve got things wrong. You cant change the view after you render things. The view must be correct during the rendering. After its there its there.

Also dont think in terms that each object has its own camera. Objects only have position and orientation which is encoded in a matrix or vector (translation) + quaternion (rotation). You set this by setting the world matrix.

You only have one camera at a time. You could have more of them for different views, but you can only use one at a time. You set this matrix with LookAtLH for example and set it for the view matrix.

I hope this clears things up a bit.
 
I would have the platform fixed (always identity) and would only scroll the car. For the camera Id calculate its position to be somewhat behind and above the car and have the lookat vector at the position of the car.
 
so your saying

identity
platform.setupworld
paltform.render

identity
car.setupworld
NOW check for collisions becuase the platforms "Back to where it was", and the platforms .. well its back to werhe it *should* be

Check For Collisions

identity the car never moves, the world moves
car.render

where the platformll move down every time the car moves up..etc

edit: i corrected a lot of code
 
Last edited by a moderator:
I dont think I understand you. What does your setupworld do? how do you perform collision tests? You definitely want to set world matrix for the car. And I dont understand what you mean by moving the platform while moving the car. Why dont you have platform at fixed location.

Id do things like this:

View = CameraViewMatrix
World = Identity
Platform.Render
World = CarMatrix
Car.Render

I skipped the collision as I dont know in what way youre doing it.
 
oh,sorry
my setupworld sets up a view (lookatLH) matrix for each individual mesh

my collision will be (in pseudocode: Mesh.Intersect(cars position,below the car) just to see whether the car is on(above) the platform))

how do u set a world matrix for the car?

thanks,
pent
 
Ok then you cant use your setupmatrix as you have it now.

To set up world matrix for the car you do something like this:
World = Matrix.Translation(CarPosition)

You could also do it like this if youd like it to be rotated:
World = Matrix.Multiply(Matrix.RotationY(AngleInRadians), Matrix.Translation(CarPosition))

If youll do collision detection like you said then you dont have to set world matrix. Just make sure that your cars position and below car are correct (meaning they are in world space coordinates).
 
Back
Top