Terrain heights, tex2dlod and Texture2D.GetData

Hey.

I've been playing around with using textures and with tex2dlod in the vertex shader to set the heights for some basic deformable terrain which a car is going to drive around on. I've got the terrain itself working well, but I'm stuck on getting the car to map to the same height. Basically I'm working out the car's roll and height from an array pulled out of the texture using Texture2D.GetData<Int32>()so the height of the car is a Int32 but the height of the shown terrain coming out of tex2dlod is a float4.

What should I do to match the car's Int32 to the terrain's float4?

[601 byte] By [uewepuep] at [2007-12-28]
# 1

When you pull the data from the texture it will be easier for you to deal with if you store it in your own array, if its two dimensional then its even easier to get at a specific coordinate, something like

float terrainData[,] = new float[height, width];

int d = 0;
for(int z=0; z < height; z++)
{
for(int x=0; x < width; x++)
{
terrainData[z,x] = (float) data[d++];
}
}

something like that anyway :)

Fluxtah at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2
For my heightfield, I use a R32F texture, where I can just GetData<float>() to get the texture data.

Btw: assuming that the car conforms to the terrain at all times isn't very realistic -- you cannot even do a good jump that way. I suggest keeping the car orientation, spin and velocity as simulated variables, and affect them with forces based on user input and car relation to terrain.

"Physics for Game Developers" is a good introduction to this topic, btw.

JonWatte at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 3

Another good solution for managing your Terrain isto use a good tree structure, like octtrees and the like (for more info on Trees, search on gpwiki.org and www.wikipedia.com )

A good example of this can be found on Codeplex, the example also includes models that interact with the terrain, they dont do rotation o the model with the Terrain but I agree with Jon's approach and having the rotation for the model seperate and update it the the terrain the model interacts with.

Hope this helps

Darkside

Darkside at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 4
Thanks guys.

Yeah, I know I should do proper physics, but right now I'm just messing around.

I

solved my problem though, instead of using GetData<Int32> I used

GetData<Color>. So now I have really access to the RGB values via

a Color object. The values after being divided by 256 are identical to

those in the vertex shader. Of course now I'm throwing Color objects

around rather than Int's which is probably slower, but it actually

*works* :D

I wish some of this stuff was better documented, it

makes sense that you can use Color objects but it doesn't actually say

this anywhere I could find. Oh well.

Thanks again.

uewepuep at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...