gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > 3d, mode7 problems

#27620 - ProblemBaby - Sun Oct 17, 2004 12:56 pm

Hi

Here is a function Ive wrote:

Code:

void TransformCoordinate(FIXED x, FIXED y, FIXED z)
{
   FIXED rx, ry, rz, tx, ty, tz, nx, ny;
   rx = x - cam_x;
   ry = y - cam_y;
   rz = z - cam_z;

   tx = rx;
   tz = rz;
   rx = FixedMul(tx, COS[cam_yaw]) - FixedMul(tz, SIN[cam_yaw]);
   rz = FixedMul(tx, SIN[cam_yaw]) ) + FixedMul(tz, COS[cam_yaw]);

   ty = ry;
   tz = rz;


   ry = FixedMul(ty, COS[cam_roll]) - FixedMul(tz, SIN[cam_roll]);
   rz = FixedMul(ty, SIN[cam_roll]) + FixedMul(tz, COS[cam_roll]);

   nx = 120 + FixedToInt(FixedDiv((FixedMul(rx, VIEWDISTANCE)), rz));
   ny = 80 - FixedToInt(FixedDiv((FixedMul(ry, VIEWDISTANCE)), rz));
   if (nx >= 0 && nx < 240 && ny >= 0 && ny < 160)
      DrawPixel(nx, ny);
}


As you probably understand cam_x,cam_y,cam_z,cam_yaw,cam_roll
are the camera position and rotation.

Now my problem...
How do I draw a mode7 world if I for example want it to reach from
(-8, 0, -8) - (8, 0, 8)
And is the zoom computed exactly as Ive done for objects to find the scale?
Code:

xscale=FixedMul(srcwidth, FixedDiv(256, FixedDiv((destwidth<<8), rz)));
yscale=FixedMul(srcheight, FixedDiv(256, FixedDiv((destheight<<8), rz)));



plz help

#27623 - poslundc - Sun Oct 17, 2004 1:42 pm

Mode7 isn't done by mapping pixels to their transformed coordinates. I suggest you have a look at Cearn's Mode 7 tutorial for a start.

Dan.

#27633 - ProblemBaby - Sun Oct 17, 2004 8:04 pm

Well, I didnt get after reading it=/
Iam quite new to 3d stuff
I thought it were more like texture mapping

#27634 - sajiimori - Sun Oct 17, 2004 8:28 pm

First, write a program that rotates and scales a background in response to button presses.

Then write one that uses an hblank interrupt to mess with the bg registers.

Those are the 2 basic components. After you understand how to do those things, Cearn's tutorial should make more sense. You can make it work even if you don't understand the math.