Camera
This commit is contained in:
@@ -48,6 +48,91 @@ void cameraInitOrthographic(camera_t *camera) {
|
|||||||
void cameraPushMatrix(camera_t *camera) {
|
void cameraPushMatrix(camera_t *camera) {
|
||||||
assertNotNull(camera, "Not a camera component");
|
assertNotNull(camera, "Not a camera component");
|
||||||
|
|
||||||
|
#if DOLPHIN
|
||||||
|
Mtx44 guProjection;
|
||||||
|
Mtx guView;
|
||||||
|
Mtx modelView;
|
||||||
|
|
||||||
|
switch(camera->projType) {
|
||||||
|
case CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC:
|
||||||
|
guOrtho(
|
||||||
|
guProjection,
|
||||||
|
camera->orthographic.left,
|
||||||
|
camera->orthographic.right,
|
||||||
|
camera->orthographic.bottom,
|
||||||
|
camera->orthographic.top,
|
||||||
|
camera->nearClip,
|
||||||
|
camera->farClip
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAMERA_PROJECTION_TYPE_PERSPECTIVE:
|
||||||
|
case CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED:
|
||||||
|
guPerspective(
|
||||||
|
guProjection,
|
||||||
|
// FOV is in degrees.
|
||||||
|
camera->perspective.fov * (180.0f / GLM_PIf),
|
||||||
|
(float_t)frameBufferGetWidth(FRAMEBUFFER_BOUND) /
|
||||||
|
(float_t)frameBufferGetHeight(FRAMEBUFFER_BOUND),
|
||||||
|
camera->nearClip,
|
||||||
|
camera->farClip
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Invalid camera projection type");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(camera->viewType) {
|
||||||
|
case CAMERA_VIEW_TYPE_LOOKAT:
|
||||||
|
guVector eye = {
|
||||||
|
camera->lookat.position[0],
|
||||||
|
camera->lookat.position[1],
|
||||||
|
camera->lookat.position[2]
|
||||||
|
};
|
||||||
|
guVector up = {
|
||||||
|
camera->lookat.up[0],
|
||||||
|
camera->lookat.up[1],
|
||||||
|
camera->lookat.up[2]
|
||||||
|
};
|
||||||
|
guVector look = {
|
||||||
|
camera->lookat.target[0],
|
||||||
|
camera->lookat.target[1],
|
||||||
|
camera->lookat.target[2]
|
||||||
|
};
|
||||||
|
guLookAt(guView, &eye, &up, &look);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAMERA_VIEW_TYPE_MATRIX:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAMERA_VIEW_TYPE_2D:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Invalid camera view type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Projection Matrix
|
||||||
|
GX_LoadProjectionMtx(
|
||||||
|
guProjection,
|
||||||
|
camera->projType == CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC ?
|
||||||
|
GX_ORTHOGRAPHIC :
|
||||||
|
GX_PERSPECTIVE
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set view and model matrix. Dunno how I'll handle models but whatever.
|
||||||
|
guMtxIdentity(modelView);
|
||||||
|
guMtxTransApply(modelView, modelView, 0.0F, 0.0F, 0.0F);
|
||||||
|
guMtxConcat(guView,modelView,modelView);
|
||||||
|
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,45 @@
|
|||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
#include "display/text.h"
|
#include "display/text.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <gccore.h>
|
||||||
|
|
||||||
display_t DISPLAY = { 0 };
|
display_t DISPLAY = { 0 };
|
||||||
|
|
||||||
|
static vu8 readyForCopy;
|
||||||
|
PADStatus pads[4];
|
||||||
|
Mtx view;
|
||||||
|
Mtx44 projection;
|
||||||
|
#define FIFO_SIZE (256*1024)
|
||||||
|
|
||||||
|
float_t vertices[] ATTRIBUTE_ALIGN(32) = {
|
||||||
|
0, 15, 0,
|
||||||
|
-15, -15, 0,
|
||||||
|
15, -15, 0};
|
||||||
|
|
||||||
|
|
||||||
|
u8 colors[] ATTRIBUTE_ALIGN(32) = {
|
||||||
|
255, 0, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 0, 255, 255
|
||||||
|
};
|
||||||
|
|
||||||
|
static void copy_buffers(u32 count __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
if (readyForCopy==GX_TRUE) {
|
||||||
|
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||||
|
GX_SetColorUpdate(GX_TRUE);
|
||||||
|
GX_CopyDisp(DISPLAY.frameBuffer,GX_TRUE);
|
||||||
|
GX_Flush();
|
||||||
|
readyForCopy = GX_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
errorret_t displayInit(void) {
|
errorret_t displayInit(void) {
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
uint32_t flags = SDL_INIT_VIDEO;
|
uint32_t flags = SDL_INIT_VIDEO;
|
||||||
@@ -81,11 +117,55 @@ errorret_t displayInit(void) {
|
|||||||
VIDEO_Configure(DISPLAY.screenMode);
|
VIDEO_Configure(DISPLAY.screenMode);
|
||||||
|
|
||||||
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer);
|
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer);
|
||||||
|
VIDEO_SetPostRetraceCallback(copy_buffers);
|
||||||
VIDEO_SetBlack(FALSE);
|
VIDEO_SetBlack(FALSE);
|
||||||
VIDEO_Flush();
|
VIDEO_Flush();
|
||||||
VIDEO_WaitVSync();
|
// VIDEO_WaitVSync();
|
||||||
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
// if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||||
|
|
||||||
|
DISPLAY.fifoBuffer = MEM_K0_TO_K1(memalign(32, FIFO_SIZE));
|
||||||
|
memoryZero(DISPLAY.fifoBuffer, FIFO_SIZE);
|
||||||
|
|
||||||
|
GX_Init(DISPLAY.fifoBuffer, FIFO_SIZE);
|
||||||
|
|
||||||
|
// This seems to be mostly related to interlacing vs progressive
|
||||||
|
GX_SetDispCopyYScale(
|
||||||
|
(f32)DISPLAY.screenMode->xfbHeight /
|
||||||
|
(f32)DISPLAY.screenMode->efbHeight
|
||||||
|
);
|
||||||
|
GX_SetScissor(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
|
||||||
|
GX_SetDispCopySrc(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
|
||||||
|
GX_SetDispCopyDst(DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->xfbHeight);
|
||||||
|
GX_SetCopyFilter(DISPLAY.screenMode->aa,DISPLAY.screenMode->sample_pattern,
|
||||||
|
GX_TRUE,DISPLAY.screenMode->vfilter);
|
||||||
|
GX_SetFieldMode(DISPLAY.screenMode->field_rendering, (
|
||||||
|
(DISPLAY.screenMode->viHeight == 2 * DISPLAY.screenMode->xfbHeight) ?
|
||||||
|
GX_ENABLE : GX_DISABLE
|
||||||
|
));
|
||||||
|
|
||||||
|
// Setup cull modes
|
||||||
|
GX_SetCullMode(GX_CULL_NONE);
|
||||||
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||||
|
|
||||||
|
//?
|
||||||
|
GX_CopyDisp(DISPLAY.frameBuffer, GX_TRUE);
|
||||||
|
|
||||||
|
// Set up view and projection matrices
|
||||||
|
guPerspective(projection, 60, 1.33F, 10.0F, 300.0F);
|
||||||
|
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);
|
||||||
|
|
||||||
|
// Prepare Vertex descriptor
|
||||||
|
GX_ClearVtxDesc();
|
||||||
|
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
||||||
|
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
|
||||||
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
||||||
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||||
|
GX_SetArray(GX_VA_POS, vertices, 3*sizeof(float_t));
|
||||||
|
GX_SetArray(GX_VA_CLR0, colors, 4*sizeof(u8));
|
||||||
|
GX_SetNumChans(1);
|
||||||
|
GX_SetNumTexGens(0);
|
||||||
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
|
||||||
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
quadInit();
|
quadInit();
|
||||||
@@ -145,6 +225,37 @@ errorret_t displayUpdate(void) {
|
|||||||
);
|
);
|
||||||
errorChain(sceneRender());
|
errorChain(sceneRender());
|
||||||
|
|
||||||
|
GX_InvVtxCache();
|
||||||
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
|
// This seems to setup camera
|
||||||
|
// guVector camera = {0.0F, 0.0F, 0.0F};
|
||||||
|
// guVector up = {0.0F, 1.0F, 0.0F};
|
||||||
|
// guVector look = {0.0F, 0.0F, -1.0F};
|
||||||
|
// guLookAt(view, &camera, &up, &look);
|
||||||
|
// Mtx modelView;
|
||||||
|
// guMtxIdentity(modelView);
|
||||||
|
// guMtxTransApply(modelView, modelView, 0.0F, 0.0F, -50.0F);
|
||||||
|
// guMtxConcat(view,modelView,modelView);
|
||||||
|
// // This seems to load the matrix into the GX pipeline?
|
||||||
|
// GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
||||||
|
|
||||||
|
camera_t camera;
|
||||||
|
cameraInitPerspective(&camera);
|
||||||
|
camera.lookat.position[0] = 32;
|
||||||
|
camera.lookat.position[1] = 32;
|
||||||
|
camera.lookat.position[2] = 32;
|
||||||
|
cameraPushMatrix(&camera);
|
||||||
|
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3);
|
||||||
|
GX_Position1x8(0);
|
||||||
|
GX_Color1x8(0);
|
||||||
|
GX_Position1x8(1);
|
||||||
|
GX_Color1x8(1);
|
||||||
|
GX_Position1x8(2);
|
||||||
|
GX_Color1x8(2);
|
||||||
|
GX_End();
|
||||||
|
cameraPopMatrix();
|
||||||
|
|
||||||
// Render UI
|
// Render UI
|
||||||
uiRender();
|
uiRender();
|
||||||
|
|
||||||
@@ -160,8 +271,11 @@ errorret_t displayUpdate(void) {
|
|||||||
debugPrint("GL Error: %d\n", err);
|
debugPrint("GL Error: %d\n", err);
|
||||||
}
|
}
|
||||||
#elif DOLPHIN
|
#elif DOLPHIN
|
||||||
|
GX_DrawDone();
|
||||||
|
readyForCopy = GX_TRUE;
|
||||||
|
|
||||||
VIDEO_WaitVSync();
|
VIDEO_WaitVSync();
|
||||||
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
// if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|||||||
@@ -103,10 +103,7 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
|
|||||||
|
|
||||||
void frameBufferBind(const framebuffer_t *framebuffer) {
|
void frameBufferBind(const framebuffer_t *framebuffer) {
|
||||||
if(framebuffer == NULL) {
|
if(framebuffer == NULL) {
|
||||||
#if DISPLAY_SDL2
|
frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
|
||||||
frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
|
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -131,6 +128,15 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
|
|||||||
0, 0,
|
0, 0,
|
||||||
frameBufferGetWidth(framebuffer), frameBufferGetHeight(framebuffer)
|
frameBufferGetWidth(framebuffer), frameBufferGetHeight(framebuffer)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#elif DOLPHIN
|
||||||
|
GX_SetViewport(
|
||||||
|
0, 0,
|
||||||
|
frameBufferGetWidth(framebuffer),
|
||||||
|
frameBufferGetHeight(framebuffer),
|
||||||
|
0, 1
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FRAMEBUFFER_BOUND = framebuffer;
|
FRAMEBUFFER_BOUND = framebuffer;
|
||||||
@@ -155,6 +161,12 @@ void frameBufferClear(uint8_t flags, color_t color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glClear(glFlags);
|
glClear(glFlags);
|
||||||
|
#elif DOLPHIN
|
||||||
|
GX_SetCopyClear(
|
||||||
|
(GXColor){ color.r, color.g, color.b, color.a },
|
||||||
|
GX_MAX_Z24
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
// Init systems. Order is important.
|
// Init systems. Order is important.
|
||||||
timeInit();
|
timeInit();
|
||||||
inputInit();
|
inputInit();
|
||||||
errorChain(assetInit());
|
// errorChain(assetInit());
|
||||||
errorChain(localeManagerInit());
|
errorChain(localeManagerInit());
|
||||||
errorChain(scriptManagerInit());
|
errorChain(scriptManagerInit());
|
||||||
errorChain(displayInit());
|
errorChain(displayInit());
|
||||||
@@ -41,10 +41,10 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
backpackInit();
|
backpackInit();
|
||||||
|
|
||||||
// Run the initial script.
|
// Run the initial script.
|
||||||
scriptcontext_t ctx;
|
// scriptcontext_t ctx;
|
||||||
errorChain(scriptContextInit(&ctx));
|
// errorChain(scriptContextInit(&ctx));
|
||||||
errorChain(scriptContextExecFile(&ctx, "init.dsf"));
|
// errorChain(scriptContextExecFile(&ctx, "init.dsf"));
|
||||||
scriptContextDispose(&ctx);
|
// scriptContextDispose(&ctx);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user