I want to simulate a 3D terrain using a 2D axis. I can convert 2D points to 3D points but I have trouble rotating the camera to look at the terrain at a X degree angle from a point above the terrain. The following pseudo code shows my logic.
// converting 2d to 3d points
// this algorithm assumes the
// origin starts from the middle
// not top left with a z axis that increases
// as it comes out towards the camera
//it's distance away from the origin along the z axis
camera = 256
//Corner A
x1 = -10;
y1 = 0;
z1 = 10;
//Corner B
x2 = 10;
y2 = 0;
z2 = 10;
//Corner C
x3 = 10;
y3 = 0;
z3 = -10;
//Corner D
x4 = -10;
y4 = 0;
z4 = -10;
//Looks like this, yahoo answers may s***w
//the formatting though
// D-------------------C
// |############|
// |############|
// |############|
// |############|
// A-------------------B
//plotting point A,B,C,D
//------------------------------------
//Corner A
camera_distance = camera - z1;
new_x1 = x1 * camera / camera_distance;
new_y1 = y1 * camera / camera_distance;
pixel_set(new_x1, new_y1);
//Corner B
camera_distance = camera - z2;
new_x2 = x2 * camera / camera_distance;
new_y2 = y2 * camera / camera_distance;
pixel_set(new_x2, new_y2);
//Corner C
camera_distance = camera - z3;
new_x3 = x3 * camera / camera_distance;
new_y3 = y3 * camera / camera_distance;
pixel_set(new_x3, new_y3);
//Corner D
camera_distance = camera - z4;
new_x4 = x4 * camera / camera_distance;
new_y4 = y4 * camera / camera_distance;
pixel_set(new_x4, new_y4);
//------------------------------------
The trouble occurs now. At the moment we're looking at the front of a 3D square with no hight that goes out towards the negative direction of the z axis. Because objects get smaller the further there away from the camera suggests that the interval DC can not be seen because it's hidden by the interval AB. What I want to do is move the camera up and then rotate the camera X degree down so I can view the whole square from an areal view, like Age Of Empire's kind of thing. Any suggestions would be great
Tags: