View Full Version : Changing Elevation

OK here goes, right now I have a small engine which allows you t move forward, back

turn around ect. Now lets say my world which I am walking through is flat, then this is fine. However when the elevation changes ( + or - on the y-axis) I would keep moving straigh through midair. How would I be able to make the program know the elvation and change so when I walked formard on a slope I would go down aswell?

DFrey

02-13-2001, 04:52 PM

Exactly how is dependent on the structure of your engine and preference. But in the most general terms, you need to implement gravity and collision detection.

Assuming you have a landscape or whatever made of triangles. your current x/z position should point you at the triangle you are on. (cell)

Solve the plane equation for the point that you're standing on.

The plane equation is (x)nx + (y)ny + (z)nz + c = 0.

{nx, ny, nz} is the plane normal of the current cell.

c is a constant offset which can be solved by plugging in

the coordinates of one of the corner points of the cell.

Your current position on the map is {x,z} solve for y.

In pseudocode:

// Get my current position on the map

pos = {something};

// Figure out the current cell I'm standing in

cell = FindCell(pos);

// Get the plane normal of the cell or triangle

normal = cell.normal;

// Get one of the corner points of the cell

point = cell.point(1);

// Solve for c, the plane equation offset

c = normal.x * point.x + normal.y * point.y + normal.z * point.z;

// Now solve for the y component of my position

pos.y = (c - normal.x * pos.x - normal.z * pos.z) / normal.y;

You should be able to accomplish this just by using glRotate* and glTranslate*. I had to write a program where the object coordinates had to stick to the object when I was rotating it. At one point I got it so that if you moved the x-axis to any orientation, a translation in x direction would move the object in that direction.

Try this (I'm not sure if it works).

Apply your rotation and save it in a matrix.

Load your matrix just before you do translation and then translate it and save the matrix...

if this doesn't work, just play with it, I am 100% sure my program was working this way (but it wasn't meant to do so).

Rizo

I am trying to do the same thing and am having trouble aswell.

Dans could you explain your way a bit more or if you have or know where i could get a sample of it tell me please.

thanks alot

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.