Add portal border

This commit is contained in:
James Lambert 2022-03-01 22:03:52 -07:00
parent de467c45e6
commit cb3db59854
6 changed files with 148 additions and 7 deletions

View File

@ -149,6 +149,20 @@ void screenClipperBoundingPoints(struct ScreenClipper* clipper, struct Vector3*
if (!isClipped) {
screenClipperIncludePoint(&transformedPoint, output);
} else {
if (!(isClipped & ClipperBoundsW)) {
if (isClipped & ClipperBoundsLeft) {
output->min.x = -1.0f;
} else if (isClipped & ClipperBoundsRight) {
output->max.x = 1.0f;
}
if (isClipped & ClipperBoundsDown) {
output->min.y = -1.0f;
} else if (isClipped & ClipperBoundsUp) {
output->max.y = 1.0f;
}
}
}
previousPoint = transformedPoint;

View File

@ -7,3 +7,4 @@
#include "subject_geo.inc.h"
#include "sphere_geo.inc.h"
#include "portal_mask.inc.h"
#include "portal_outline.inc.h"

View File

@ -5,3 +5,4 @@
#include "sphere.h"
extern Gfx portal_mask_Circle_mesh[];
extern Gfx portal_outline_portal_outline_mesh[];

View File

@ -0,0 +1,103 @@
Vtx portal_outline_portal_outline_mesh_vtx_0[38] = {
{{{79, 152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{85, 159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{120, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 215, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 204, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{72, 144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{111, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{85, -159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{79, -152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, -225, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, -215, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-85, -159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-79, -152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-120, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-111, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-85, 159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-111, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-85, 159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-79, 152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 225, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 215, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{85, 159, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-72, 144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-102, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-72, -144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-79, -152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, -204, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, -215, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{72, -144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{79, -152, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{102, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{111, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{72, 144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{111, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{102, 0, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{-72, 144, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 215, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
{{{0, 204, 0},0, {-16, 1008},{0x0, 0x0, 0x81, 0xFF}}},
};
Gfx portal_outline_portal_outline_mesh_tri_0[] = {
gsSPVertex(portal_outline_portal_outline_mesh_vtx_0 + 0, 16, 0),
gsSP1Triangle(0, 1, 2, 0),
gsSP1Triangle(3, 1, 0, 0),
gsSP1Triangle(4, 3, 0, 0),
gsSP1Triangle(4, 0, 5, 0),
gsSP1Triangle(5, 0, 6, 0),
gsSP1Triangle(0, 2, 6, 0),
gsSP1Triangle(6, 2, 7, 0),
gsSP1Triangle(6, 7, 8, 0),
gsSP1Triangle(8, 7, 9, 0),
gsSP1Triangle(8, 9, 10, 0),
gsSP1Triangle(10, 9, 11, 0),
gsSP1Triangle(10, 11, 12, 0),
gsSP1Triangle(12, 11, 13, 0),
gsSP1Triangle(12, 13, 14, 0),
gsSP1Triangle(14, 13, 15, 0),
gsSPVertex(portal_outline_portal_outline_mesh_vtx_0 + 16, 16, 0),
gsSP1Triangle(0, 1, 2, 0),
gsSP1Triangle(2, 1, 3, 0),
gsSP1Triangle(2, 3, 4, 0),
gsSP1Triangle(4, 3, 5, 0),
gsSP1Triangle(6, 2, 4, 0),
gsSP1Triangle(7, 2, 6, 0),
gsSP1Triangle(7, 0, 2, 0),
gsSP1Triangle(8, 0, 7, 0),
gsSP1Triangle(8, 9, 0, 0),
gsSP1Triangle(10, 9, 8, 0),
gsSP1Triangle(10, 11, 9, 0),
gsSP1Triangle(12, 11, 10, 0),
gsSP1Triangle(12, 13, 11, 0),
gsSP1Triangle(14, 13, 12, 0),
gsSP1Triangle(14, 15, 13, 0),
gsSPVertex(portal_outline_portal_outline_mesh_vtx_0 + 32, 6, 0),
gsSP1Triangle(0, 1, 2, 0),
gsSP1Triangle(3, 4, 5, 0),
gsSPEndDisplayList(),
};
Gfx mat_portal_outline_portal_outline[] = {
gsDPPipeSync(),
gsSPSetGeometryMode(G_SHADE),
gsSPClearGeometryMode(G_LIGHTING),
gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2),
gsDPSetCombineLERP(0, 0, 0, PRIMITIVE, 0, 0, 0, SHADE, 0, 0, 0, PRIMITIVE, 0, 0, 0, SHADE),
gsSPTexture(65535, 65535, 0, 0, 1),
gsSPEndDisplayList(),
};
Gfx portal_outline_portal_outline_mesh[] = {
gsSPDisplayList(mat_portal_outline_portal_outline),
gsSPDisplayList(portal_outline_portal_outline_mesh_tri_0),
gsDPPipeSync(),
gsSPTexture(65535, 65535, 0, 0, 0),
gsSPEndDisplayList(),
};

View File

@ -8,9 +8,9 @@ void playerInit(struct Player* player) {
transformInitIdentity(&player->transform);
}
#define PLAYER_SPEED (SCENE_SCALE * 5.0f)
#define PLAYER_SPEED (SCENE_SCALE * 2.0f)
#define ROTATE_RATE (M_PI)
#define ROTATE_RATE (M_PI * 0.25f)
void playerUpdate(struct Player* player, struct Transform* cameraTransform) {
struct Vector3 forward;

View File

@ -18,6 +18,8 @@ struct Vector3 gPortalOutline[] = {
{-0.353553f * SCENE_SCALE, 0.707107f * SCENE_SCALE, 0.0f},
};
struct Quaternion gVerticalFlip = {0.0f, 1.0f, 0.0f, 0.0f};
void renderPropsInit(struct RenderProps* props, struct Camera* camera, float aspectRatio, struct RenderState* renderState) {
props->camera = *camera;
props->aspectRatio = aspectRatio;
@ -59,14 +61,28 @@ void portalInit(struct Portal* portal, enum PortalFlags flags) {
void portalRender(struct Portal* portal, struct Portal* otherPortal, struct RenderProps* props, SceneRenderCallback sceneRenderer, void* data, struct RenderState* renderState) {
if (props->currentDepth == 0) {
// TODO render non see through portal
Mtx* matrix = renderStateRequestMatrices(renderState, 1);
transformToMatrixL(&portal->transform, matrix);
gSPMatrix(renderState->dl++, matrix, G_MTX_MODELVIEW | G_MTX_PUSH | G_MTX_MUL);
gDPSetPrimColor(renderState->dl++, 0, 0, 255, 128, 0, 255);
gSPDisplayList(renderState->dl++, portal_outline_portal_outline_mesh);
gSPPopMatrix(renderState->dl++, G_MTX_MODELVIEW);
return;
}
struct ScreenClipper clipper;
float portalTransform[4][4];
transformToMatrix(&portal->transform, portalTransform);
struct Transform finalTransform;
finalTransform = portal->transform;
if (portal->flags & PortalFlagsOddParity) {
quatMultiply(&portal->transform.rotation, &gVerticalFlip, &finalTransform.rotation);
}
transformToMatrix(&finalTransform, portalTransform);
screenClipperInitWithCamera(&clipper, &props->camera, (float)SCREEN_WD / (float)SCREEN_HT, portalTransform);
@ -74,7 +90,7 @@ void portalRender(struct Portal* portal, struct Portal* otherPortal, struct Rend
screenClipperBoundingPoints(&clipper, gPortalOutline, sizeof(gPortalOutline) / sizeof(*gPortalOutline), &clippingBounds);
if (clippingBounds.min.x < clippingBounds.max.x) {
if (clippingBounds.min.x < clippingBounds.max.x && clippingBounds.min.y < clippingBounds.max.y) {
int minX = CALC_SCREEN_SPACE(clippingBounds.min.x, SCREEN_WD);
int maxX = CALC_SCREEN_SPACE(clippingBounds.max.x, SCREEN_WD);
int minY = CALC_SCREEN_SPACE(-clippingBounds.max.y, SCREEN_HT);
@ -94,6 +110,12 @@ void portalRender(struct Portal* portal, struct Portal* otherPortal, struct Rend
guMtxF2L(portalTransform, matrix);
gSPMatrix(renderState->dl++, matrix, G_MTX_MODELVIEW | G_MTX_PUSH | G_MTX_MUL);
gSPDisplayList(renderState->dl++, portal_mask_Circle_mesh);
if (portal->flags & PortalFlagsOddParity) {
gDPSetPrimColor(renderState->dl++, 0, 0, 0, 128, 255, 255);
} else {
gDPSetPrimColor(renderState->dl++, 0, 0, 255, 128, 0, 255);
}
gSPDisplayList(renderState->dl++, portal_outline_portal_outline_mesh);
gSPPopMatrix(renderState->dl++, G_MTX_MODELVIEW);
}