# Height maps

Hi there,

I ran into a post of yours on the internet… See below---------------------------------------------------------------
I have a data structure

struct Vector
{
float x, y, z;
};

I have loaded an SDL_Surface with my own Image class the
uses the SDL_image library.

So I have:

Image *hmapImg = new Image();

My Image class has the SDL_Surface* member
Image.theImage.

How would I allocate space for an array of type Vector *
to hold one Vector for every pixel of the loaded image, then
loop through the loaded image picking out the vertices
with Vector.x being the x position in the image, Vector.z
being the y position in the image, and Vector.y being a
value from 0-255 based on the Alpha value of the pixel
at x,y?

To the best of my knowledge this SHOULD just be a few lines
and then a few more inside of 2 nested for loops.

## Thanks! -Randall

I know it’s an old post… Anyway… I’m working myself on some terrain now.
How did you finally end up doing this? In my oppinion it would’nt be such a
good idea as to store a vector per pixel. It would take a lot of memory.
Nowadays memory is relative slow, compared to processor power. Why not
calculate the pixel’s vector in the main loop? There are some good functions
for this… For example:

1. Get the normal of the triangle

CVector3 Normal(CVector3 vTriangle[])
{
CVector3 vVector1 = Vector(vTriangle[2], vTriangle[0]);
CVector3 vVector2 = Vector(vTriangle[1], vTriangle[0]);
CVector3 vNormal = Cross(vVector1, vVector2);

``````vNormal = Normalize(vNormal);

return vNormal;
``````

}

Now that you know the normal, (center of triangle), you can now calculate
the vector from the triangle’s center to this normal. Once you have this you
can calculate where the pixel is - and so it’s normal

I don’t know if this is correct. It’s just a thought, and I haven’t tried
it. I’m actually a n00b in 3D-programming, but I’m VERY willing to learn.
I’m just looking for people to discuss stuff with, and to think stuff over
with. That’s the reason i sent you this email…

Well… maybe cya

NecrArch

MSN Zoeken, voor duidelijke zoekresultaten!
http://search.msn.nl/worldwide.asp