2024-02-23 03:20:50 +00:00
|
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
//
|
|
|
|
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
|
|
|
|
//
|
|
|
|
// This file is part of Nitro Engine
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2024-02-23 03:41:47 +00:00
|
|
|
#include <stdlib.h>
|
2024-02-23 03:20:50 +00:00
|
|
|
|
|
|
|
#include <filesystem.h>
|
2024-02-23 07:01:35 +00:00
|
|
|
#include <nds.h>
|
2024-02-23 03:20:50 +00:00
|
|
|
#include <NEMain.h>
|
2024-02-23 03:41:47 +00:00
|
|
|
#include <nf_lib.h>
|
2024-02-23 03:20:50 +00:00
|
|
|
|
|
|
|
NE_Camera *Camera;
|
|
|
|
NE_Model *Model;
|
|
|
|
NE_Animation *Animation;
|
|
|
|
NE_Material *Material;
|
|
|
|
|
|
|
|
void Draw3DScene(void)
|
|
|
|
{
|
|
|
|
NE_CameraUse(Camera);
|
|
|
|
|
|
|
|
NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0);
|
|
|
|
NE_ModelDraw(Model);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitLoop(void)
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
swiWaitForVBlank();
|
|
|
|
}
|
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
void LoadAndSetupGraphics3D(void)
|
2024-02-23 03:20:50 +00:00
|
|
|
{
|
2024-02-23 07:01:35 +00:00
|
|
|
// When using nflib for the 2D sub screen engine, banks C and H are used for
|
|
|
|
// backgrounds and banks D and I are used for sprites. Nitro Engine only
|
|
|
|
// uses bank E for palettes, so the only thing we need to do is to tell
|
|
|
|
// Nitro Engine to only use banks A and B and leave C and D unused.
|
2024-02-23 03:20:50 +00:00
|
|
|
|
|
|
|
NE_Init3D();
|
|
|
|
// libnds uses VRAM_C for the text console, reserve A and B only
|
|
|
|
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
|
|
|
|
|
|
|
|
// Allocate space for objects...
|
|
|
|
Model = NE_ModelCreate(NE_Animated);
|
|
|
|
Camera = NE_CameraCreate();
|
|
|
|
Material = NE_MaterialCreate();
|
|
|
|
Animation = NE_AnimationCreate();
|
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Load assets form the filesystem
|
|
|
|
|
2024-02-23 03:20:50 +00:00
|
|
|
if (NE_ModelLoadDSMFAT(Model, "chibi_kp.dsm") == 0)
|
|
|
|
{
|
2024-02-23 07:01:35 +00:00
|
|
|
consoleDemoInit();
|
2024-02-23 03:20:50 +00:00
|
|
|
printf("Couldn't load model...");
|
|
|
|
WaitLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NE_AnimationLoadFAT(Animation, "chibi_kp_idle.dsa") == 0)
|
|
|
|
{
|
2024-02-23 07:01:35 +00:00
|
|
|
consoleDemoInit();
|
2024-02-23 03:20:50 +00:00
|
|
|
printf("Couldn't load animation...");
|
|
|
|
WaitLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NE_MaterialTexLoadFAT(Material, NE_A1RGB5, 256, 256, NE_TEXGEN_TEXCOORD,
|
|
|
|
"texture.img.bin") == 0)
|
|
|
|
{
|
2024-02-23 07:01:35 +00:00
|
|
|
consoleDemoInit();
|
2024-02-23 03:20:50 +00:00
|
|
|
printf("Couldn't load texture...");
|
|
|
|
WaitLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign material to the model
|
|
|
|
NE_ModelSetMaterial(Model, Material);
|
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Assign animation to the model and start it
|
2024-02-23 03:20:50 +00:00
|
|
|
NE_ModelSetAnimation(Model, Animation);
|
|
|
|
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
|
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// setup light
|
2024-02-23 03:20:50 +00:00
|
|
|
NE_LightSet(0, NE_White, 0, -1, -1);
|
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// setup background color
|
|
|
|
NE_ClearColorSet(RGB15(10, 0, 17), 31, 63);
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Setup camera
|
|
|
|
NE_CameraSet(Camera,
|
|
|
|
6, 1.5, -1,
|
|
|
|
0, 0, 0,
|
|
|
|
0, 0, -1);
|
|
|
|
NE_SetFov(30);
|
|
|
|
}
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
void LoadAndSetupGraphics2D(void)
|
|
|
|
{
|
|
|
|
// Initialize sub 2D engine
|
|
|
|
NF_Set2D(1, 0);
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Initialize tiled backgrounds and text systems for the 2D sub engine
|
|
|
|
// (using VRAM C & D)
|
|
|
|
NF_InitTiledBgBuffers();
|
|
|
|
NF_InitTiledBgSys(1);
|
|
|
|
NF_InitTextSys(1);
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// load assets from filesystem to RAM
|
|
|
|
NF_LoadTiledBg("bg/badge_01", "capa_0", 2048, 256);
|
|
|
|
NF_LoadTextFont("fnt/default", "normal", 256, 256, 0);
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Create tiled background
|
|
|
|
NF_CreateTiledBg(1, 1, "capa_0");
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
// Create text layer
|
|
|
|
NF_CreateTextLayer(1, 0, 0, "normal");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
// Initialize nitrof before doing anything else
|
|
|
|
NF_Set2D(0, 0);
|
|
|
|
NF_Set2D(1, 0);
|
|
|
|
consoleDemoInit();
|
|
|
|
printf("Starting nitroFS...\n");
|
|
|
|
if(!nitroFSInit(NULL))
|
|
|
|
{
|
|
|
|
printf("Failed to start nitroFS\n");
|
|
|
|
printf("Press START to exit\n");
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
swiWaitForVBlank();
|
|
|
|
scanKeys();
|
|
|
|
if (keysHeld() & KEY_START)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
swiWaitForVBlank();
|
|
|
|
|
|
|
|
// Set the root folder to the nitroFS filesystem
|
|
|
|
NF_SetRootFolder("NITROFS");
|
|
|
|
|
|
|
|
//setup interrupt
|
|
|
|
irqEnable(IRQ_HBLANK);
|
|
|
|
irqSet(IRQ_VBLANK, NE_VBLFunc);
|
|
|
|
irqSet(IRQ_HBLANK, NE_HBLFunc);
|
|
|
|
|
|
|
|
// load and setup graphics
|
|
|
|
LoadAndSetupGraphics3D();
|
|
|
|
LoadAndSetupGraphics2D();
|
|
|
|
|
|
|
|
// print instructions:
|
|
|
|
//NF_WriteText(1, 0, 1, 1, "PAD: Rotate Model");
|
|
|
|
//NF_WriteText(1, 0, 1, 2, "START: Exit");
|
|
|
|
//NF_UpdateTextLayers();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
|
|
|
|
//rotate model:
|
|
|
|
NE_ModelRotate(Model, 0, 1, 0);
|
|
|
|
|
|
|
|
scanKeys();
|
|
|
|
uint32_t keys = keysHeld();
|
2024-02-23 03:20:50 +00:00
|
|
|
|
2024-02-23 07:01:35 +00:00
|
|
|
if (keys & KEY_START)
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2024-02-23 03:20:50 +00:00
|
|
|
}
|