Add bias to portal clipping plane

This commit is contained in:
James Lambert 2022-06-11 16:03:44 -06:00
parent 7676510a12
commit ace04c87f5
8 changed files with 80 additions and 2 deletions

View file

@ -298,6 +298,7 @@ materials:
gDPSetCombineMode: G_CC_DECALRGB
gDPSetCycleType: G_CYC_1CYCLE
gDPSetTextureFilter: G_TF_BILERP
radio:
gDPSetTile:

View file

@ -15,11 +15,14 @@ struct Vector2 gCylinderColliderEdgeVectors[] = {
{0.707f, -0.707f},
};
struct CollisionQuad gCyliderColliderFaces[8];
struct CollisionCylinder gCylinderCollider = {
0.3f,
0.35f,
gCylinderColliderEdgeVectors,
sizeof(gCylinderColliderEdgeVectors) / sizeof(*gCylinderColliderEdgeVectors),
gCyliderColliderFaces,
};
struct CollisionBox gRadioCollider = {

View file

@ -6,6 +6,7 @@
#include "raycasting.h"
#include "line.h"
#include "../math/vector2.h"
#include "./raycasting.h"
struct ColliderCallbacks gCollisionCylinderCallbacks = {
raycastCylinder,
@ -14,6 +15,59 @@ struct ColliderCallbacks gCollisionCylinderCallbacks = {
collisionCylinderMinkowsiSum,
};
void collisionCylinderBoxCheckForFaces(struct CollisionCylinder* cylinder) {
if (cylinder->outsideFaces[0].edgeALength > 0.0f) {
return;
}
struct Vector2 prevPoint;
vector2Scale(&cylinder->edgeVectors[cylinder->edgeCount - 1], -cylinder->radius, &prevPoint);
for (int i = 0; i < (cylinder->edgeCount << 1); ++i) {
struct Vector2 currPoint;
vector2Scale(&cylinder->edgeVectors[i % cylinder->edgeCount], i >= cylinder->edgeCount ? -cylinder->radius : cylinder->radius, &currPoint);
struct CollisionQuad* quad = &cylinder->outsideFaces[i];
quad->corner.x = prevPoint.x;
quad->corner.y = -cylinder->halfHeight;
quad->corner.z = prevPoint.y;
struct Vector3 toEdge;
toEdge.x = currPoint.x;
toEdge.y = -cylinder->halfHeight;
toEdge.z = currPoint.y;
vector3Sub(&toEdge, &quad->corner, &quad->edgeA);
quad->edgeALength = sqrtf(vector3MagSqrd(&quad->edgeA));
vector3Scale(&quad->edgeA, &quad->edgeA, 1.0f / quad->edgeALength);
quad->edgeB = gUp;
quad->edgeBLength = cylinder->halfHeight * 2.0f;
vector3Cross(&quad->edgeA, &quad->edgeB, &quad->plane.normal);
if (vector3Dot(&quad->plane.normal, &quad->corner) < 0.0f) {
struct Vector3 tmpEdge = quad->edgeA;
quad->edgeA = quad->edgeB;
quad->edgeB = tmpEdge;
float tmpLen = quad->edgeALength;
quad->edgeALength = quad->edgeBLength;
quad->edgeBLength = tmpLen;
vector3Negate(&quad->plane.normal, &quad->plane.normal);
}
quad->plane.d = -vector3Dot(&quad->plane.normal, &quad->corner);
quad->enabledEdges = 0;
prevPoint = currPoint;
}
}
float collisionCylinderSolidMofI(struct ColliderTypeData* typeData, float mass) {
struct CollisionCylinder* cylinder = (struct CollisionCylinder*)typeData->data;
@ -119,5 +173,16 @@ int collisionCylinderRaycast(struct CollisionObject* cylinderObject, struct Ray*
basisUnRotate(&cylinderObject->body->rotationBasis, &ray->dir, &localRay.dir);
basisUnRotate(&cylinderObject->body->rotationBasis, &offset, &localRay.origin);
collisionCylinderBoxCheckForFaces(cylinder);
struct RaycastHit localHit;
for (int i = 0; i < (cylinder->edgeCount << 1); ++i) {
if (raycastQuadShape(&cylinder->outsideFaces[i], &localRay, maxDistance, &localHit)) {
// TODO transform hit
return 1;
}
}
return 0;
}

View file

@ -10,6 +10,7 @@ struct CollisionCylinder {
float halfHeight;
struct Vector2* edgeVectors;
int edgeCount;
struct CollisionQuad* outsideFaces;
};
extern struct ColliderCallbacks gCollisionCylinderCallbacks;

View file

@ -27,11 +27,14 @@ struct Vector2 gPlayerColliderEdgeVectors[] = {
{0.707f, -0.707f},
};
struct CollisionQuad gPlayerColliderFaces[8];
struct CollisionCylinder gPlayerCollider = {
0.25f,
0.7f,
gPlayerColliderEdgeVectors,
sizeof(gPlayerColliderEdgeVectors) / sizeof(*gPlayerColliderEdgeVectors),
gPlayerColliderFaces,
};
struct ColliderTypeData gPlayerColliderData = {

View file

@ -18,11 +18,14 @@ struct Vector2 gButtonCylinderEdgeVectors[] = {
{0.707f, -0.707f},
};
struct CollisionQuad gButtonCylinderFaces[8];
struct CollisionCylinder gButtonCylinder = {
0.5f,
0.3f,
gButtonCylinderEdgeVectors,
sizeof(gButtonCylinderEdgeVectors) / sizeof(*gButtonCylinderEdgeVectors),
gButtonCylinderFaces,
};
struct ColliderTypeData gButtonCollider = {

View file

@ -44,6 +44,8 @@ struct Quaternion gVerticalFlip = {0.0f, 1.0f, 0.0f, 0.0f};
#define STARTING_RENDER_DEPTH 2
#define PORTAL_CLIPPING_PLANE_BIAS (SCENE_SCALE * 0.25f)
void renderPropsInit(struct RenderProps* props, struct Camera* camera, float aspectRatio, struct RenderState* renderState, u16 roomIndex) {
props->camera = *camera;
props->aspectRatio = aspectRatio;
@ -150,7 +152,7 @@ void renderPropsNext(struct RenderProps* current, struct RenderProps* next, stru
if (toPortal < fromPortal) {
vector3Negate(&next->cullingInfo.clippingPlanes[4].normal, &next->cullingInfo.clippingPlanes[4].normal);
}
next->cullingInfo.clippingPlanes[4].d = -vector3Dot(&next->cullingInfo.clippingPlanes[4].normal, &toPortal->position) * SCENE_SCALE;
next->cullingInfo.clippingPlanes[4].d = -vector3Dot(&next->cullingInfo.clippingPlanes[4].normal, &toPortal->position) * SCENE_SCALE - PORTAL_CLIPPING_PLANE_BIAS;
next->currentDepth = current->currentDepth - 1;
next->fromPortalIndex = toPortal < fromPortal ? 0 : 1;