# spherical graphics engine?

## Recommended Posts

Jwilkins    122
I am just beggining programming on a graphics engine, and I was wondering... Is it possible to add a hieght map to a sphere? If so, how do you make things stick to it(like water, tress, houses...)? Also, could you program a chareter to run on it's surface? I know how to do these things on a planar height mapped surface, but not on a sphere. So is it even possible to hieghtmap a sphere, then create a world on it that had enough of a "gravitational pull" to hold everything in place, and easily navigate on its surface? -Josh

##### Share on other sites
biggoron    154
The principle is the same, but instead of vertices moving along the Y axis (0, 1, 0) to go up, move them away from the centre of the sphere to go up (vertexPosition - sphereCentre).

For your physics, the idea is the same. Instead of applying force in the down axis (0, -1, 0), apply force in the axis that points to the centre (sphereCentre - objectPosition).

To stop things flying off, just don't let any of your physical objects maintain escape velocity ;)

##### Share on other sites
MattHughes    122
You might need to work in spherical coordinates (r, theta, phi). Opengl works in Cartesian coordinates (x, y, z). To learn more about spherical coordinates read this.

"Gravity" will always act radially (it will pull you from your position to the center of the planet) as biggoron says. You will also need to use the same (but opposite) vector to define the "up" direction of your camera.

##### Share on other sites
Jwilkins    122
Matt thankyou I pretty much understand the logic and mathmatical theories behind it but thankyou for the link. More so asking how to transulate the math to code?

And big where in my program would i put the vertex position and object postion? Right after the declaration of the sphere, or after the adding of my height map, or would i ant to add it before adding or declaring much of any thing in the main function?