tags:

views:

21

answers:

1

I am writing a car car rally game. for modeling the road i am used from "PositionNormalTextured" vertex type and for modeling the car i am used from a Mesh. the car is fixed and road moves below it an i have one Device that i render car and road with it. Now i want to move car left and right but car and road move together. What should i do to move the
car left and right without road moving?

+1  A: 

How do you do your rendering? How do you do your translating?

If you add a translation to your world matrix and then render and BOTH move then you are not setting different world matrices.

Your code should go something like this:

RenderCar();
TranslateRoadBack( speed );
TranslateRoadSideways( amount ); 
RenderRoad();

This way you render the car at the origin of the world. As the car moves forward or sideways you move the track under the car. Note, though, that the Car and Road are rendered seperately.

Its also worth noting that this is one solution. You could keep the road static and move the car (This may seem more logical depending on your mindset) but bare in mind if you want the camera to stay behind the car then you'll need to move the camera as well.

edit: I answer to your comment you simply set D3DTS_WORLD again. When you call DrawIndexed Primitive (DIP) it uses the currently set matrix. If you change the matrix then call DIP again the data being rendered in the new DIP call will be using the new matrix.

(Note: This goes for DrawPrimitive (DP) calls just as much as DrawIndexedPrimitive but you should prefer DIP over DP as it allows the card to not re-transform a vertex with an index it has just transformed.)

Goz
How can i set another world matrix ? (as you know Transform calss has World , World1 , World2 and World3)
Hesam Qodsi
Updated my answer.
Goz