The best way to learn is by doing...
Low-level HowTos
-Get and Color Pixels-
This will get the color of a pixel at the mouse's position and display it in a box on the bottom left of the screen. Make sure not to draw outside of memory.
In scene1.c
At the very end of the file type:
int pixel;
pixel = rI.scrnBuff[(int)xMousePos][(int)yMousePos];
for (y = 0; y < rI.yWin/4; y++)
for (x = 0; x < rI.xWin/4; x++)
rI.scrnBuff[x][y] = pixel;
-Draw a 3d Line-
This will draw a blue line.
In scene1.c
At the very end of the file type:
line(0, 0, 0, 200, 100, -1000, 0xFF0000, rI);
To draw a line with fog:
fLine(0, 0, 0, 200, 100, -1000, 0xFF0000, bgColor, rI);
To draw a line with antialiasing:
aLine(0, 0, 0, 200, 100, -1000, 0xFF0000, rI);
To draw a line with antialiasing and fog:
afLine(0, 0, 0, 200, 100, -1000, 0xFF0000, bgColor, rI);
-Rotate a Point-
This will rotate a blue line a 180 around the z axis.
In scene1.c
At the very end of the file type:
float xLine, yLine, zLine;
xLine = 200; yLine = 100; zLine = -1000;
rotatePoint(&xLine, &yLine, &zLine, 0, 0, 0, 0, 0, M_PI);
line(0, 0, 0, xLine, yLine, zLine, 0xFF0000, rI);
Rotation and Mesh Manipulation Howto
In scene1.c
-Methods of Rotating-
First make sure the camera angle doesn't change.
Find "// angle the camera to normal position" and replace:
if (xScreenRot > -1.3)
xScreenRot = xScreenRot - 0.1;
With:
//if (xScreenRot > -1.3)
//xScreenRot = xScreenRot - 0.1;
Now we will insert a function that will allow us to rotate a mesh with the mouse.
Find "// return global and transformation data back to its original state" and just before that paste:
globalRotRelToScrn(character_STATICGLOBAL, character_STATICTRANS, character_MESHCNT,
0, 0, 0, xDragLgth/50, yDragLgth/50, 0);
Compile and run...
Here is the function:
globalRotRelToScrn(mesh_GLOBAL, mesh_TRANS, mesh_MESHCNT,
xCenter, yCenter, zCenter, lr, tb, cc)
It can rotate the whole mesh from left to right, right to left, top down, bottom up, or clockwise, counterclockwise.
Now try this function:
globalRot(character_STATICGLOBAL, character_STATICTRANS, character_MESHCNT,
0, 0, 0, xDragLgth/50, yDragLgth/50, 0);
Compile and run...
globalRot(mesh_GLOBAL, mesh_TRANS, mesh_MESHCNT,
xCenter, yCenter, zCenter, xAxis, yAxis, zAxis)
Unlike globalRotRelToScrn this function will rotate the mesh around its x axis first then the y and z axises in serial rather than all at once.
Here's a function that will rotate only part of a mesh:
localRotRelToScrn(character_STATICTRANS, 2,
0, 0, 0, xDragLgth/50, yDragLgth/50, 0);
It should rotate the head of the character mesh.
Compile and run...
Some other functions:
localRot(mesh_TRANS, transformation data block location,
xCenter, yCenter, zCenter, xAxis, yAxis, zAxis)
globalMove(mesh_GLOBAL, mesh_TRANS, mesh_MESHCNT, xMove, yMove, zMove)
localMove(mesh_TRANS, transformation data block location, xMove, yMove, zMove)
globalResize(mesh_GLOBAL, mesh_TRANS, mesh_MESHCNT,
xCenter, yCenter, zCenter, xSize, ySize, zSize)
localResize(mesh_TRANS, transformation data block location,
xCenter, yCenter, zCenter, xSize, ySize, zSize)
Cheat Codes
In scene1.c
-Mini Dome-
Find "// resize the dome" and replace:
globalResize(dome1_GLOBAL, dome1_TRANS, dome1_MESHCNT, 0, 0, 0, 1000, 1000, 100);
With:
globalResize(dome1_GLOBAL, dome1_TRANS, dome1_MESHCNT, 0, 0, 0, 2, 2, 2);
Compile and run...
-Mini Course-
Find "// resize the course" and replace:
globalResize(course1_GLOBAL, course1_TRANS, course1_MESHCNT, 0, 0, 0, 20, 20, 20);
With:
globalResize(course1_GLOBAL, course1_TRANS, course1_MESHCNT, 0, 0, 0, 5, 5, 5);
Compile and run...
-Fast Moving Clouds-
Find "// rotate the sky and apply the correct rotation to the dome" and replace:
zDomeRotSave = fmod(zDomeRotSave + 0.002, M_PI * 2);
With:
zDomeRotSave = fmod(zDomeRotSave + 0.2, M_PI * 2);
Compile and run...
-Flawless Victory-
Find "// rotate the character while falling" and replace:
xCharacterRot = xCharacterRot + 0.2;
zCharacterRot = zCharacterRot + 0.1;
With:
static float separate = 0;
static float run1_STATICTRANS[sizeof(character_TRANS)/sizeof(float)];
for (i = 0; i < character_MESHCNT; i++)
{
if (!separate)
{
run1_STATICTRANS[0+i*9] = run1_TRANS[0+i*9];
run1_STATICTRANS[5+i*9] = run1_TRANS[5+i*9];
}
run1_TRANS[0+i*9] = separate*(1+i);
run1_TRANS[5+i*9] = separate*(1+i);
}
separate = separate + 2;
Find "// if the character falls past a certain point reset the game" and replace:
if (course2_TRANS[5] > 5000)
{
With:
if (course1_TRANS[5] > 50000)
{
separate = 0;
for (i = 0; i < character_MESHCNT; i++)
{
run1_TRANS[0+i*9] = run1_STATICTRANS[0+i*9];
run1_TRANS[5+i*9] = run1_STATICTRANS[5+i*9];
}
Compile and run...
-Luigi Jump-
Find "// jump with legs apart" and remove:
if ((allowFlyUp) || (timeToFall))
{
for (i = 0; i < character_MESHCNT*9; i++)
character_TRANS[i] = run1_TRANS[i];
runCharacter = 0;
}
Compile and run...
-Spin-
Find "// turn the character toward the correct direction" and replace:
zCharacterRot = zCharacterRot + turnRight + turnLeft;
With:
zCharacterRot = zCharacterRot + turnRight*-8 + turnLeft*-8;
Compile and run...
-Moon Jump-
Find "// make the character fall by moving the course up" and replace:
fallSpeed = fallSpeed + 15;
With:
fallSpeed = fallSpeed + 5;
Find "// make the character jump on key down if ready" and replace:
flyUpHeight = 140;
With:
flyUpHeight = 240;
Compile and run...
-Float-
Find "// make the character fall by moving the course up" and replace:
fallSpeed = fallSpeed + 15;
With:
if (!jumpUp)
fallSpeed = fallSpeed + 12;
else
fallSpeed = 2;
Compile and run...
-Under View-
Find "// angle the camera to normal position" and replace:
if (xScreenRot > -1.3)
With:
if (xScreenRot > -1.8)
Compile and run...
-Night Time-
Find "// color background" and replace:
bgColor = 0xFFFFFF;
With:
bgColor = 0x555555;
Compile and run...
Changing and Adding Meshes
In scene1.c
-Add Another Platform To The Course-
You will need "blender" (3d modelling software).
Also make sure you have placed the python files, which you will find in the "ImportExport3dInC" folder of the game engine, in the correct blender directory.
If you run blender and go to "File" then "Import" you should see "C code (.c)...".
Now run blender and press "A" a couple of times, this should unhighlight and highlight all the objects in the 3d window.
Press "X" and click "Erase Selected Object(s)".
Make sure you are in object mode and not edit mode. To change between object and edit mode press "Tab".
After erasing all objects go to "File", "Import" then "C code (.c)..." and import "course1Poly.c" not "course1.c".
"course1Poly.c" is in a polygon format and "course1.c" is in a vector format and the import script will only understand the polygon format.
Note: Use the middle mouse botton to navigate. Click to move the cursor and press "C" to move the window where the cursor is.
Once "course1Poly.c" has been imported right click on some piece of the course. Hold "Ctrl" and press "D". This should duplicate the selected piece. Move it to some other place and left click to place it. If you want to move it again press "G". To move it to a specific location press "N" to bring up the "Transform Properties" window and change the location values. (you can also change the scale)
Note: Do not change the rotation of a platform. The code in "scene1.c" calculates the platform's surface by using the object's scale relative to its center and ignores the rotation.
Export the new course back to "course1Poly.c" by going to "File", "Export" then "C code (.c)...".
Copy "course1Poly.c" and "course1Poly.h" to "course1.c" and "course1.h".
Run "polyToLine" which is in the meshes directory to convert the polygon info within "course1.c" to vectors (It doesn't have to be converted but this makes it nicer). Drag and drop "course1.c" into the program. Press "N" to change the name to course1, Press "C" to convert and "W" to write to files.
Compile and run...
-Adding A New Model-
You will need "blender" (3d modelling software).
Also make sure you have placed the python files, which you will find in the "ImportExport3dInC" folder of the game engine, in the correct blender directory.
If you run blender and go to "File" then "Import" you should see "C code (.c)...".
Now run blender and press "A" a couple of times, this should unhighlight and highlight all the objects in the 3d window.
Press "X" and click "Erase Selected Object(s)".
Make sure you are in object mode and not edit mode. To change between object and edit mode press "Tab".
Move the cursor to the center. Go to "View" then "View Properties..." to open the View Properties window and change the 3d cursor to position 0,0,0.
Add a mesh by going to "Add", "Mesh" then "Monkey".
Go to "File", "Export" then "C code (.c)..." and export the model as "monkey.c" into the "meshes" directory.
Resize the mesh from monkey.c.
Open "monkey.c".
Find "//transformation data" and replace:
1.000000, 1.000000, 1.000000,
With:
100.000000, 100.000000, 100.000000,
Add monkey.c to the makefile...
For Windows:
Double click game Dev-C++ Project File and add the files "monkey.c" and "monkey.h" to the project.
For Linux:
Open "Makefile".
Add this near the bottom of the makefile:
meshes/monkey.o: meshes/monkey.c
//TAB// $(CC) -c meshes/monkey.c -o meshes/monkey.o $(CFLAGS)
Replace //TAB// with a tab.
Add this to "OBJ =" within the makefile:
meshes/monkey.o
Add monkey.c to the source code...
Add this near the top of main.c:
#include "meshes/monkey.h"
Open "scene1.c".
Add this under "if (initializeDrawScene1) {":
globalRot(monkey_GLOBAL, monkey_TRANS, monkey_MESHCNT, 0, 0, 0, M_PI/2, 0, 0);//to rotate upright
for (i = 0; i < 9; i++)
monkey_STATICGLOBAL[i] = monkey_GLOBAL[i];
for (i = 0; i < sizeof(monkey_TRANS)/sizeof(float); i++)
monkey_STATICTRANS[i] = monkey_TRANS[i];
for (i = 0; i < sizeof(monkey_POINT)/sizeof(float); i++)
monkey_STATICPOINT[i] = monkey_POINT[i];
Add this at the end of "scene1.c":
// draw monkey
addRotLocSz(monkey_TRANS, monkey_POINT, monkey_POINTDATSZ,
monkey_STATICPOINT, monkey_MESHCNT);
addScreenRotLocSz(xScreenRot, yScreenRot, zScreenRot,
xScreenSize, yScreenSize, zScreenSize,
xScreenLoc, yScreenLoc, zScreenLoc,
monkey_POINT, monkey_POINTDATSZ, monkey_MESHCNT);
drawMesh(monkey_POINT, monkey_LINE, monkey_COLOR,
monkey_LINEDATSZ, monkey_MESHCNT, bgColor, antialiasing, rI);
Compile and run...
To place the monkey model somewhere in the environment.
Find this in "scene1.c":
// return global and transformation data back to its original state
// this will keep rounding errors from deforming the meshes
Add this right after:
for (i = 0; i < 9; i++)
monkey_GLOBAL[i] = monkey_STATICGLOBAL[i];
for (i = 0; i < sizeof(monkey_TRANS)/sizeof(float); i++)
monkey_TRANS[i] = monkey_STATICTRANS[i];
Add this right after "// apply the correct orientations":
// put the monkey in the right position
monkey_TRANS[3] = -300;
monkey_TRANS[4] = 800.0;
// keep the monkey with the course
globalRot(monkey_GLOBAL, monkey_TRANS, monkey_MESHCNT, 0, 0, 0, 0, 0, zCourseRotSave);
globalMove(monkey_GLOBAL, monkey_TRANS, monkey_MESHCNT,
-xCharacterPosSave, -yCharacterPosSave, -zCharacterPosSave);
globalMove(monkey_GLOBAL, monkey_TRANS, monkey_MESHCNT, 0, -(forward+backward), 0);
globalRot(monkey_GLOBAL, monkey_TRANS, monkey_MESHCNT, 0, 0, 0, 0, 0, (turnLeft+turnRight));
Find:
// If the character falls or jumps this changes the z
// position of the course and if you have objects placed on
// the course this is the place to change the z positions
// of those objects to keep them with the course.
Add this right after:
// put the monkey at the right height
monkey_TRANS[5] = 100.0;
Compile and run...
Menu Howto
I will add this just for the heck of it.
In scene0.c
Find:
drawAscII("ZOOM CAMERA = PAGEUP,PAGEDOWN", 10*rI.xWin/400, 10*rI.xWin/400,
15-rI.xCenter, -55+rI.yCenter, 0, 0, 0, 0, 0x0, bgColor, 1, rI);
Add this right after:
drawAscII("This is how to add menu text", 10*rI.xWin/400, 10*rI.xWin/400,
15-rI.xCenter, -75+rI.yCenter, 0, 0, 0, 0, 0x0, bgColor, 1, rI);
Compile and run...
Now at the game menu go to "VIEW CONTROLS" and you should see "This is how to add menu text".