131 lines
2.8 KiB
C
131 lines
2.8 KiB
C
|
// 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>
|
||
|
|
||
|
#include <filesystem.h>
|
||
|
|
||
|
#include <NEMain.h>
|
||
|
|
||
|
|
||
|
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();
|
||
|
scanKeys();
|
||
|
if (keysHeld() & KEY_START)
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
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();
|
||
|
|
||
|
if (!nitroFSInit(NULL))
|
||
|
{
|
||
|
printf("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();
|
||
|
|
||
|
// Setup camera
|
||
|
NE_CameraSet(Camera,
|
||
|
3, 3, -1,
|
||
|
0, 2, 0,
|
||
|
0, 1, 0);
|
||
|
|
||
|
if (NE_ModelLoadDSMFAT(Model, "chibi_kp.dsm") == 0)
|
||
|
{
|
||
|
printf("Couldn't load model...");
|
||
|
WaitLoop();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (NE_AnimationLoadFAT(Animation, "chibi_kp_idle.dsa") == 0)
|
||
|
{
|
||
|
printf("Couldn't load animation...");
|
||
|
WaitLoop();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (NE_MaterialTexLoadFAT(Material, NE_A1RGB5, 256, 256, NE_TEXGEN_TEXCOORD,
|
||
|
"texture.img.bin") == 0)
|
||
|
{
|
||
|
printf("Couldn't load texture...");
|
||
|
WaitLoop();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// Assign material to the model
|
||
|
NE_ModelSetMaterial(Model, Material);
|
||
|
|
||
|
NE_ModelSetAnimation(Model, Animation);
|
||
|
NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1));
|
||
|
|
||
|
NE_LightSet(0, NE_White, 0, -1, -1);
|
||
|
|
||
|
NE_ClearColorSet(NE_Black, 31, 63);
|
||
|
|
||
|
printf("\x1b[0;0HPad: Rotate\nSTART: Exit");
|
||
|
|
||
|
while (1)
|
||
|
{
|
||
|
NE_WaitForVBL(NE_UPDATE_ANIMATIONS);
|
||
|
//rotate model:
|
||
|
NE_ModelRotate(Model, 0, 2, 0);
|
||
|
|
||
|
scanKeys();
|
||
|
uint32_t keys = keysHeld();
|
||
|
|
||
|
if (keys & KEY_START)
|
||
|
break;
|
||
|
|
||
|
if (keys & KEY_RIGHT)
|
||
|
NE_ModelRotate(Model, 0, 2, 0);
|
||
|
if (keys & KEY_LEFT)
|
||
|
NE_ModelRotate(Model, 0, -4, 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;
|
||
|
}
|