example: Cleanup source files

This commit is contained in:
Antonio Niño Díaz 2022-10-16 14:40:35 +01:00
parent ccc8a67caf
commit db8add4d7e
32 changed files with 2033 additions and 1955 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -129,23 +129,17 @@ int main(void)
{
scanKeys(); // This function is needed for the GUI
printf("\x1b[0;0HSlide bar 1: %d ",
NE_GUISlideBarGetValue(SldBar1));
printf("\nSlide bar 2: %d ",
NE_GUISlideBarGetValue(SldBar2));
printf("\n\nRadio button 1: %d ",
NE_GUIRadioButtonGetValue(RaBtn1));
printf("\nRadio button 2: %d ",
NE_GUIRadioButtonGetValue(RaBtn2));
printf("\nRadio button 3: %d ",
NE_GUIRadioButtonGetValue(RaBtn3));
printf("\n\nCheck box: %d ",
NE_GUICheckBoxGetValue(ChBx));
printf("\n\nButton event: %d ",
NE_GUIObjectGetEvent(Button));
printf("\x1b[0;0H");
printf("Slide bar 1: %d \n", NE_GUISlideBarGetValue(SldBar1));
printf("Slide bar 2: %d \n", NE_GUISlideBarGetValue(SldBar2));
printf("\n");
printf("Radio button 1: %d \n", NE_GUIRadioButtonGetValue(RaBtn1));
printf("Radio button 2: %d \n", NE_GUIRadioButtonGetValue(RaBtn2));
printf("Radio button 3: %d \n", NE_GUIRadioButtonGetValue(RaBtn3));
printf("\n");
printf("Check box: %d \n", NE_GUICheckBoxGetValue(ChBx));
printf("\n");
printf("Button event: %d ", NE_GUIObjectGetEvent(Button));
// Draw things...
NE_Process(Draw3DScene);

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008, Ti-Ra-Nog
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -17,15 +17,14 @@
#include "texsphere_bin.h"
// Set the initial number of balls/spheres
#define NUM_BALLS 50
#define NUM_BALLS 50
// Set the maxium number of balls/spheres
#define MAX_NUM_BALLS 255
#define MAX_NUM_BALLS 255
// Set the minium number of balls/spheres
#define MIN_NUM_BALLS 0
#define MIN_NUM_BALLS 0
int NUM = NUM_BALLS;
// Pointers to objects...
NE_Camera *Camera;
NE_Model *Sphere[MAX_NUM_BALLS], *Cube;
NE_Material *Material, *Material2;
@ -33,203 +32,208 @@ NE_Material *Material, *Material2;
float mov;
typedef struct {
float x,y,z;
float vx,vy,vz;
float x,y,z;
float vx,vy,vz;
} ball_t;
ball_t Ball[MAX_NUM_BALLS];
void Draw3DScene(void)
{
scanKeys(); // Get keys information
int keys = keysHeld(); // Keys continously pressed
scanKeys(); // Refresh keypad
int keys = keysHeld(); // Keys continously pressed
mov += 0.5; // If B is pressed, increase camera rotation speed
NE_CameraUse(Camera); //Use camera and draw all objects.
mov += 0.5; // If B is pressed, increase camera rotation speed
NE_CameraUse(Camera); //Use camera and draw all objects.
// Rotate the camara every frame if the B Button is pressed (slowly)
if (!(keys & KEY_B))
NE_ViewRotate(0, 0, mov);
// Rotate the camara every frame if the B Button is pressed (slowly)
if (!(keys & KEY_B))
NE_ViewRotate(0, 0, mov);
// Draw the cube
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
// Draw the cube
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
// Draw every Sphere
NE_PolyFormat(31, 0, NE_LIGHT_ALL,NE_CULL_BACK, 0);
for (int i = 0; i < NUM; i++)
NE_ModelDraw(Sphere[i]);
// Draw every Sphere
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
for (int i = 0; i < NUM; i++)
NE_ModelDraw(Sphere[i]);
// Get some information AFTER drawing but BEFORE returning from the
// function.
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
// Get some information AFTER drawing but BEFORE returning from the function
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine 3D rendering in one screen.
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Init Nitro Engine 3D rendering in one screen.
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate objects
Cube = NE_ModelCreate(NE_Static); // Cube model
Material = NE_MaterialCreate(); // Material for the cube
Material2 = NE_MaterialCreate(); // Material fot the spheres
// Allocate objects
Cube = NE_ModelCreate(NE_Static); // Cube model
Material = NE_MaterialCreate(); // Material for the cube
Material2 = NE_MaterialCreate(); // Material fot the spheres
for (int i = 0; i < MAX_NUM_BALLS; i++) // Create all spheres
Sphere[i] = NE_ModelCreate(NE_Static);
for (int i = 0; i < MAX_NUM_BALLS; i++) // Create all spheres
Sphere[i] = NE_ModelCreate(NE_Static);
// Create and setup camera
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
6, 6, 6,
0, 0, 0,
0, 1, 0);
// Create and setup camera
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
6, 6, 6,
0, 0, 0,
0, 1, 0);
// Load sphere texture to its material
NE_MaterialTexLoad(Material2, GL_RGB, 64, 64,TEXGEN_TEXCOORD,
(u8 *) texsphere_bin);
// Load sphere texture to its material
NE_MaterialTexLoad(Material2, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texsphere_bin);
// Loop until it arrives to the max ball number
for (int i = 0; i < MAX_NUM_BALLS; i++) {
//Load every sphere model
NE_ModelLoadStaticMesh(Sphere[i], (u32 *)model_bin);
// Set Material2 to every Sphere
NE_ModelSetMaterial(Sphere[i],Material2);
}
// Loop until it arrives to the max ball number
for (int i = 0; i < MAX_NUM_BALLS; i++)
{
//Load every sphere model
NE_ModelLoadStaticMesh(Sphere[i], (u32 *)model_bin);
// Set Material2 to every Sphere
NE_ModelSetMaterial(Sphere[i],Material2);
}
// Load cube texture to its material
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *) texcube_bin);
// Load the cube mesh
NE_ModelLoadStaticMesh(Cube,(u32*) cube_bin);
// Set the cube material
NE_ModelSetMaterial(Cube,Material);
// Resize the cube (it's originally 7x7x7, now it's 21x21x21)
NE_ModelScale(Cube, 3, 3, 3);
// Load cube texture to its material
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texcube_bin);
// Load the cube mesh
NE_ModelLoadStaticMesh(Cube, (u32*)cube_bin);
// Set the cube material
NE_ModelSetMaterial(Cube, Material);
// Resize the cube (it's originally 7x7x7, now it's 21x21x21)
NE_ModelScale(Cube, 3, 3, 3);
// Set up the white light
NE_LightSet(0,NE_White,0,1,0);
// Set up the white light
NE_LightSet(0, NE_White, 0, 1, 0);
//Enable shading
NE_ShadingEnable(true);
//Enable shading
NE_ShadingEnable(true);
// Set cube coordinates to (0, 0, 0)
NE_ModelSetCoord(Cube, 0, 0, 0);
// Set cube coordinates to (0, 0, 0)
NE_ModelSetCoord(Cube, 0, 0, 0);
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < MAX_NUM_BALLS; i++) {
// Set the speed for each axis
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < MAX_NUM_BALLS; i++)
{
// Set the speed for each axis
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 10;
// Randomly invert the speeds
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Randomly invert the speeds
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Initialize some variables
int fpscount = 0;
int oldsec = 0;
int seconds = 0;
// Initialize some variables
int fpscount = 0;
int oldsec = 0;
int seconds = 0;
while (1) {
// Time Variables/Structs
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
while (1)
{
// Time Variables/Structs
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
// Have we moved to a new second?
if (seconds != oldsec) {
oldsec = seconds; // old second = new second
printf("\x1b[0;20HFPS: %d", fpscount);
fpscount = 0; // Reset FPS count for next second
}
// Have we moved to a new second?
if (seconds != oldsec)
{
oldsec = seconds; // old second = new second
printf("\x1b[0;20HFPS: %d", fpscount);
fpscount = 0; // Reset FPS count for next second
}
// Get keys information
scanKeys();
uint32 keys = keysHeld(); // Keys Continously pressed
uint32 keysd = keysDown(); // Keys NOW pressed (only this frame)
// Get keys information
scanKeys();
uint32 keys = keysHeld(); // Keys Continously pressed
uint32 keysd = keysDown(); // Keys NOW pressed (only this frame)
// Set the model rotation for every Sphere
for (int i = 0; i < NUM; i++)
NE_ModelRotate(Sphere[i], 25 / i, -25 / i, 25 / i);
// Set the model rotation for every Sphere
for (int i = 0; i < NUM; i++)
NE_ModelRotate(Sphere[i], 25 / i, -25 / i, 25 / i);
// Calculate the model position for every model
for (int i = 0; i < NUM; i++) {
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 10.5) || (Ball[i].x <= -10.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 9.5) || (Ball[i].y <= -9.0))
Ball[i].vy *= -1;
if ((Ball[i].z >= 10.5) || (Ball[i].z <= -10.5))
Ball[i].vz *= -1;
// Calculate the model position for every model
for (int i = 0; i < NUM; i++)
{
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 10.5) || (Ball[i].x <= -10.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 9.5) || (Ball[i].y <= -9.0))
Ball[i].vy *= -1;
if ((Ball[i].z >= 10.5) || (Ball[i].z <= -10.5))
Ball[i].vz *= -1;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Update position
NE_ModelSetCoord(Sphere[i],
Ball[i].x, Ball[i].y, Ball[i].z);
}
// Update position
NE_ModelSetCoord(Sphere[i], Ball[i].x, Ball[i].y, Ball[i].z);
}
// Set all balls to (0, 0, 0) position.
if (keys & KEY_Y) {
for (int i = 0; i < NUM; i++) {
Ball[i].x = 0;
Ball[i].y = 0;
Ball[i].z = 0;
}
}
// Set all balls to (0, 0, 0) position.
if (keys & KEY_Y)
{
for (int i = 0; i < NUM; i++)
{
Ball[i].x = 0;
Ball[i].y = 0;
Ball[i].z = 0;
}
}
printf("\x1b[3;0HPolygon count: %d ", NUM * 48);
printf("\x1b[3;0HPolygon count: %d ", NUM * 48);
printf("\x1b[6;0HUp: Increase Ball Number.");
printf("\x1b[7;0HDown: Decrease Ball Number.");
printf("\x1b[8;0HR: Increase Ball Number by one.");
printf("\x1b[9;0HL: Decrease Ball Number by one.");
printf("\x1b[10;0HB: Stop camera rotation.");
printf("\x1b[11;0HY: Set all balls to 0 position.");
printf("\x1b[6;0HUp: Increase Ball Number.");
printf("\x1b[7;0HDown: Decrease Ball Number.");
printf("\x1b[8;0HR: Increase Ball Number by one.");
printf("\x1b[9;0HL: Decrease Ball Number by one.");
printf("\x1b[10;0HB: Stop camera rotation.");
printf("\x1b[11;0HY: Set all balls to 0 position.");
// Draw scene
NE_Process(Draw3DScene);
// Draw scene
NE_Process(Draw3DScene);
// Press UP: Increase the balls number
if ((keys & KEY_UP) && (NUM != MAX_NUM_BALLS))
NUM++;
// Press DOWN: Decrease the balls number
if ((keys & KEY_DOWN) && (NUM != MIN_NUM_BALLS))
NUM--;
// Press R: Increase the balls number by one
if ((keysd & KEY_R) && (NUM != MAX_NUM_BALLS))
NUM++;
// Press L: Decrease the balls number by one
if ((keysd & KEY_L) && (NUM != MIN_NUM_BALLS))
NUM--;
// Press UP: Increase the balls number
if ((keys & KEY_UP) && (NUM != MAX_NUM_BALLS))
NUM++;
// Press DOWN: Decrease the balls number
if ((keys & KEY_DOWN) && (NUM != MIN_NUM_BALLS))
NUM--;
// Press R: Increase the balls number by one
if ((keysd & KEY_R) && (NUM != MAX_NUM_BALLS))
NUM++;
// Press L: Decrease the balls number by one
if ((keysd & KEY_L) && (NUM != MIN_NUM_BALLS))
NUM--;
printf("\x1b[2;0HBalls Number: %d ", NUM);
printf("\x1b[2;0HBalls Number: %d ", NUM);
// Wait for next frame
NE_WaitForVBL(0);
fpscount++; // Increase the fps count
}
// Wait for next frame
NE_WaitForVBL(0);
fpscount++; // Increase the fps count
}
return 0;
return 0;
}

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008, Ti-Ra-Nog
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -23,13 +23,13 @@
#endif
// Set the initial number of balls/spheres
#define NUM_BALLS 50
#define NUM_BALLS 50
// Set the initial number of balls/spheres for the second scene
#define SCENE2_BALLS 10
#define SCENE2_BALLS 10
// Set the maxium number of balls/spheres
#define MAX_NUM_BALLS 255
#define MAX_NUM_BALLS 255
// Set the minium number of balls/spheres
#define MIN_NUM_BALLS 0
#define MIN_NUM_BALLS 0
int NUM = NUM_BALLS;
@ -41,13 +41,13 @@ NE_Material *Material3;
bool camera_swap = false;
#define SUMX 3
#define SUMY 1
#define SUMZ 2
#define SUMX 3
#define SUMY 1
#define SUMZ 2
typedef struct {
float x, y, z;
float vx, vy, vz;
float x, y, z;
float vx, vy, vz;
} ball_t;
ball_t Ball[MAX_NUM_BALLS];
@ -61,401 +61,428 @@ int posz2 = 0;
void Draw3DScene(void)
{
if (camera_swap)
NE_CameraUse(Camara);
else
NE_CameraUse(Camara2);
if (camera_swap)
NE_CameraUse(Camara);
else
NE_CameraUse(Camara2);
NE_ViewRotate(posx, posy, posz);
NE_ViewRotate(posx, posy, posz);
// Set the culling to none
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
NE_ModelDraw(Cube2);
// Set the culling to none
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
NE_ModelDraw(Cube2);
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
// Draw all spheres
for (int i = 0; i < SCENE2_BALLS; i++)
NE_ModelDraw(Sphere[i]);
// Draw all spheres
for (int i = 0; i < SCENE2_BALLS; i++)
NE_ModelDraw(Sphere[i]);
printf("\x1b[19;1HPolygon RAM1: %d \n Vertex RAM1: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
printf("\x1b[19;1HPolygon RAM1: %d \n Vertex RAM1: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
void Draw3DScene2(void)
{
if (camera_swap)
NE_CameraUse(Camara2);
else
NE_CameraUse(Camara);
if (camera_swap)
NE_CameraUse(Camara2);
else
NE_CameraUse(Camara);
NE_ViewRotate(posx2, posy2, posz2);
NE_ViewRotate(posx2, posy2, posz2);
// Set the culling to none
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
NE_ModelDraw(Cube2);
// Set the culling to none
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_NONE, 0);
NE_ModelDraw(Cube);
NE_ModelDraw(Cube2);
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
// Draw all spheres
for (int i = SCENE2_BALLS; i < NUM; i++)
NE_ModelDraw(Sphere[i]);
// Draw all spheres
for (int i = SCENE2_BALLS; i < NUM; i++)
NE_ModelDraw(Sphere[i]);
printf("\x1b[21;1HPolygon RAM2: %d \n Vertex RAM2: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
printf("\x1b[21;1HPolygon RAM2: %d \n Vertex RAM2: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
void dual(void)
{
char file[200];
bool noise_effect = false;
bool sine_effect = false;
bool recording = false;
bool auto_rotate = false;
bool hide_text = false;
char file[200];
bool noise_effect = false;
bool sine_effect = false;
bool recording = false;
bool auto_rotate = false;
bool hide_text = false;
// Screenshot number count
int nc = 0;
int sc = 0;
// Screenshot number count
int nc = 0;
int sc = 0;
// Allocate all needed objects
for (int i = 0; i < MAX_NUM_BALLS; i++)
Sphere[i] = NE_ModelCreate(NE_Static);
// Allocate all needed objects
for (int i = 0; i < MAX_NUM_BALLS; i++)
Sphere[i] = NE_ModelCreate(NE_Static);
Cube = NE_ModelCreate(NE_Static);
Cube2 = NE_ModelCreate(NE_Static);
Camara = NE_CameraCreate();
Camara2 = NE_CameraCreate();
Material = NE_MaterialCreate();
Material2 = NE_MaterialCreate();
Cube = NE_ModelCreate(NE_Static);
Cube2 = NE_ModelCreate(NE_Static);
Camara = NE_CameraCreate();
Camara2 = NE_CameraCreate();
Material = NE_MaterialCreate();
Material2 = NE_MaterialCreate();
#ifdef FAT_MESH_TEXT
NE_MaterialTexLoadFAT(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
"texsphere.bin");
NE_MaterialTexLoadFAT(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
"texsphere.bin");
for (int i = 0; i < MAX_NUM_BALLS; i++) {
// Load sphere model. Note that this is just to test. This is a
// really inefficient way to load the same model several times.
// Ideally, you'd load it once and then create models by cloning
// the first one.
NE_ModelLoadStaticMeshFAT(Sphere[i], "sphere.bin");
// Set Material to every Sphere
NE_ModelSetMaterial(Sphere[i], Material);
}
for (int i = 0; i < MAX_NUM_BALLS; i++)
{
// Load sphere model. Note that this is just to test. This is a
// really inefficient way to load the same model several times.
// Ideally, you'd load it once and then create models by cloning
// the first one.
NE_ModelLoadStaticMeshFAT(Sphere[i], "sphere.bin");
// Set Material to every Sphere
NE_ModelSetMaterial(Sphere[i], Material);
}
NE_MaterialTexLoadFAT(Material2, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
"texcube.bin");
NE_ModelLoadStaticMeshFAT(Cube, "cube.bin");
NE_ModelSetMaterial(Cube, Material2);
NE_MaterialTexLoadFAT(Material2, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
"texcube.bin");
NE_ModelLoadStaticMeshFAT(Cube, "cube.bin");
NE_ModelSetMaterial(Cube, Material2);
NE_ModelLoadStaticMeshFAT(Cube2, "cube.bin");
NE_ModelSetMaterial(Cube2, Material2);
NE_ModelLoadStaticMeshFAT(Cube2, "cube.bin");
NE_ModelSetMaterial(Cube2, Material2);
#else
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *) texsphere_bin);
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texsphere_bin);
for (int i = 0; i < MAX_NUM_BALLS; i++) {
// Load sphere model
NE_ModelLoadStaticMesh(Sphere[i], (u32 *)sphere_bin);
// Set material to every sphere
NE_ModelSetMaterial(Sphere[i], Material);
}
for (int i = 0; i < MAX_NUM_BALLS; i++)
{
// Load sphere model
NE_ModelLoadStaticMesh(Sphere[i], (u32 *)sphere_bin);
// Set material to every sphere
NE_ModelSetMaterial(Sphere[i], Material);
}
NE_MaterialTexLoad(Material2, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *) texcube_bin);
NE_ModelLoadStaticMesh(Cube, (u32 *) cube_bin);
NE_ModelSetMaterial(Cube, Material2);
NE_MaterialTexLoad(Material2, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texcube_bin);
NE_ModelLoadStaticMesh(Cube, (u32 *)cube_bin);
NE_ModelSetMaterial(Cube, Material2);
NE_ModelLoadStaticMesh(Cube2, (u32 *) cube_bin);
NE_ModelSetMaterial(Cube2, Material2);
NE_ModelLoadStaticMesh(Cube2, (u32 *)cube_bin);
NE_ModelSetMaterial(Cube2, Material2);
#endif
NE_ModelScale(Cube2, 3, 3, 3);
NE_ModelScale(Cube2, 3, 3, 3);
NE_LightSet(0, NE_White, 0, -1, 0);
NE_LightSet(0, NE_White, 0, -1, 0);
if (camera_swap) {
NE_CameraSet(Camara2,
-6, 6, -6,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camara,
-2, 2, -2,
0, 0, 0,
0, 1, 0);
} else {
NE_CameraSet(Camara,
-6, 6, -6,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camara2,
-2, 2, -2,
0, 0, 0,
0, 1, 0);
}
if (camera_swap)
{
NE_CameraSet(Camara2,
-6, 6, -6,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camara,
-2, 2, -2,
0, 0, 0,
0, 1, 0);
}
else
{
NE_CameraSet(Camara,
-6, 6, -6,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camara2,
-2, 2, -2,
0, 0, 0,
0, 1, 0);
}
NE_SetConsoleColor(NE_Red);
NE_SetConsoleColor(NE_Red);
// Clear screen and move cursor to the top
printf("\x1b[2J");
// Clear screen and move cursor to the top
printf("\x1b[2J");
printf("\x1b[1;1HTi-Ra-Nog 3D Test\n =================");
printf("\x1b[4;1HR: Save Video (So Sloooow).");
printf("\x1b[5;1HL: Save screenshot.");
printf("\x1b[6;1HA: Move camera (Held Button).");
printf("\x1b[7;1HB: Sine Effect.");
printf("\x1b[8;1HX: Noise Effect.");
printf("\x1b[9;1HY: Show/hide the text.");
printf("\x1b[10;1HStart: Move mesh (on/off).");
printf("\x1b[11;1HSelect: LCD Swap.");
printf("\x1b[12;1HUP: Scene mode 1.");
printf("\x1b[13;1HDown: Scene mode 2.");
printf("\x1b[23;8HPowered By Nitro Engine");
printf("\x1b[1;1HTi-Ra-Nog 3D Test\n =================");
printf("\x1b[4;1HR: Save Video (So Sloooow).");
printf("\x1b[5;1HL: Save screenshot.");
printf("\x1b[6;1HA: Move camera (Held Button).");
printf("\x1b[7;1HB: Sine Effect.");
printf("\x1b[8;1HX: Noise Effect.");
printf("\x1b[9;1HY: Show/hide the text.");
printf("\x1b[10;1HStart: Move mesh (on/off).");
printf("\x1b[11;1HSelect: LCD Swap.");
printf("\x1b[12;1HUP: Scene mode 1.");
printf("\x1b[13;1HDown: Scene mode 2.");
printf("\x1b[23;8HPowered By Nitro Engine");
for (int i = 0; i < NUM; i++)
NE_ModelScale(Sphere[i], 0.5, 0.5, 0.5);
for (int i = 0; i < NUM; i++)
NE_ModelScale(Sphere[i], 0.5, 0.5, 0.5);
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < MAX_NUM_BALLS; i++) {
// Set the absolute initial speed
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < MAX_NUM_BALLS; i++)
{
// Set the absolute initial speed
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 30;
// Randomly invert the speed
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Randomly invert the speed
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Set start coordinates/rotation for models using random formules
for (int i = MAX_NUM_BALLS; i < NUM; i++) {
// Set the absolute initial speed
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
// Set start coordinates/rotation for models using random formules
for (int i = MAX_NUM_BALLS; i < NUM; i++)
{
// Set the absolute initial speed
Ball[i].vx = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
Ball[i].vy = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
Ball[i].vz = (float)(1 + ((float)(rand() % 10) / 10)) / 1;
// Randomly invert the speed
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Randomly invert the speed
if (rand() & 1)
Ball[i].vx *= -1;
if (rand() & 1)
Ball[i].vy *= -1;
if (rand() & 1)
Ball[i].vz *= -1;
}
// Initialize some variables
int fpscount = 0;
int oldsec = 0;
int seconds = 0;
// Initialize some variables
int fpscount = 0;
int oldsec = 0;
int seconds = 0;
while (1) {
// Time Variables/Structs
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
while (1)
{
// Time Variables/Structs
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
// Has the second changed?
if (seconds != oldsec) {
oldsec = seconds; // old second = new second
printf("\x1b[1;24HFPS: %d", fpscount);
fpscount = 0; // Reset FPS count for next second
}
// Has the second changed?
if (seconds != oldsec)
{
oldsec = seconds; // old second = new second
printf("\x1b[1;24HFPS: %d", fpscount);
fpscount = 0; // Reset FPS count for next second
}
scanKeys();
uint32 keysd = keysDown();
uint32 keysh = keysHeld();
scanKeys();
uint32 keysd = keysDown();
uint32 keysh = keysHeld();
// Set rotation for every sphere
for (int i = 0; i < NUM; i++)
NE_ModelRotate(Sphere[i], 25 / i, -25 / i, 25 / i);
// Set rotation for every sphere
for (int i = 0; i < NUM; i++)
NE_ModelRotate(Sphere[i], 25 / i, -25 / i, 25 / i);
// Calculate the model position for every model based on its
// current position and speed
for (int i = 0; i < SCENE2_BALLS; i++) {
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 2.5) || (Ball[i].x <= -2.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 2.5) || (Ball[i].y <= -2.5))
Ball[i].vy *= -1;
if ((Ball[i].z >= 2.5) || (Ball[i].z <= -2.5))
Ball[i].vz *= -1;
// Calculate the model position for every model based on its
// current position and speed
for (int i = 0; i < SCENE2_BALLS; i++)
{
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 2.5) || (Ball[i].x <= -2.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 2.5) || (Ball[i].y <= -2.5))
Ball[i].vy *= -1;
if ((Ball[i].z >= 2.5) || (Ball[i].z <= -2.5))
Ball[i].vz *= -1;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Update position
NE_ModelSetCoord(Sphere[i],
Ball[i].x, Ball[i].y, Ball[i].z);
}
// Update position
NE_ModelSetCoord(Sphere[i], Ball[i].x, Ball[i].y, Ball[i].z);
}
// Calculate the model position for every model based on its
// current position and speed
for (int i = SCENE2_BALLS; i < NUM; i++) {
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 9.5) || (Ball[i].x <= -9.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 9.5) || (Ball[i].y <= -9.5))
Ball[i].vy *= -1;
if ((Ball[i].z >= 9.5) || (Ball[i].z <= -9.5))
Ball[i].vz *= -1;
// Calculate the model position for every model based on its
// current position and speed
for (int i = SCENE2_BALLS; i < NUM; i++)
{
// If the ball crashes with one of the faces of the cube
// invert the speed of the corresponding axis.
if ((Ball[i].x >= 9.5) || (Ball[i].x <= -9.5))
Ball[i].vx *= -1;
if ((Ball[i].y >= 9.5) || (Ball[i].y <= -9.5))
Ball[i].vy *= -1;
if ((Ball[i].z >= 9.5) || (Ball[i].z <= -9.5))
Ball[i].vz *= -1;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Add speed to the position to calculate the new
// position
Ball[i].x += Ball[i].vx;
Ball[i].y += Ball[i].vy;
Ball[i].z += Ball[i].vz;
// Update position
NE_ModelSetCoord(Sphere[i],
Ball[i].x, Ball[i].y, Ball[i].z);
}
// Update position
NE_ModelSetCoord(Sphere[i], Ball[i].x, Ball[i].y, Ball[i].z);
}
if (keysd & KEY_UP)
camera_swap = false;
if (keysd & KEY_UP)
camera_swap = false;
if (keysd & KEY_DOWN)
camera_swap = true;
if (keysd & KEY_DOWN)
camera_swap = true;
if (keysh & KEY_A) {
posx += SUMX;
posy += SUMY;
posz += SUMZ;
if (keysh & KEY_A)
{
posx += SUMX;
posy += SUMY;
posz += SUMZ;
posx2 += SUMX;
posy2 += SUMY;
posz2 += SUMZ;
}
posx2 += SUMX;
posy2 += SUMY;
posz2 += SUMZ;
}
NE_ProcessDual(Draw3DScene, Draw3DScene2);
fpscount++;
swiWaitForVBlank();
NE_ProcessDual(Draw3DScene, Draw3DScene2);
fpscount++;
swiWaitForVBlank();
// If SELECT is pressed swap top and bottom screens
if (keysd & KEY_SELECT)
lcdSwap();
// If SELECT is pressed swap top and bottom screens
if (keysd & KEY_SELECT)
lcdSwap();
if (keysd & KEY_L) {
// Generate file name
sprintf(file, "screen/screenshot_%04d.bmp", sc);
// Save the screenshot
NE_ScreenshotBMP(file);
// Increase the Screenshot number
sc++;
// Wait for next frame (this is necessary for not making
// artifacts in the next screenshot)
NE_WaitForVBL(0);
}
if (keysd & KEY_L)
{
// Generate file name
sprintf(file, "screen/screenshot_%04d.bmp", sc);
// Save the screenshot
NE_ScreenshotBMP(file);
// Increase the Screenshot number
sc++;
// Wait for next frame (this is necessary for not making
// artifacts in the next screenshot)
NE_WaitForVBL(0);
}
if (keysd & KEY_START) {
if (!auto_rotate)
auto_rotate = true;
else
auto_rotate = false;
}
if (keysd & KEY_START)
{
if (!auto_rotate)
auto_rotate = true;
else
auto_rotate = false;
}
if (auto_rotate) {
posx += SUMX;
posy += SUMY;
posz += SUMZ;
if (auto_rotate)
{
posx += SUMX;
posy += SUMY;
posz += SUMZ;
posx2 += SUMX;
posy2 += SUMY;
posz2 += SUMZ;
}
posx2 += SUMX;
posy2 += SUMY;
posz2 += SUMZ;
}
if (keysd & KEY_R) {
if (!recording)
recording = true;
else
recording = false;
}
if (keysd & KEY_R)
{
if (!recording)
recording = true;
else
recording = false;
}
if (recording) {
// Generate file name
sprintf(file,"video/vid/video_%04d.bmp",nc);
// Save the screenshot
NE_ScreenshotBMP(file);
// Increase the Screenshot number
nc++;
// Wait for next frame (this is needed for not making
// artifacs in the next screenshot)
NE_WaitForVBL(0);
}
if (recording)
{
// Generate file name
sprintf(file,"video/vid/video_%04d.bmp",nc);
// Save the screenshot
NE_ScreenshotBMP(file);
// Increase the Screenshot number
nc++;
// Wait for next frame (this is needed for not making
// artifacs in the next screenshot)
NE_WaitForVBL(0);
}
if (keysd & KEY_Y) {
if (!hide_text) {
hide_text = true;
if (keysd & KEY_Y)
{
if (!hide_text)
{
hide_text = true;
// Clear screen and move cursor to the top
printf("\x1b[2J");
// Clear screen and move cursor to the top
printf("\x1b[2J");
printf("\x1b[1;1H"
"Ti-Ra-Nog 3D Test\n"
" =================");
printf("\x1b[23;8HPowered By Nitro Engine");
} else {
hide_text = false;
printf("\x1b[4;1HR: Save Video (So Sloooow).");
printf("\x1b[5;1HL: Save screenshot.");
printf("\x1b[6;1HA: Move camera (Held Button).");
printf("\x1b[7;1HB: Sine Effect.");
printf("\x1b[8;1HX: Noise Effect.");
printf("\x1b[9;1HY: Show/hide the text.");
printf("\x1b[10;1HStart: Move mesh (on/off).");
printf("\x1b[11;1HSelect: LCD Swap.");
printf("\x1b[12;1HUP: Scene mode 1.");
printf("\x1b[13;1HDown: Scene mode 2.");
}
}
printf("\x1b[1;1H"
"Ti-Ra-Nog 3D Test\n"
" =================");
printf("\x1b[23;8HPowered By Nitro Engine");
}
else
{
hide_text = false;
printf("\x1b[4;1HR: Save Video (So Sloooow).");
printf("\x1b[5;1HL: Save screenshot.");
printf("\x1b[6;1HA: Move camera (Held Button).");
printf("\x1b[7;1HB: Sine Effect.");
printf("\x1b[8;1HX: Noise Effect.");
printf("\x1b[9;1HY: Show/hide the text.");
printf("\x1b[10;1HStart: Move mesh (on/off).");
printf("\x1b[11;1HSelect: LCD Swap.");
printf("\x1b[12;1HUP: Scene mode 1.");
printf("\x1b[13;1HDown: Scene mode 2.");
}
}
// If B is pressed use the sine effect. Stop if pressed again
if (keysd & KEY_B) {
if (!sine_effect) {
sine_effect = true;
NE_SpecialEffectSet(NE_SINE);
} else {
sine_effect = false;
NE_SpecialEffectSet(0);
}
}
// If B is pressed use the sine effect. Stop if pressed again
if (keysd & KEY_B)
{
if (!sine_effect)
{
sine_effect = true;
NE_SpecialEffectSet(NE_SINE);
}
else
{
sine_effect = false;
NE_SpecialEffectSet(0);
}
}
if (keysd & KEY_X) {
if (!noise_effect) {
noise_effect = true;
NE_SpecialEffectSet(NE_NOISE);
} else {
noise_effect = false;
NE_SpecialEffectSet(0);
}
}
}
if (keysd & KEY_X)
{
if (!noise_effect)
{
noise_effect = true;
NE_SpecialEffectSet(NE_NOISE);
}
else
{
noise_effect = false;
NE_SpecialEffectSet(0);
}
}
}
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
fatInitDefault();
fatInitDefault();
NE_InitDual3D();
NE_InitConsole();
NE_InitDual3D();
NE_InitConsole();
NE_WaitForVBL(0);
NE_WaitForVBL(0);
dual();
dual();
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -9,121 +9,123 @@
#include "texture_bin.h"
#include "model_bin.h"
// Pointers to objects...
NE_Camera *Camera;
NE_Model *Model, *Model2, *Model3;
NE_Material *Material;
void Draw3DScene(void)
{
// Set camera view and draw objects...
NE_CameraUse(Camera);
// Set camera
NE_CameraUse(Camera);
// This has to be used to use fog...
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, NE_FOG_ENABLE);
// This has to be used to use fog
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, NE_FOG_ENABLE);
NE_ModelDraw(Model);
NE_ModelDraw(Model2);
NE_ModelDraw(Model3);
// Draw models
NE_ModelDraw(Model);
NE_ModelDraw(Model2);
NE_ModelDraw(Model3);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
// Init console and Nitro Engine
NE_Init3D();
// libnds uses VRAM_C for the demo text console
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
consoleDemoInit();
// Init console and Nitro Engine
NE_Init3D();
// Use banks A and B for textures. libnds uses bank C for the demo text
// console.
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
consoleDemoInit();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Model2 = NE_ModelCreate(NE_Static);
Model3 = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Model2 = NE_ModelCreate(NE_Static);
Model3 = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Set camera coordinates
NE_CameraSet(Camera,
-1, 2, -1,
1, 1, 1,
0,1,0);
// Set camera coordinates
NE_CameraSet(Camera,
-1, 2, -1,
1, 1, 1,
0, 1, 0);
// Load objects...
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model2, (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model3, (u32 *)model_bin);
// Load models
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model2, (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model3, (u32 *)model_bin);
// Load texture
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Load texture
NE_MaterialTexLoad(Material, GL_RGB, 64, 64, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Assign the same material to every model object.
NE_ModelSetMaterial(Model, Material);
NE_ModelSetMaterial(Model2, Material);
NE_ModelSetMaterial(Model3, Material);
// Assign the same material to every model object.
NE_ModelSetMaterial(Model, Material);
NE_ModelSetMaterial(Model2, Material);
NE_ModelSetMaterial(Model3, Material);
// Set light and vector of light 0
NE_LightSet(0, NE_White, 0, -1, -1);
// Set light and vector of light 0
NE_LightSet(0, NE_White, 0, -1, -1);
// Set position of every object
NE_ModelSetCoord(Model, 1, 0, 1);
NE_ModelSetCoord(Model2, 3, 1, 3);
NE_ModelSetCoord(Model3, 7, 2, 7);
// Set position of every object
NE_ModelSetCoord(Model, 1, 0, 1);
NE_ModelSetCoord(Model2, 3, 1, 3);
NE_ModelSetCoord(Model3, 7, 2, 7);
// Set initial fog color to black
u32 color = NE_Black;
// Set initial fog color to black
u32 color = NE_Black;
// Some parameters
u16 depth = 0x7800;
u8 shift = 3;
u8 mass = 1;
// Some parameters
u16 depth = 0x7800;
u8 shift = 3;
u8 mass = 1;
while (1) {
// Get keys information
scanKeys();
uint32 keys = keysDown();
while (1)
{
// Refresh keys
scanKeys();
uint32 keys = keysDown();
// Modify parameters
if (keys & KEY_UP)
shift ++;
if (keys & KEY_DOWN)
shift --;
if (keys & KEY_X)
mass ++;
if(keys & KEY_B)
mass --;
if (keysHeld() & KEY_R)
depth += 0x20;
if(keysHeld() & KEY_L)
depth -= 0x20;
// Modify parameters
if (keys & KEY_UP)
shift ++;
if (keys & KEY_DOWN)
shift --;
if (keys & KEY_X)
mass ++;
if(keys & KEY_B)
mass --;
if (keysHeld() & KEY_R)
depth += 0x20;
if(keysHeld() & KEY_L)
depth -= 0x20;
// Wrap around parameters
shift &= 0xF;
mass &= 7;
depth = (depth & 0x0FFF) + 0x7000;
// Wrap values of parameters
shift &= 0xF;
mass &= 7;
depth = (depth & 0x0FFF) + 0x7000;
// Set fog color
if (keys & KEY_START)
color = NE_Black;
if (keys & KEY_SELECT)
color = NE_White;
// Set fog color
if (keys & KEY_START)
color = NE_Black;
if (keys & KEY_SELECT)
color = NE_White;
// Enable/update fog
NE_FogEnable(shift, color, 31, mass, depth);
// Enable/update fog
NE_FogEnable(shift, color, 31, mass, depth);
printf("\x1b[0;0H"
"Up/Down - Shift: %d \nX/B - Mass: %d \n"
"L/R - Depth: 0x%x \nSelect/Start - Change color.",
shift, mass, depth);
printf("\x1b[0;0H"
"Up/Down - Shift: %d \nX/B - Mass: %d \n"
"L/R - Depth: 0x%x \nSelect/Start - Change color.",
shift, mass, depth);
// Draw scene...
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -8,101 +8,101 @@
#include "nitrocat_bin.h"
// Create pointers to objects...
NE_Camera *Camera;
NE_Model *Model;
void Draw3DScene(void)
{
// Set rear plane color
NE_ClearColorSet(NE_Red, 31, 63);
// Set rear plane color
NE_ClearColorSet(NE_Red, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
}
void Draw3DScene2(void)
{
// Set rear plane color
NE_ClearColorSet(NE_Green, 31, 63);
// Set rear plane color
NE_ClearColorSet(NE_Green, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
}
int main(void)
{
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init dual 3D mode and console
NE_InitDual3D();
NE_InitConsole();
// Init dual 3D mode and console
NE_InitDual3D();
NE_InitConsole();
// Allocate objects...
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
// Allocate objects...
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
// Setup camera
NE_CameraSet(Camera,
-8, 0, 0,
0, 0, 0,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
-8, 0, 0,
0, 0, 0,
0, 1, 0);
// Load model...
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load model
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Set light color and direction
NE_LightSet(0,NE_White,-0.5,-0.5,-0.5);
// Set light color and direction
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// Enable shading...
NE_ShadingEnable(true);
// Enable shading
NE_ShadingEnable(true);
// Other test configurations
//NE_SpecialEffectNoiseConfig(31);
//NE_SpecialEffectSineConfig(3, 8);
// Other test configurations
//NE_SpecialEffectNoiseConfig(31);
//NE_SpecialEffectSineConfig(3, 8);
while (1) {
// Get keys information
scanKeys();
uint32 keys = keysHeld();
uint32 kdown = keysDown();
while (1)
{
// Refresh keys
scanKeys();
uint32 keys = keysHeld();
uint32 kdown = keysDown();
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Sine effect.\nB: Noise effect.\n"
"X: Deactivate effects.\nL/R: Pause/Unpause.");
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Sine effect.\nB: Noise effect.\n"
"X: Deactivate effects.\nL/R: Pause/Unpause.");
// Rotate model
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Rotate model
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Activate effects
if (kdown & KEY_B)
NE_SpecialEffectSet(NE_NOISE);
if (kdown & KEY_A)
NE_SpecialEffectSet(NE_SINE);
// Deactivate effects
if (kdown & KEY_X)
NE_SpecialEffectSet(0);
// Activate effects
if (kdown & KEY_B)
NE_SpecialEffectSet(NE_NOISE);
if (kdown & KEY_A)
NE_SpecialEffectSet(NE_SINE);
// Deactivate effects
if (kdown & KEY_X)
NE_SpecialEffectSet(0);
// Pause effects
if (kdown & KEY_L)
NE_SpecialEffectPause(true);
if (kdown & KEY_R)
NE_SpecialEffectPause(false);
// Pause effects
if (kdown & KEY_L)
NE_SpecialEffectPause(true);
if (kdown & KEY_R)
NE_SpecialEffectPause(false);
// Draw 3D scenes
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
// Draw 3D scenes
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -9,8 +9,6 @@
#include "nitrocat_bin.h"
#include "texture_bin.h"
// We use pointers to use less ram if we are not using 3D, but you can create
// the structs directly and you won't have to use Create/Delete functions.
NE_Camera *Camera;
NE_Model *Model;
NE_Material *Material;
@ -19,113 +17,115 @@ int shading, alpha, id;
void Draw3DScene(void)
{
//Set camera
NE_CameraUse(Camera);
// Set camera
NE_CameraUse(Camera);
//Set polygon format
NE_PolyFormat(alpha, id, NE_LIGHT_0, NE_CULL_BACK, shading);
// Set polygon format
NE_PolyFormat(alpha, id, NE_LIGHT_0, NE_CULL_BACK, shading);
//Draw model...
NE_ModelDraw(Model);
// Draw model
NE_ModelDraw(Model);
}
int main(void)
{
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
// Init console and Nitro Engine
NE_Init3D();
// libnds uses VRAM_C for the demo text console
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// This is needed to print text
consoleDemoInit();
// Init console and Nitro Engine
NE_Init3D();
// Use banks A and B for textures. libnds uses bank C for the demo text
// console.
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// This is needed to print text
consoleDemoInit();
// Allocate the things we will use
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate the objects we will use
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Set coordinates for the camera
NE_CameraSet(Camera,
-8, 0, 0,
0, 0, 0,
0, 1, 0);
// Set camera coordinates
NE_CameraSet(Camera,
-8, 0, 0,
0, 0, 0,
0, 1, 0);
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *) texture_bin);
// Load mesh from RAM and assign it to a model
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load texture from RAM and assign it to a material
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// Assign material to the model
NE_ModelSetMaterial(Model, Material);
//Set some propierties to Material
NE_MaterialSetPropierties(Material,
RGB15(24,24,24), //diffuse
RGB15(8,8,8), // ambient
RGB15(0,0,0), // specular
RGB15(0,0,0), // emission
false, false); // vtxcolor, useshininess
// Set some propierties to the material
NE_MaterialSetPropierties(Material,
RGB15(24, 24, 24), // Diffuse
RGB15(8, 8, 8), // Ambient
RGB15(0, 0, 0), // Specular
RGB15(0, 0, 0), // Emission
false, false); // Vertex color, use shininess table
// We set a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// Setup a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// This enables shading (you can choose normal or toon).
NE_ShadingEnable(true);
// This enables outlining in all polygons, so be careful
NE_OutliningEnable(true);
// This enables shading (you can choose normal or toon).
NE_ShadingEnable(true);
// This enables outlining in all polygons, so be careful
NE_OutliningEnable(true);
// We set the second outlining color to red.
// This will be used by polygons with ID 8 - 15.
NE_OutliningSetColor(1, NE_Red);
// We set the second outlining color to red.
// This will be used by polygons with ID 8 - 15.
NE_OutliningSetColor(1, NE_Red);
while(1) {
// Get keys information
scanKeys();
uint32 keys = keysHeld();
while (1)
{
// Refresh keys
scanKeys();
uint32 keys = keysHeld();
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Toon shading.\n"
"B: Change alpha value.\nY: Wireframe mode (alpha = 0)\n"
"X: Outlining.");
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Toon shading.\n"
"B: Change alpha value.\nY: Wireframe mode (alpha = 0)\n"
"X: Outlining.");
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Change shading type
if (keys & KEY_A)
shading = NE_TOON_SHADING;
else
shading = NE_MODULATION;
// Change shading type
if (keys & KEY_A)
shading = NE_TOON_HIGHLIGHT_SHADING;
else
shading = NE_MODULATION;
if (keys & KEY_B)
alpha = 15; // Transparent
else if (keys & KEY_Y)
alpha = 0; // Wireframe
else
alpha = 31; // Opaque
if (keys & KEY_B)
alpha = 15; // Transparent
else if (keys & KEY_Y)
alpha = 0; // Wireframe
else
alpha = 31; // Opaque
// Change id co change outlining color
if (keys & KEY_X)
id = 8;
else
id = 0;
// Change polygon ID to change outlining color
if (keys & KEY_X)
id = 8;
else
id = 0;
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, 2022, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -17,65 +17,66 @@ NE_Material *Texture;
void Draw3DScene(void)
{
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
NE_CameraUse(Camera);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_ModelDraw(Model);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_InitConsole();
NE_Init3D();
NE_InitConsole();
Camera = NE_CameraCreate();
Model = NE_ModelCreate(NE_Animated);
Animation = NE_AnimationCreate();
Camera = NE_CameraCreate();
Model = NE_ModelCreate(NE_Animated);
Animation = NE_AnimationCreate();
NE_AnimationLoad(Animation, robot_wave_dsa_bin);
NE_ModelLoadDSM(Model, robot_dsm_bin);
NE_ModelSetAnimation(Model, Animation);
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
NE_AnimationLoad(Animation, robot_wave_dsa_bin);
NE_ModelLoadDSM(Model, robot_dsm_bin);
NE_ModelSetAnimation(Model, Animation);
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
NE_CameraSet(Camera,
6, 3, -4,
0, 3, 0,
0, 1, 0);
NE_CameraSet(Camera,
6, 3, -4,
0, 3, 0,
0, 1, 0);
Texture = NE_MaterialCreate();
NE_MaterialTexLoad(Texture, GL_RGBA, 128, 128, TEXGEN_TEXCOORD,
Texture = NE_MaterialCreate();
NE_MaterialTexLoad(Texture, GL_RGBA, 128, 128, TEXGEN_TEXCOORD,
(void *)texture128_bin);
NE_ModelSetMaterial(Model, Texture);
NE_ModelSetMaterial(Model, Texture);
NE_LightSet(0, NE_White, -0.9, 0, 0);
NE_ClearColorSet(NE_Black, 31, 63);
NE_LightSet(0, NE_White, -0.9, 0, 0);
NE_ClearColorSet(NE_Black, 31, 63);
while(1) {
scanKeys();
uint32 keys = keysHeld();
while (1)
{
scanKeys();
uint32 keys = keysHeld();
if (keys & KEY_RIGHT)
NE_ModelRotate(Model,0,2,0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model,0,-2,0);
if (keys & KEY_UP)
NE_ModelRotate(Model,0,0,2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model,0,0,-2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model,0,2,0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model,0,-2,0);
if (keys & KEY_UP)
NE_ModelRotate(Model,0,0,2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model,0,0,-2);
printf("\x1b[0;0H"
"CPU%%: %d \nFrame: %.3f ",
NE_GetCPUPercent(), f32tofloat(NE_ModelAnimGetFrame(Model)));
printf("\x1b[0;0H"
"CPU%%: %d \nFrame: %.3f ",
NE_GetCPUPercent(), f32tofloat(NE_ModelAnimGetFrame(Model)));
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -26,73 +26,77 @@ NE_Model *Model[16];
void Draw3DScene(void)
{
// Setup camera and draw all objects.
NE_CameraUse(Camera);
// Setup camera and draw all objects.
NE_CameraUse(Camera);
int i;
for (i = 0; i < 16; i++)
NE_ModelDraw(Model[i]);
int i;
for (i = 0; i < 16; i++)
NE_ModelDraw(Model[i]);
// Get some information AFTER drawing but BEFORE returning from the
// function.
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
// Get some information AFTER drawing but BEFORE returning from the
// function.
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
int main()
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine.
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Init Nitro Engine.
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate space for everything.
for (int i = 0; i < 16; i++)
Model[i] = NE_ModelCreate(NE_Static);
// Allocate space for everything.
for (int i = 0; i < 16; i++)
Model[i] = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Camera = NE_CameraCreate();
// Setup camera
NE_CameraSet(Camera,
-3.5, 1.5, 1.25,
0, 1.5, 1.25,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
-3.5, 1.5, 1.25,
0, 1.5, 1.25,
0, 1, 0);
// Load model once
NE_ModelLoadStaticMesh(Model[0], (u32 *)model_bin);
// Load model once
NE_ModelLoadStaticMesh(Model[0], (u32 *)model_bin);
// Clone model to the test of the objects
for (int i = 1; i < 16; i++)
NE_ModelClone(Model[i], // Destination
Model[0]); // Source model
// Clone model to the test of the objects
for (int i = 1; i < 16; i++)
{
NE_ModelClone(Model[i], // Destination
Model[0]); // Source model
}
// Set up light
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
// Set up light
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
// Enable shading
NE_ShadingEnable(true);
// Enable shading
NE_ShadingEnable(true);
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < 16; i++) {
NE_ModelSetRot(Model[i], i, i * 30, i * 20);
NE_ModelSetCoord(Model[i], 0, i % 4, i / 4);
}
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < 16; i++)
{
NE_ModelSetRot(Model[i], i, i * 30, i * 20);
NE_ModelSetCoord(Model[i], 0, i % 4, i / 4);
}
while (1) {
// Rotate every model using random formules :P
for (int i = 0; i < 16; i++)
NE_ModelRotate(Model[i], -i, i % 5, 5 - i);
while (1)
{
// Rotate every model using random formules :P
for (int i = 0; i < 16; i++)
NE_ModelRotate(Model[i], -i, i % 5, 5 - i);
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -17,111 +17,117 @@ NE_Material *Material;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
}
void WaitLoop(void)
{
while(1) {
swiWaitForVBlank();
scanKeys();
if (keysHeld() & KEY_START)
return;
}
while(1)
{
swiWaitForVBlank();
scanKeys();
if (keysHeld() & KEY_START)
return;
}
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
if (!nitroFSInit(NULL)) {
iprintf("nitroFSInit failed.\nPress START to exit");
WaitLoop();
return 0;
}
if (!nitroFSInit(NULL))
{
iprintf("nitroFSInit failed.\nPress START to exit");
WaitLoop();
return 0;
}
// Allocate space for objects...
Model = NE_ModelCreate(NE_Animated);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
Animation = NE_AnimationCreate();
// Allocate space for objects...
Model = NE_ModelCreate(NE_Animated);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
Animation = NE_AnimationCreate();
// Setup camera
NE_CameraSet(Camera,
6, 3, -4,
0, 3, 0,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
6, 3, -4,
0, 3, 0,
0, 1, 0);
if (NE_ModelLoadDSMFAT(Model, "robot.dsm") == 0) {
printf("Couldn't load model...");
WaitLoop();
return 0;
}
if (NE_ModelLoadDSMFAT(Model, "robot.dsm") == 0)
{
printf("Couldn't load model...");
WaitLoop();
return 0;
}
if (NE_AnimationLoadFAT(Animation, "robot_wave.dsa") == 0) {
printf("Couldn't load animation...");
WaitLoop();
return 0;
}
if (NE_AnimationLoadFAT(Animation, "robot_wave.dsa") == 0)
{
printf("Couldn't load animation...");
WaitLoop();
return 0;
}
if (NE_FATMaterialTexLoadBMPtoRGBA(Material, "texture.bmp", true) == 0) {
printf("Couldn't load texture...");
WaitLoop();
return 0;
}
if (NE_FATMaterialTexLoadBMPtoRGBA(Material, "texture.bmp", true) == 0)
{
printf("Couldn't load texture...");
WaitLoop();
return 0;
}
// Assign material to the model
NE_ModelSetMaterial(Model, Material);
// Assign material to the model
NE_ModelSetMaterial(Model, Material);
NE_ModelSetAnimation(Model, Animation);
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
NE_ModelSetAnimation(Model, Animation);
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
NE_LightSet(0, NE_White, 0, -1, -1);
NE_LightSet(0, NE_White, 0, -1, -1);
NE_ClearColorSet(NE_Black, 31, 63);
NE_ClearColorSet(NE_Black, 31, 63);
float scale = 1;
float scale = 1;
while (1) {
printf("\x1b[0;0HPad: Rotate\nA/B: Scale\nSTART: Exit");
while (1)
{
printf("\x1b[0;0HPad: Rotate\nA/B: Scale\nSTART: Exit");
scanKeys();
uint32 keys = keysHeld();
scanKeys();
uint32 keys = keysHeld();
if (keys & KEY_START)
break;
if (keys & KEY_START)
break;
if (keys & KEY_A)
scale += 0.1;
if (keys & KEY_B)
scale -= 0.1;
if (keys & KEY_A)
scale += 0.1;
if (keys & KEY_B)
scale -= 0.1;
NE_ModelScale(Model, scale, scale, scale);
NE_ModelScale(Model, scale, scale, scale);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
// Draw scene...
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
}
// Draw scene...
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
}
return 0;
return 0;
}

View File

@ -21,87 +21,90 @@ NE_Material *OpaqueMaterial, *TransparentMaterial;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
if (!nitroFSInit(NULL)) {
iprintf("nitroFSInit failed.\nPress START to exit");
while(1) {
swiWaitForVBlank();
scanKeys();
if (keysHeld() & KEY_START)
return 0;
}
}
if (!nitroFSInit(NULL))
{
iprintf("nitroFSInit failed.\nPress START to exit");
while (1)
{
swiWaitForVBlank();
scanKeys();
if (keysHeld() & KEY_START)
return 0;
}
}
// Allocate space for objects...
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
OpaqueMaterial = NE_MaterialCreate();
TransparentMaterial = NE_MaterialCreate();
// Allocate space for objects...
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
OpaqueMaterial = NE_MaterialCreate();
TransparentMaterial = NE_MaterialCreate();
// Setup camera
NE_CameraSet(Camera,
-2, -2, -2,
0, 0, 0,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
-2, -2, -2,
0, 0, 0,
0, 1, 0);
// Load things from FAT...
NE_ModelLoadStaticMeshFAT(Model, "cube.bin");
NE_FATMaterialTexLoadBMPtoRGBA(TransparentMaterial, "bmp16bit_x1rgb5.bmp", 1);
NE_FATMaterialTexLoadBMPtoRGBA(OpaqueMaterial, "bmp24bit.bmp", 0);
// Load things from FAT
NE_ModelLoadStaticMeshFAT(Model, "cube.bin");
NE_FATMaterialTexLoadBMPtoRGBA(TransparentMaterial, "bmp16bit_x1rgb5.bmp", 1);
NE_FATMaterialTexLoadBMPtoRGBA(OpaqueMaterial, "bmp24bit.bmp", 0);
// Assign material to model
NE_ModelSetMaterial(Model, TransparentMaterial);
// Assign material to model
NE_ModelSetMaterial(Model, TransparentMaterial);
// Set up light
NE_LightSet(0, NE_White, 0, -1, -1);
// Set up light
NE_LightSet(0, NE_White, 0, -1, -1);
// Background color...
NE_ClearColorSet(NE_Gray, 31, 63);
// Background color
NE_ClearColorSet(NE_Gray, 31, 63);
// Reduce size of the cube, the original model is 7.5 x 7.5 x 7.5
NE_ModelScale(Model, 0.3, 0.3, 0.3);
// Reduce size of the cube, the original model is 7.5 x 7.5 x 7.5
NE_ModelScale(Model, 0.3, 0.3, 0.3);
while (1) {
scanKeys(); //Get keys information...
uint32 keys = keysDown();
while (1)
{
scanKeys(); //Get keys information...
uint32 keys = keysDown();
if (keys & KEY_START)
return 0;
if (keys & KEY_START)
return 0;
// Change material if pressed
if (keys & KEY_B)
NE_ModelSetMaterial(Model, OpaqueMaterial);
if (keys & KEY_A)
NE_ModelSetMaterial(Model, TransparentMaterial);
// Change material if pressed
if (keys & KEY_B)
NE_ModelSetMaterial(Model, OpaqueMaterial);
if (keys & KEY_A)
NE_ModelSetMaterial(Model, TransparentMaterial);
printf("\x1b[0;0HA/B: Change material.\n\nSTART: Exit.");
printf("\x1b[0;0HA/B: Change material.\n\nSTART: Exit.");
// Increase rotation, you can't get the rotation angle after
// this. If you want to know always the angle, you should use
// NE_ModelSetRot().
NE_ModelRotate(Model, 1, 2, 0);
// Increase rotation, you can't get the rotation angle after
// this. If you want to know always the angle, you should use
// NE_ModelSetRot().
NE_ModelRotate(Model, 1, 2, 0);
// Draw scene...
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw scene...
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -30,51 +30,52 @@ NE_Palette *Palette, *Palette2;
void Draw3DScene(void)
{
NE_2DViewInit();
NE_2DViewInit();
NE_2DDrawTexturedQuad(10, 10,
10 + 57, 10 + 100,
0, Material);
NE_2DDrawTexturedQuad(10, 10,
10 + 57, 10 + 100,
0, Material);
NE_2DDrawTexturedQuad(118, 10,
246, 138,
0, Material2);
NE_2DDrawTexturedQuad(118, 10,
246, 138,
0, Material2);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init 3D mode
NE_Init3D();
// Init 3D mode
NE_Init3D();
// Allocate objects for a material
Material = NE_MaterialCreate();
Palette = NE_PaletteCreate();
// Allocate objects for a material
Material = NE_MaterialCreate();
Palette = NE_PaletteCreate();
NE_MaterialTexLoad(Material,
GL_RGB32_A3, // Texture type
57, 100, // Width, height (in pixels)
TEXGEN_TEXCOORD, (u8 *) test_tex_bin);
NE_PaletteLoad(Palette, (u16 *)test_pal_bin, 32, GL_RGB32_A3);
NE_MaterialTexSetPal(Material, Palette);
NE_MaterialTexLoad(Material,
GL_RGB32_A3, // Texture type
57, 100, // Width, height (in pixels)
TEXGEN_TEXCOORD, (u8 *)test_tex_bin);
NE_PaletteLoad(Palette, (u16 *)test_pal_bin, 32, GL_RGB32_A3);
NE_MaterialTexSetPal(Material, Palette);
// Allocate objects for another material
Material2 = NE_MaterialCreate();
Palette2 = NE_PaletteCreate();
// Allocate objects for another material
Material2 = NE_MaterialCreate();
Palette2 = NE_PaletteCreate();
NE_MaterialTexLoad(Material2, GL_RGB4, 100, 100, TEXGEN_TEXCOORD,
(u8 *) test2_tex_bin);
NE_PaletteLoad(Palette2, (u16 *)test2_pal_bin, 32, GL_RGB4);
NE_MaterialTexSetPal(Material2, Palette2);
NE_MaterialTexLoad(Material2, GL_RGB4, 100, 100, TEXGEN_TEXCOORD,
(u8 *)test2_tex_bin);
NE_PaletteLoad(Palette2, (u16 *)test2_pal_bin, 32, GL_RGB4);
NE_MaterialTexSetPal(Material2, Palette2);
while (1) {
// Draw 3D scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
while (1)
{
// Draw 3D scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -13,66 +13,68 @@ NE_Model *Model[16];
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
for (int i = 0; i < 16; i++)
NE_ModelDraw(Model[i]);
for (int i = 0; i < 16; i++)
NE_ModelDraw(Model[i]);
// Get some information AFTER drawing but BEFORE returning from the
// function
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
// Get some information after drawing but before returning from the
// function
printf("\x1b[0;0HPolygon RAM: %d \nVertex RAM: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate space for everything
for (int i = 0; i < 16; i++)
Model[i] = NE_ModelCreate(NE_Static);
// Allocate space for everything
for (int i = 0; i < 16; i++)
Model[i] = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Camera = NE_CameraCreate();
// Setup camera
NE_CameraSet(Camera,
-3.5, 1.5, 1.25,
0, 1.5, 1.25,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
-3.5, 1.5, 1.25,
0, 1.5, 1.25,
0, 1, 0);
// Load model
for (int i = 0; i < 16; i++)
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
// Load model
for (int i = 0; i < 16; i++)
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
// Setup light
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
// Setup light
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
// Enable shading
NE_ShadingEnable(true);
// Enable shading
NE_ShadingEnable(true);
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < 16; i++) {
NE_ModelSetRot(Model[i], i, i * 30, i * 20);
NE_ModelSetCoord(Model[i], 0, i % 4, i / 4);
}
// Set start coordinates/rotation for models using random formules...
for (int i = 0; i < 16; i++)
{
NE_ModelSetRot(Model[i], i, i * 30, i * 20);
NE_ModelSetCoord(Model[i], 0, i % 4, i / 4);
}
while (1) {
// Rotate every model using random formules
for (int i = 0; i < 16; i++)
NE_ModelRotate(Model[i], -i, i % 5, 5 - i);
while (1)
{
// Rotate every model using random formules
for (int i = 0; i < 16; i++)
NE_ModelRotate(Model[i], -i, i % 5, 5 - i);
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -19,78 +19,77 @@ NE_Palette *Palette4, *Palette8;
void Draw3DScene(void)
{
// Set camera position and vector
NE_CameraUse(Camera);
// Set camera position and vector
NE_CameraUse(Camera);
// Draw model
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
// Draw model
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine, normal 3D mode
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Init Nitro Engine, normal 3D mode
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material8 = NE_MaterialCreate();
Material4 = NE_MaterialCreate();
Palette8 = NE_PaletteCreate();
Palette4 = NE_PaletteCreate();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material8 = NE_MaterialCreate();
Material4 = NE_MaterialCreate();
Palette8 = NE_PaletteCreate();
Palette4 = NE_PaletteCreate();
// Setup camera
NE_CameraSet(Camera,
-2, -2, -2,
0, 0, 0,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
-2, -2, -2,
0, 0, 0,
0, 1, 0);
// Load model
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
// Load model
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
// Load textures, this one's color 0 is transparent
NE_MaterialTexLoadBMPtoRGB256(Material4, Palette4,
(void *)bmp4bit_bin, 1);
// This one is completely opaque
NE_MaterialTexLoadBMPtoRGB256(Material8, Palette8,
(void *)bmp8bit_bin, 0);
// Load textures, this one's color 0 is transparent
NE_MaterialTexLoadBMPtoRGB256(Material4, Palette4, (void *)bmp4bit_bin, 1);
// This one is completely opaque
NE_MaterialTexLoadBMPtoRGB256(Material8, Palette8, (void *)bmp8bit_bin, 0);
// Assign material to model
NE_ModelSetMaterial(Model, Material8);
// Assign material to model
NE_ModelSetMaterial(Model, Material8);
// Set light 0 color and vector
NE_LightSet(0, NE_White, 0, -1, -1);
// Set light 0 color and vector
NE_LightSet(0, NE_White, 0, -1, -1);
// The original model of the cube is too big to fit, scale it down
NE_ModelScale(Model, 0.3, 0.3, 0.3);
// The original model of the cube is too big to fit, scale it down
NE_ModelScale(Model, 0.3, 0.3, 0.3);
printf("Press A/B to change texture");
printf("Press A/B to change texture");
while (1) {
scanKeys();
while (1)
{
scanKeys();
// Rotate model a bit
NE_ModelRotate(Model, 1, 2, 0);
// Rotate model a bit
NE_ModelRotate(Model, 1, 2, 0);
// Change material
if (keysHeld() & KEY_A)
NE_ModelSetMaterial(Model, Material8);
else if (keysHeld() & KEY_B)
NE_ModelSetMaterial(Model, Material4);
// Change material
if (keysHeld() & KEY_A)
NE_ModelSetMaterial(Model, Material8);
else if (keysHeld() & KEY_B)
NE_ModelSetMaterial(Model, Material4);
// Draw 3D scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
// Draw 3D scene
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -14,54 +14,55 @@ NE_Palette *Palette;
void Draw3DScene(void)
{
NE_2DViewInit();
NE_2DViewInit();
NE_2DDrawTexturedQuad(0, 0,
256, 192,
0, Material);
NE_2DDrawTexturedQuad(0, 0,
256, 192,
0, Material);
}
void Draw3DScene2(void)
{
NE_2DViewInit();
NE_2DViewInit();
NE_2DDrawTexturedQuad(64, 32,
64 + 128, 32 + 128,
0, Material2);
NE_2DDrawTexturedQuad(64, 32,
64 + 128, 32 + 128,
0, Material2);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init 3D mode
NE_InitDual3D();
// Init 3D mode
NE_InitDual3D();
// Allocate objects
Material = NE_MaterialCreate();
Material2 = NE_MaterialCreate();
Palette = NE_PaletteCreate();
// Allocate objects
Material = NE_MaterialCreate();
Material2 = NE_MaterialCreate();
Palette = NE_PaletteCreate();
// Load part of the texture ignoring some of its height. You can't do
// this with width because of how textures are laid out in VRAM.
NE_MaterialTexLoad(Material, GL_RGB32_A3, 128, 96, TEXGEN_TEXCOORD,
(u8 *) test_tex_bin);
// Load part of the texture ignoring some of its height. You can't do
// this with width because of how textures are laid out in VRAM.
NE_MaterialTexLoad(Material, GL_RGB32_A3, 128, 96, TEXGEN_TEXCOORD,
(u8 *)test_tex_bin);
// Load complete texture
NE_MaterialTexLoad(Material2, GL_RGB32_A3, 128, 128, TEXGEN_TEXCOORD,
(u8 *) test_tex_bin);
// Load complete texture
NE_MaterialTexLoad(Material2, GL_RGB32_A3, 128, 128, TEXGEN_TEXCOORD,
(u8 *)test_tex_bin);
NE_PaletteLoad(Palette, (u16 *)test_pal_bin, 32, GL_RGB32_A3);
NE_PaletteLoad(Palette, (u16 *)test_pal_bin, 32, GL_RGB32_A3);
NE_MaterialTexSetPal(Material, Palette);
NE_MaterialTexSetPal(Material2, Palette);
NE_MaterialTexSetPal(Material, Palette);
NE_MaterialTexSetPal(Material2, Palette);
while(1) {
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
while (1)
{
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -25,69 +25,70 @@ NE_Material *Material;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine in normal 3D mode
NE_Init3D();
// Init Nitro Engine in normal 3D mode
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate space for the objects we'll use
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate space for the objects we'll use
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Set coordinates for the camera
NE_CameraSet(Camera,
-8, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Set coordinates for the camera
NE_CameraSet(Camera,
-8, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *) texture_bin);
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// We set up a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// We set up a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
while (1) {
// Get keys information
scanKeys();
uint32 keys = keysHeld();
while (1)
{
// Get keys information
scanKeys();
uint32 keys = keysHeld();
printf("\x1b[0;0HPad: Rotate.");
printf("\x1b[0;0HPad: Rotate.");
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Draw scene
NE_Process(Draw3DScene);
// Wait for next frame
NE_WaitForVBL(0);
}
// Draw scene
NE_Process(Draw3DScene);
// Wait for next frame
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -15,78 +15,79 @@ NE_Model *Model;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
NE_PolyFormat(31, 0, NE_LIGHT_01, NE_CULL_BACK, 0);
NE_ModelDraw(Model);
NE_PolyFormat(31, 0, NE_LIGHT_01, NE_CULL_BACK, 0);
NE_ModelDraw(Model);
NE_2DViewInit();
NE_2DDrawQuad(0, 0,
100, 100,
0, NE_White);
NE_2DViewInit();
NE_2DDrawQuad(0, 0,
100, 100,
0, NE_White);
}
int main()
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
// The clear bitmap is placed in VRAM_C and VRAM_D, so it is needed to
// preserve them.
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// The clear bitmap is placed in VRAM_C and VRAM_D, so it is needed to
// preserve them.
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Copy data into VRAM
vramSetBankC(VRAM_C_LCD);
dmaCopy(background_tex_bin, VRAM_C, background_tex_bin_size);
vramSetBankD(VRAM_D_LCD);
dmaCopy(depth_tex_bin, VRAM_D, depth_tex_bin_size);
// Copy data into VRAM
vramSetBankC(VRAM_C_LCD);
dmaCopy(background_tex_bin, VRAM_C, background_tex_bin_size);
vramSetBankD(VRAM_D_LCD);
dmaCopy(depth_tex_bin, VRAM_D, depth_tex_bin_size);
NE_ClearBMPEnable(true);
NE_ClearBMPEnable(true);
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
1, 1, 1,
0, 0, 0,
0, 1, 0);
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
1, 1, 1,
0, 0, 0,
0, 1, 0);
Model = NE_ModelCreate(NE_Static);
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
Model = NE_ModelCreate(NE_Static);
NE_ModelLoadStaticMesh(Model, (u32 *)model_bin);
NE_LightSet(0, NE_Yellow, -1, -1, 0);
NE_LightSet(1, NE_Red, -1, 1, 0);
NE_LightSet(0, NE_Yellow, -1, -1, 0);
NE_LightSet(1, NE_Red, -1, 1, 0);
NE_ClearColorSet(0, // Color not used when clear BMP
31, 63); // ID and alpha are used
NE_ClearColorSet(0, // Color not used when clear BMP
31, 63); // ID and alpha are used
u8 scrollx = 0, scrolly = 0;
while (1) {
scanKeys();
uint32 keys = keysHeld();
u8 scrollx = 0, scrolly = 0;
while (1)
{
scanKeys();
uint32 keys = keysHeld();
NE_ModelRotate(Model, 0, 2, 1);
NE_ModelRotate(Model, 0, 2, 1);
if (keys & KEY_A)
NE_ClearBMPEnable(true);
if (keys & KEY_B)
NE_ClearBMPEnable(false);
if (keys & KEY_A)
NE_ClearBMPEnable(true);
if (keys & KEY_B)
NE_ClearBMPEnable(false);
NE_ClearBMPScroll(scrollx,scrolly);
NE_ClearBMPScroll(scrollx,scrolly);
if (keys & KEY_UP)
scrolly --;
if (keys & KEY_DOWN)
scrolly ++;
if (keys & KEY_RIGHT)
scrollx ++;
if (keys & KEY_LEFT)
scrollx --;
if (keys & KEY_UP)
scrolly --;
if (keys & KEY_DOWN)
scrolly ++;
if (keys & KEY_RIGHT)
scrollx ++;
if (keys & KEY_LEFT)
scrollx --;
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -10,44 +10,45 @@
void Draw3DScene(void)
{
// Let's generate some error messages...
NE_LightOff(100);
NE_CameraSetI(NULL,
1, 1, 1,
1, 1, 1,
1, 1, 1);
NE_PolyFormat(100, 120, 0, 0, 0);
// Let's generate some error messages...
NE_LightOff(100);
NE_CameraSetI(NULL,
1, 1, 1,
1, 1, 1,
1, 1, 1);
NE_PolyFormat(100, 120, 0, 0, 0);
}
void error_handler(const char * text)
{
// Simple handler. You could write this to a file instead, for example.
printf(text);
// Simple handler. You could write this to a file instead, for example.
printf(text);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Set a custom error handler
NE_DebugSetHandler(error_handler);
// Set a custom error handler
NE_DebugSetHandler(error_handler);
// In order to use the default handler again it is needed to call
// NE_DebugSetHandlerConsole(). After that, all messages will be printed
// to the default console
// In order to use the default handler again it is needed to call
// NE_DebugSetHandlerConsole(). After that, all messages will be printed
// to the default console
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -20,89 +20,91 @@ NE_Material *Material;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine in normal 3D mode
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Init Nitro Engine in normal 3D mode
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate space for objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate space for objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Set coordinates for the camera
NE_CameraSet(Camera,
-8, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Set coordinates for the camera
NE_CameraSet(Camera,
-8, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *) texture_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// We set a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// We set a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
int fpscount = 0;
int fpscount = 0;
// This is used to see if second has changed
int oldsec = 0;
int seconds = 0;
// This is used to see if second has changed
int oldsec = 0;
int seconds = 0;
while (1) {
// Get time
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
while (1)
{
// Get time
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);
seconds = timeStruct->tm_sec;
// If new second
if (seconds != oldsec) {
// Reset fps count and print current
oldsec = seconds;
printf("\x1b[10;0HFPS: %d", fpscount);
fpscount = 0;
}
// If new second
if (seconds != oldsec)
{
// Reset fps count and print current
oldsec = seconds;
printf("\x1b[10;0HFPS: %d", fpscount);
fpscount = 0;
}
// Get keys information
scanKeys();
uint32 keys = keysHeld();
// Get keys information
scanKeys();
uint32 keys = keysHeld();
printf("\x1b[0;0HPad: Rotate.");
printf("\x1b[0;0HPad: Rotate.");
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
NE_Process(Draw3DScene);
// Wait for next frame
NE_WaitForVBL(0);
// Increase frame count
fpscount++;
}
NE_Process(Draw3DScene);
// Wait for next frame
NE_WaitForVBL(0);
// Increase frame count
fpscount++;
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -15,78 +15,82 @@ NE_Material *Material;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
NE_CameraUse(Camera);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
NE_ModelDraw(Model);
}
int main()
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Set coordinates for the camera
NE_CameraSet(Camera,
-10, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Set coordinates for the camera
NE_CameraSet(Camera,
-10, 0, 0, // Position
0, 0, 0, // Look at
0, 1, 0); // Up direction
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *) texture_bin);
// Load mesh from RAM and assign it to the object "Model".
NE_ModelLoadStaticMesh(Model, (u32 *)nitrocat_bin);
// Load a RGB texture from RAM and assign it to "Material".
NE_MaterialTexLoad(Material, GL_RGB, 128, 128, TEXGEN_TEXCOORD,
(u8 *)texture_bin);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
// Assign texture to model...
NE_ModelSetMaterial(Model, Material);
NE_ModelScale(Model, 5, 5, 5);
NE_ModelScale(Model, 5, 5, 5);
// We set up a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// We set up a light and its color
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
int angle = 0;
int angle = 0;
while (1) {
// Get keys information
scanKeys();
uint32 keys = keysHeld();
while (1)
{
// Get keys information
scanKeys();
uint32 keys = keysHeld();
printf("\x1b[0;0HPad: Rotate.\nA/B: Move forward/back.");
printf("\x1b[0;0HPad: Rotate.\nA/B: Move forward/back.");
if (keys & KEY_UP && angle < 92) {
angle += 3;
NE_CameraRotateFree(Camera, 3, 0, 0);
} else if (keys & KEY_DOWN && angle > -92) {
angle -= 3;
NE_CameraRotateFree(Camera, -3, 0, 0);
}
if (keys & KEY_UP && angle < 92)
{
angle += 3;
NE_CameraRotateFree(Camera, 3, 0, 0);
}
else if (keys & KEY_DOWN && angle > -92)
{
angle -= 3;
NE_CameraRotateFree(Camera, -3, 0, 0);
}
if (keys & KEY_LEFT)
NE_CameraRotateFree(Camera, 0, -3, 0);
else if (keys & KEY_RIGHT)
NE_CameraRotateFree(Camera, 0, 3, 0);
if (keys & KEY_LEFT)
NE_CameraRotateFree(Camera, 0, -3, 0);
else if (keys & KEY_RIGHT)
NE_CameraRotateFree(Camera, 0, 3, 0);
if (keys & KEY_A)
NE_CameraMoveFree(Camera, 0.2, 0, 0);
else if (keys & KEY_B)
NE_CameraMoveFree(Camera, -0.2, 0, 0);
if (keys & KEY_A)
NE_CameraMoveFree(Camera, 0.2, 0, 0);
else if (keys & KEY_B)
NE_CameraMoveFree(Camera, -0.2, 0, 0);
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -20,86 +20,87 @@ bool wireframe;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
if (wireframe)
NE_PolyFormat(0, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
else
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
if (wireframe)
NE_PolyFormat(0, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
else
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, 0);
NE_ModelDraw(Model);
NE_ModelDraw(Model);
printf("\x1b[5;0HPolygon count: %d \nVertex count: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
printf("\x1b[5;0HPolygon count: %d \nVertex count: %d ",
NE_GetPolygonCount(), NE_GetVertexCount());
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
// Setup camera
NE_CameraSet(Camera,
2, 0, 0,
0, 0, 0,
0, 1, 0);
// Setup camera
NE_CameraSet(Camera,
2, 0, 0,
0, 0, 0,
0, 1, 0);
// Load model...
NE_ModelLoadStaticMesh(Model,(u32*)ball_bin);
NE_MaterialTexLoadBMPtoRGBA(Material, (void*) texture_bin, 0);
NE_ModelSetMaterial(Model, Material);
// Load model
NE_ModelLoadStaticMesh(Model,(u32*)ball_bin);
NE_MaterialTexLoadBMPtoRGBA(Material, (void *)texture_bin, 0);
NE_ModelSetMaterial(Model, Material);
// Set some propierties to Material
NE_MaterialSetPropierties(Material,
RGB15(31, 31, 31), // diffuse
RGB15(0, 0, 0), // ambient
RGB15(0, 0, 0), // specular
RGB15(0, 0, 0), // emission
false, false); // vtxcolor, useshininess
// Set some propierties to Material
NE_MaterialSetPropierties(Material,
RGB15(31, 31, 31), // Diffuse
RGB15(0, 0, 0), // Ambient
RGB15(0, 0, 0), // Specular
RGB15(0, 0, 0), // Emission
false, false); // Vtx color, use shininess table
// Set light color and direction
NE_LightSet(0, NE_White, 0, 1, 0);
NE_LightSet(1, NE_Blue, 0, -1, 0);
NE_LightSet(2, NE_Red, 1, 0, 0);
NE_LightSet(3, NE_Green, -1, 0, 0);
// Set light color and direction
NE_LightSet(0, NE_White, 0, 1, 0);
NE_LightSet(1, NE_Blue, 0, -1, 0);
NE_LightSet(2, NE_Red, 1, 0, 0);
NE_LightSet(3, NE_Green, -1, 0, 0);
while (1) {
// Get keys information
scanKeys();
uint32 keys = keysHeld();
while (1)
{
// Get keys information
scanKeys();
uint32 keys = keysHeld();
printf("\x1b[0;0HPad: Rotate.\nA: Set wireframe mode.");
printf("\x1b[0;0HPad: Rotate.\nA: Set wireframe mode.");
// Rotate model
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
// Rotate model
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
if (keys & KEY_A)
wireframe = true;
else
wireframe = false;
if (keys & KEY_A)
wireframe = true;
else
wireframe = false;
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -10,47 +10,48 @@ NE_Camera *Camera;
void Draw3DScene(void)
{
// Use camera and draw polygon.
NE_CameraUse(Camera);
// Use camera and draw polygon.
NE_CameraUse(Camera);
// Begin drawing
NE_PolyBegin(GL_QUAD);
// Begin drawing
NE_PolyBegin(GL_QUAD);
NE_PolyColor(NE_Red); // Set next vertices color
NE_PolyVertex(-1, 1, 0); // Send vertex
NE_PolyColor(NE_Red); // Set next vertices color
NE_PolyVertex(-1, 1, 0); // Send vertex
NE_PolyColor(NE_Green);
NE_PolyVertex(-1, -1, 0);
NE_PolyColor(NE_Green);
NE_PolyVertex(-1, -1, 0);
NE_PolyColor(NE_Yellow);
NE_PolyVertex(1, -1, 0);
NE_PolyColor(NE_Yellow);
NE_PolyVertex(1, -1, 0);
NE_PolyColor(NE_Blue);
NE_PolyVertex(1, 1, 0);
NE_PolyColor(NE_Blue);
NE_PolyVertex(1, 1, 0);
// Apparently this is useless
NE_PolyEnd();
// This seems to not be needed
NE_PolyEnd();
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
Camera = NE_CameraCreate();
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
0, 0, 2,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camera,
0, 0, 2,
0, 0, 0,
0, 1, 0);
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -13,54 +13,54 @@ NE_Palette *Palette;
void Draw3DScene(void)
{
NE_2DViewInit();
NE_2DDrawTexturedQuad(0, 0,
128, 128,
0, Material);
NE_2DViewInit();
NE_2DDrawTexturedQuad(0, 0,
128, 128,
0, Material);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init Nitro Engine, normal 3D mode, and move the 3D screen to the
// bottom screen
NE_Init3D();
NE_SwapScreens();
// Init Nitro Engine, normal 3D mode, and move the 3D screen to the
// bottom screen
NE_Init3D();
NE_SwapScreens();
// Allocate objects
Material = NE_MaterialCreate();
Palette = NE_PaletteCreate();
// Allocate objects
Material = NE_MaterialCreate();
Palette = NE_PaletteCreate();
// Load texture
NE_MaterialTexLoadBMPtoRGB256(Material, Palette, (void *) bmp8bit_bin,
1);
// Load texture
NE_MaterialTexLoadBMPtoRGB256(Material, Palette, (void *) bmp8bit_bin, 1);
// Modify color 254 of the palette so that we can use it to draw with a
// known color
NE_PaletteModificationStart(Palette);
NE_PaletteRGB256SetColor(254, RGB15(0, 0, 31));
NE_PaletteModificationEnd();
// Modify color 254 of the palette so that we can use it to draw with a
// known color
NE_PaletteModificationStart(Palette);
NE_PaletteRGB256SetColor(254, RGB15(0, 0, 31));
NE_PaletteModificationEnd();
touchPosition touch;
touchPosition touch;
while (1) {
scanKeys();
touchRead(&touch);
while (1)
{
scanKeys();
touchRead(&touch);
NE_Process(Draw3DScene);
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
NE_WaitForVBL(0);
if (keysHeld() & KEY_TOUCH) {
NE_TextureDrawingStart(Material);
NE_TexturePutPixelRGB256(touch.px >> 1 ,touch.py >> 1 ,
254);
NE_TextureDrawingEnd();
}
}
if (keysHeld() & KEY_TOUCH)
{
NE_TextureDrawingStart(Material);
NE_TexturePutPixelRGB256(touch.px >> 1, touch.py >> 1, 254);
NE_TextureDrawingEnd();
}
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -14,43 +14,45 @@ NE_Material *Texture;
void Draw3DScene(void)
{
NE_2DViewInit();
NE_2DDrawTexturedQuad(0, 0, 128, 128, 0, Texture);
NE_2DViewInit();
NE_2DDrawTexturedQuad(0, 0, 128, 128, 0, Texture);
}
int main()
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
lcdMainOnBottom();
NE_Init3D();
lcdMainOnBottom();
Texture = NE_MaterialCreate();
NE_MaterialTexLoadBMPtoRGBA(Texture, (void *) bmp24bit_bin, 1);
Texture = NE_MaterialCreate();
NE_MaterialTexLoadBMPtoRGBA(Texture, (void *) bmp24bit_bin, 1);
// Wait a bit...
scanKeys();
NE_WaitForVBL(0);
// Wait a bit...
scanKeys();
NE_WaitForVBL(0);
while (1) {
scanKeys();
touchPosition touch;
while (1)
{
scanKeys();
touchPosition touch;
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
if (keysHeld() & KEY_TOUCH) {
// Update stylus coordinates when screen is pressed
touchRead(&touch);
NE_TextureDrawingStart(Texture);
// Draw blue pixels with no transparency
NE_TexturePutPixelRGBA(touch.px >> 1, touch.py >> 1,
RGB15(0, 0, 31) | BIT(15));
NE_TextureDrawingEnd();
}
}
if (keysHeld() & KEY_TOUCH)
{
// Update stylus coordinates when screen is pressed
touchRead(&touch);
NE_TextureDrawingStart(Texture);
// Draw blue pixels with no transparency
NE_TexturePutPixelRGBA(touch.px >> 1, touch.py >> 1,
RGB15(0, 0, 31) | BIT(15));
NE_TextureDrawingEnd();
}
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -15,58 +15,59 @@ NE_Material *Texture;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_CameraUse(Camera);
// This set material's color to drawing color (default = white)
NE_MaterialUse(Texture);
// This set material's color to drawing color (default = white)
NE_MaterialUse(Texture);
// In general you should avoid using the functions below
// In general you should avoid using the functions below
// Begin drawing
NE_PolyBegin(GL_QUAD);
// Begin drawing
NE_PolyBegin(GL_QUAD);
NE_PolyColor(NE_Red); // Set next vertices color
NE_PolyTexCoord(0, 0); // Texture coordinates
NE_PolyVertex(-1, 1, 0); // Send new vertex
NE_PolyColor(NE_Red); // Set next vertices color
NE_PolyTexCoord(0, 0); // Texture coordinates
NE_PolyVertex(-1, 1, 0); // Send new vertex
NE_PolyColor(NE_Blue);
NE_PolyTexCoord(0, 64);
NE_PolyVertex(-1, -1, 0);
NE_PolyColor(NE_Blue);
NE_PolyTexCoord(0, 64);
NE_PolyVertex(-1, -1, 0);
NE_PolyColor(NE_Green);
NE_PolyTexCoord(64, 64);
NE_PolyVertex(1, -1, 0);
NE_PolyColor(NE_Green);
NE_PolyTexCoord(64, 64);
NE_PolyVertex(1, -1, 0);
NE_PolyColor(NE_Yellow);
NE_PolyTexCoord(64, 0);
NE_PolyVertex(1, 1, 0);
NE_PolyColor(NE_Yellow);
NE_PolyTexCoord(64, 0);
NE_PolyVertex(1, 1, 0);
// Apparently this command is ignored by the GPU
NE_PolyEnd();
// Apparently this command is ignored by the GPU
NE_PolyEnd();
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
Camera = NE_CameraCreate();
Texture = NE_MaterialCreate();
Camera = NE_CameraCreate();
Texture = NE_MaterialCreate();
NE_CameraSet(Camera,
0, 0, 2,
0, 0, 0,
0, 1, 0);
NE_CameraSet(Camera,
0, 0, 2,
0, 0, 0,
0, 1, 0);
NE_MaterialTexLoadBMPtoRGBA(Texture, (void *)bmp24bit_bin, 1);
NE_MaterialTexLoadBMPtoRGBA(Texture, (void *)bmp24bit_bin, 1);
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -21,171 +21,183 @@ uint32 keys;
void Draw3DScene(void)
{
NE_CameraUse(Camera);
NE_ViewRotate(0, roty, rotz);
NE_CameraUse(Camera);
NE_ViewRotate(0, roty, rotz);
// Draw everything
for (int i = 0; i < 10; i++) {
if (i == object_touched)
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
else
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
// Draw everything
for (int i = 0; i < 10; i++)
{
if (i == object_touched)
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
else
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
NE_ModelDraw(Model[i]);
}
NE_ModelDraw(Model[i]);
}
if (keys & KEY_TOUCH) {
// Get the information
NE_TouchTestStart();
for (int i = 0; i < 10; i++) {
// Models being drawn during the touch test aren't
// actually drawn. That means you can use less detailed
// objects, with no textures, etc, in order to make it
// easier for the GPU to handle.
NE_TouchTestObject();
NE_ModelDraw(Model[i]);
distancetocamera[i] = NE_TouchTestResult();
}
NE_TouchTestEnd();
}
if (keys & KEY_TOUCH)
{
// Get the information
NE_TouchTestStart();
for (int i = 0; i < 10; i++)
{
// Models being drawn during the touch test aren't
// actually drawn. That means you can use less detailed
// objects, with no textures, etc, in order to make it
// easier for the GPU to handle.
NE_TouchTestObject();
NE_ModelDraw(Model[i]);
distancetocamera[i] = NE_TouchTestResult();
}
NE_TouchTestEnd();
}
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// Move 3D screen to lower screen
NE_SwapScreens();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
NE_Init3D();
// Move 3D screen to lower screen
NE_SwapScreens();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
for (int i = 0; i < 10; i++)
Model[i] = NE_ModelCreate(NE_Static);
for (int i = 0; i < 10; i++)
Model[i] = NE_ModelCreate(NE_Static);
// Allocate everything
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
-4, 0, 0,
0, 0, 0,
0, 1, 0);
// Allocate everything
Camera = NE_CameraCreate();
NE_CameraSet(Camera,
-4, 0, 0,
0, 0, 0,
0, 1, 0);
// Load model
for (int i = 0; i < 10; i++)
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
// Load model
for (int i = 0; i < 10; i++)
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
// Set up lights
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
NE_LightSet(1, NE_Red, 0, -0.5, -0.5);
// Set up lights
NE_LightSet(0, NE_Yellow, 0, -0.5, -0.5);
NE_LightSet(1, NE_Red, 0, -0.5, -0.5);
// Enable shading
NE_ShadingEnable(true);
// Enable shading
NE_ShadingEnable(true);
// Wait a bit
swiWaitForVBlank();
swiWaitForVBlank();
swiWaitForVBlank();
swiWaitForVBlank();
printf("Press any key to start...");
// Wait a bit
swiWaitForVBlank();
swiWaitForVBlank();
swiWaitForVBlank();
swiWaitForVBlank();
printf("Press any key to start...");
int framecount = 0;
int framecount = 0;
while (1) {
if(framecount < 30)
printf("\x1b[1;0H_");
else
printf("\x1b[1;0H ");
while (1)
{
if(framecount < 30)
printf("\x1b[1;0H_");
else
printf("\x1b[1;0H ");
if(framecount == 60)
framecount = 0;
if(framecount == 60)
framecount = 0;
framecount++;
framecount++;
scanKeys();
scanKeys();
// Set random coordinates
for (int i = 0; i < 10; i++) {
NE_ModelSetCoordI(Model[i],
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5));
}
// Set random coordinates
for (int i = 0; i < 10; i++)
{
NE_ModelSetCoordI(Model[i],
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5));
}
if (keysHeld())
break;
if (keysHeld())
break;
swiWaitForVBlank();
}
swiWaitForVBlank();
}
printf("\x1b[0;0H ");
printf("\x1b[1;0H ");
printf("\x1b[0;0H ");
printf("\x1b[1;0H ");
printf("\x1b[0;0HNote: If two objects overlap,\n"
"it may fail to diferenciate\nwhich is closer to the camera.");
printf("\x1b[22;0HPAD: Rotate.");
printf("\x1b[23;0HSTART: New positions.");
printf("\x1b[0;0HNote: If two objects overlap,\n"
"it may fail to diferenciate\nwhich is closer to the camera.");
printf("\x1b[22;0HPAD: Rotate.");
printf("\x1b[23;0HSTART: New positions.");
while (1) {
scanKeys();
keys = keysHeld();
while (1)
{
scanKeys();
keys = keysHeld();
// Rotate view
if (keys & KEY_RIGHT)
roty --;
if (keys & KEY_LEFT)
roty ++;
if (keys & KEY_UP)
rotz ++;
if (keys & KEY_DOWN)
rotz --;
// Rotate view
if (keys & KEY_RIGHT)
roty --;
if (keys & KEY_LEFT)
roty ++;
if (keys & KEY_UP)
rotz ++;
if (keys & KEY_DOWN)
rotz --;
if (keysDown() & KEY_START) {
// Set random coordinates
for (int i = 0; i < 10; i++) {
NE_ModelSetCoordI(Model[i],
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5) ,
(rand() & (inttof32(3) - 1)) - floattof32(1.5));
}
}
if (keysDown() & KEY_START)
{
// Set random coordinates
for (int i = 0; i < 10; i++)
{
NE_ModelSetCoordI(Model[i],
(rand() & (inttof32(3) - 1)) - floattof32(1.5),
(rand() & (inttof32(3) - 1)) - floattof32(1.5) ,
(rand() & (inttof32(3) - 1)) - floattof32(1.5));
}
}
// Reset object being touched, let's test if we're wrong
object_touched = -1;
// Reset object being touched, let's test if we're wrong
object_touched = -1;
if (keys & KEY_TOUCH) {
// This is the part that checks if there are objects
// being touched
if (keys & KEY_TOUCH)
{
// This is the part that checks if there are objects being touched
// GL_MAX_DEPTH is the max possible distance
int min_distance = GL_MAX_DEPTH;
// GL_MAX_DEPTH is the max possible distance
int min_distance = GL_MAX_DEPTH;
for(int j = 0; j < 10; j++) {
// If the distance is greater than 0, the object
// has been touched. Note that this array is
// filled in the drawing function
if(distancetocamera[j] >= 0) {
// If the object is closer than any
// previously detected object, replace
// it
if (distancetocamera[j] < min_distance) {
object_touched = j;
min_distance = distancetocamera[j];
}
}
}
} else {
// Reset distances if screen is not being touched
for(int j = 0; j < 10; j++)
distancetocamera[j] = GL_MAX_DEPTH;
}
for (int j = 0; j < 10; j++)
{
// If the distance is greater than 0, the object has been
// touched. Note that this array is filled in the drawing
// function
if(distancetocamera[j] >= 0)
{
// If the object is closer than any previously detected
// object, replace it
if (distancetocamera[j] < min_distance)
{
object_touched = j;
min_distance = distancetocamera[j];
}
}
}
}
else
{
// Reset distances if screen is not being touched
for (int j = 0; j < 10; j++)
distancetocamera[j] = GL_MAX_DEPTH;
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -14,87 +14,89 @@ NE_Physics *Physics[6];
void Draw3DScene(void)
{
NE_CameraUse(Camara);
NE_CameraUse(Camara);
// The first 3 boxes will be affected by one light and 3 last boxes by
// another one
NE_PolyFormat(31, 0, NE_LIGHT_0,NE_CULL_BACK, 0);
for (int i = 0; i < 3; i++)
NE_ModelDraw(Model[i]);
// The first 3 boxes will be affected by one light and 3 last boxes by
// another one
NE_PolyFormat(31, 0, NE_LIGHT_0,NE_CULL_BACK, 0);
for (int i = 0; i < 3; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_1,NE_CULL_BACK, 0);
for (int i = 3; i < 6; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_1,NE_CULL_BACK, 0);
for (int i = 3; i < 6; i++)
NE_ModelDraw(Model[i]);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-4, 3, 1,
0, 2, 0,
0, 1, 0);
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-4, 3, 1,
0, 2, 0,
0, 1, 0);
// Create objects
for (int i = 0; i < 6; i++) {
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
// Create objects
for (int i = 0; i < 6; i++)
{
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_PhysicsSetModel(Physics[i], // Physics object
(void *)Model[i]); // Model assigned to it
NE_PhysicsSetModel(Physics[i], // Physics object
(void *)Model[i]); // Model assigned to it
NE_PhysicsEnable(Physics[i], false);
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
NE_PhysicsEnable(Physics[i], false);
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
// Enable only the ones we will move
NE_PhysicsEnable(Physics[0], true);
NE_PhysicsEnable(Physics[1], true);
NE_PhysicsEnable(Physics[2], true);
// Enable only the ones we will move
NE_PhysicsEnable(Physics[0], true);
NE_PhysicsEnable(Physics[1], true);
NE_PhysicsEnable(Physics[2], true);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 4, 1);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 4, -1);
NE_ModelSetCoord(Model[3], 0, 0, 1);
NE_ModelSetCoord(Model[4], 0, 0, 0);
NE_ModelSetCoord(Model[5], 0, 0, -1);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 4, 1);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 4, -1);
NE_ModelSetCoord(Model[3], 0, 0, 1);
NE_ModelSetCoord(Model[4], 0, 0, 0);
NE_ModelSetCoord(Model[5], 0, 0, -1);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColBounce);
NE_PhysicsOnCollision(Physics[2], NE_ColBounce);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColBounce);
NE_PhysicsOnCollision(Physics[2], NE_ColBounce);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost.
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 75);
NE_PhysicsSetBounceEnergy(Physics[2], 50);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost.
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 75);
NE_PhysicsSetBounceEnergy(Physics[2], 50);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -14,85 +14,87 @@ NE_Physics *Physics[6];
void Draw3DScene(void)
{
NE_CameraUse(Camara);
NE_CameraUse(Camara);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
for (int i = 0; i < 5; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
for (int i = 0; i < 5; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
NE_ModelDraw(Model[5]);
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
NE_ModelDraw(Model[5]);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-9, 7, 5,
0, 6, 0,
0, 1, 0);
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-9, 7, 5,
0, 6, 0,
0, 1, 0);
// Create objects
for (int i = 0; i < 6; i++) {
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
// Create objects
for (int i = 0; i < 6; i++)
{
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_PhysicsSetModel(Physics[i], (void *)Model[i]);
NE_PhysicsSetModel(Physics[i], (void *)Model[i]);
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
NE_PhysicsEnable(Physics[5],false);
NE_PhysicsEnable(Physics[5],false);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 2, 0);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 6, 0);
NE_ModelSetCoord(Model[3], 0, 8, 0);
NE_ModelSetCoord(Model[4], 0, 10, 0);
NE_ModelSetCoord(Model[5], 0, 0, 0);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 2, 0);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 6, 0);
NE_ModelSetCoord(Model[3], 0, 8, 0);
NE_ModelSetCoord(Model[4], 0, 10, 0);
NE_ModelSetCoord(Model[5], 0, 0, 0);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
NE_PhysicsSetGravity(Physics[3], 0.001);
NE_PhysicsSetGravity(Physics[4], 0.001);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
NE_PhysicsSetGravity(Physics[3], 0.001);
NE_PhysicsSetGravity(Physics[4], 0.001);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColBounce);
NE_PhysicsOnCollision(Physics[2], NE_ColBounce);
NE_PhysicsOnCollision(Physics[3], NE_ColBounce);
NE_PhysicsOnCollision(Physics[4], NE_ColBounce);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColBounce);
NE_PhysicsOnCollision(Physics[2], NE_ColBounce);
NE_PhysicsOnCollision(Physics[3], NE_ColBounce);
NE_PhysicsOnCollision(Physics[4], NE_ColBounce);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 100);
NE_PhysicsSetBounceEnergy(Physics[2], 100);
NE_PhysicsSetBounceEnergy(Physics[3], 100);
NE_PhysicsSetBounceEnergy(Physics[4], 100);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 100);
NE_PhysicsSetBounceEnergy(Physics[2], 100);
NE_PhysicsSetBounceEnergy(Physics[3], 100);
NE_PhysicsSetBounceEnergy(Physics[4], 100);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -14,88 +14,90 @@ NE_Physics *Physics[6];
void Draw3DScene(void)
{
NE_CameraUse(Camara);
NE_CameraUse(Camara);
// The first 3 boxes will be affected by one light and 3 last boxes by
// another one
// The first 3 boxes will be affected by one light and 3 last boxes by
// another one
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
for (int i = 0; i < 3; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_BACK, 0);
for (int i = 0; i < 3; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
for (int i = 3; i < 6; i++)
NE_ModelDraw(Model[i]);
NE_PolyFormat(31, 0, NE_LIGHT_1, NE_CULL_BACK, 0);
for (int i = 3; i < 6; i++)
NE_ModelDraw(Model[i]);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-4, 3, 1,
0, 2, 0,
0, 1, 0);
Camara = NE_CameraCreate();
NE_CameraSet(Camara,
-4, 3, 1,
0, 2, 0,
0, 1, 0);
// Create objects
for (int i = 0; i < 6; i++) {
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
// Create objects
for (int i = 0; i < 6; i++)
{
Model[i] = NE_ModelCreate(NE_Static);
Physics[i] = NE_PhysicsCreate(NE_BoundingBox);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_ModelLoadStaticMesh(Model[i], (u32 *)model_bin);
NE_PhysicsSetModel(Physics[i], // Physics object
(void *)Model[i]); // Model assigned to it
NE_PhysicsSetModel(Physics[i], // Physics object
(void *)Model[i]); // Model assigned to it
NE_PhysicsEnable(Physics[i], false);
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
NE_PhysicsEnable(Physics[i], false);
NE_PhysicsSetSize(Physics[i], 1, 1, 1);
}
// Enable only the ones we will move
NE_PhysicsEnable(Physics[0], true);
NE_PhysicsEnable(Physics[1], true);
NE_PhysicsEnable(Physics[2], true);
// Enable only the ones we will move
NE_PhysicsEnable(Physics[0], true);
NE_PhysicsEnable(Physics[1], true);
NE_PhysicsEnable(Physics[2], true);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 4, 1);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 4, -1);
NE_ModelSetCoord(Model[3], 0, 0, 1);
NE_ModelSetCoord(Model[4], 0, 0, 0);
NE_ModelSetCoord(Model[5], 0, 0, -1);
// Object coordinates
NE_ModelSetCoord(Model[0], 0, 4, 1);
NE_ModelSetCoord(Model[1], 0, 4, 0);
NE_ModelSetCoord(Model[2], 0, 4, -1);
NE_ModelSetCoord(Model[3], 0, 0, 1);
NE_ModelSetCoord(Model[4], 0, 0, 0);
NE_ModelSetCoord(Model[5], 0, 0, -1);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
// Set gravity
NE_PhysicsSetGravity(Physics[0], 0.001);
NE_PhysicsSetGravity(Physics[1], 0.001);
NE_PhysicsSetGravity(Physics[2], 0.001);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColStop);
NE_PhysicsOnCollision(Physics[2], NE_ColNothing);
// Tell the engine what to do if there is a collision
NE_PhysicsOnCollision(Physics[0], NE_ColBounce);
NE_PhysicsOnCollision(Physics[1], NE_ColStop);
NE_PhysicsOnCollision(Physics[2], NE_ColNothing);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost.
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 75);
NE_PhysicsSetBounceEnergy(Physics[2], 50);
// Set percent of energy kept after a bounce
// Default is 50, 100 = no energy lost.
NE_PhysicsSetBounceEnergy(Physics[0], 100);
NE_PhysicsSetBounceEnergy(Physics[1], 75);
NE_PhysicsSetBounceEnergy(Physics[2], 50);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Lights
NE_LightSet(0, NE_Green, -1, -1, 0);
NE_LightSet(1, NE_Blue, -1, -1, 0);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
// Background
NE_ClearColorSet(NE_Red, 31, 63);
while (1) {
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
while (1)
{
NE_Process(Draw3DScene);
NE_WaitForVBL(NE_UPDATE_PHYSICS);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -18,18 +18,19 @@ void Draw3DScene2(void)
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
NE_InitDual3D();
NE_InitDual3D();
while (1) {
scanKeys();
while (1)
{
scanKeys();
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_WaitForVBL(0);
}
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -13,18 +13,19 @@ void Draw3DScene(void)
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_Init3D();
while (1) {
scanKeys();
while (1)
{
scanKeys();
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
NE_Process(Draw3DScene);
NE_WaitForVBL(0);
}
return 0;
return 0;
}