mirror of https://github.com/n64decomp/007.git
94 lines
6.0 KiB
Plaintext
94 lines
6.0 KiB
Plaintext
Every object and room requires different kinds of data in order to be rendered. The bare minimum requirement is a list of points in the model and a display list that maps those points.
|
|
|
|
Goldeneye Point Table Structure
|
|
Most N64 games follow this structure. It contains x, y, z data, as well as s/t coordinates to map textures to the surface and an RGBA value blended between the points composing the triangles.
|
|
offset size data type usage
|
|
0x0 2 signed short x coordinate
|
|
0x2 2 signed short y coordinate
|
|
0x4 2 signed short z coordinate
|
|
0x6 2 signed short reserved (0000)
|
|
0x8 2 signed short s value (x image mapping component)
|
|
0xA 2 signed short t value (y image mapping value)
|
|
0xC 1 unsigned byte Red Component, from 00-FF
|
|
0xD 1 unsigned byte Green Component, from 00-FF
|
|
0xE 1 unsigned byte Blue Component, from 00-FF
|
|
0xF 1 unsigned byte Alpha Component, from 00 (invisible) to FF (opaque)
|
|
|
|
Sample: FFE0 0000 0020 0000 0020 0020 FFFFFFFF
|
|
|
|
S/t coordinates are used for texture mapping. Unfortunately, the values are intimately tied to the image's own dimentions. There are several common mapping modes, including mirrorred, clamped, and tiled.
|
|
|
|
First, lets build a 32x32 square from these four points...
|
|
0000 0000 0020 0000 0000 0000 FF0000FF
|
|
0020 0000 0020 0000 0020 0000 00FF00FF
|
|
0020 0000 0000 0000 0020 FFE0 0000FFFF
|
|
0000 0000 0000 0000 0000 FFE0 FFFF00FF
|
|
Clockwise, from the upper left, the square is red, green, blue, and yellow. Notice the mapping coordinates already set. The s values match the x values for the square. However, the t values are negative. Negative s or t values naturally mirror the image on that axis. So, the image should appear inverted.
|
|
|
|
Now, to actually apply an image. Lets assume a greyscale image, 32x32 to match the square. When applied, it will fit precisely, albeit upside-down because of the t values. If the colour combining mode is active, the image will also be colourized to match the lighting of the square, red, blue, green, and yellow.
|
|
However, if the image is 64x64, it doesn't fit precisely on the square. Ordinarily, you will only see the upper-left corner of the image. To fit precisely, the 0020 needs to be 0040, and FFE0 changed to FFC0.
|
|
Lets try a 16x16 image now. For this example, the tile flag is assumed to be set. The image will repeat after being textured, so instead of seeing one image, four are mapped to the square! Without tiling set but with active clamps, it is more likely the image will be stretched to fit.
|
|
|
|
Imagine, for a minute, that you wish to draw four triangles, all meeting at a centerpoint, but still want the 32x32 texture to map perfectly to the surface. This is easy enough. The point list will look like so:
|
|
0000 0000 0020 0000 0000 0000 FF0000FF //ul
|
|
0020 0000 0020 0000 0020 0000 00FF00FF //ur
|
|
0020 0000 0000 0000 0020 FFE0 0000FFFF //lr
|
|
0000 0000 0000 0000 0000 FFE0 FFFF00FF //ll
|
|
0010 0000 0010 0000 0010 FFF0 FFFFFFFF //center
|
|
Notice the centerpoint chose mapping pins in the center of the image. Conforming to the image's properties ensures the image is rendered correctly.
|
|
|
|
|
|
Image sizes and other properties can be found in SubDrag's image index.
|
|
-------------
|
|
|
|
04 point table offset command
|
|
The RSP 04 command is used to set the offset within a point table. At most, 16 points can be declared at one time. Functionally, rooms and objects will be concidered seperately.
|
|
|
|
Rooms are the simplest case. The offset command is a literal offset within the point data file. You can expect:
|
|
04F00100 00000000
|
|
to grab the first 16 entries at the beginning of the point table. The 0100 indicates, in bytes, how much data is being copied. If only 8 points are being pulled, the command would look like this:
|
|
04700080 00000000
|
|
The offset is a literal offset in the point data binary. For instance,
|
|
04F00100 00000100
|
|
grabs the next 0x100 bytes at file offset 0x100. To get the next 5 points, you would use this:
|
|
04400050 00000200
|
|
-and the next 10 points...
|
|
049000A0 00000250
|
|
|
|
Objects are more difficult. Each offset is relative to the pointer set by the display list command. In other words-
|
|
04F00100 04000000
|
|
-would load the first 16 points and 0x100 bytes from the beginning of the display list's point table.
|
|
05 offsets can also be used to specificly state the offset within the file to start pulling points from.
|
|
|
|
-------------
|
|
|
|
B1 4-triangle draw routine
|
|
The primary triangle drawing routine draws up to four at once. This function is unique to Rare's games, so don't expect it to work with other ucodes.
|
|
The format is a little unusual, refering to the points in the point table loaded perviously. The values are one nibble long, ranging from 0-F, or point 1 to 16. If all the points are set to 0, that triangle is not drawn. Below, the first point in the triangle is listed as x, the second y, and the third z.
|
|
B100zzzz yxyxyxyx
|
|
0000000z 000000yx first triangle
|
|
000000z0 0000yx00 second triangle
|
|
00000z00 00yx0000 third triangle
|
|
0000z000 yx000000 fourth triangle
|
|
|
|
B1000002 00000010 Creates one triangle using points {0,1,2}
|
|
B1000042 00003110 Creates two triangles, using points {0,1,2} and {1,3,4}
|
|
B1000242 00413110 Creates three triangles; {0,1,2}, {1,3,4}, and {1,4,2}
|
|
B1007242 65413110 Creates four triangles; {0,1,2}, {1,3,4}, {1,4,2}, and {5,6,7}
|
|
|
|
Remember, don't try to use points that were not previously called with the 04 command. If only five points were declared (0-4), then the last example, B1007242 65413110 would be invalid and cause an exception.
|
|
|
|
-------------
|
|
|
|
BF single triangle draw routine
|
|
These are very infrequently used. They draw only one triangle at a time, again refering to the points in the point table loaded previously. Before each value can be used, they must be divided by 10 (0xA) to return the point index number.
|
|
BF000000 00zzyyxx
|
|
|
|
BF000000 00140A00 Creates a triangle using points {0,1,2}, or 0/A=0, A/A=1, 14/A=2
|
|
BF000000 00968C82 Creates a triangle using points {13,14,15}, or 82/A=D, 8C/A=E, 96/A=F
|
|
|
|
Again, you still can't use points that haven't been loaded with the 04 vertex command.
|
|
|
|
-------------
|
|
|