Add bias to portal clipping plane
This commit is contained in:
parent
7676510a12
commit
ace04c87f5
|
@ -298,6 +298,7 @@ materials:
|
||||||
|
|
||||||
gDPSetCombineMode: G_CC_DECALRGB
|
gDPSetCombineMode: G_CC_DECALRGB
|
||||||
gDPSetCycleType: G_CYC_1CYCLE
|
gDPSetCycleType: G_CYC_1CYCLE
|
||||||
|
gDPSetTextureFilter: G_TF_BILERP
|
||||||
|
|
||||||
radio:
|
radio:
|
||||||
gDPSetTile:
|
gDPSetTile:
|
||||||
|
|
Binary file not shown.
|
@ -15,11 +15,14 @@ struct Vector2 gCylinderColliderEdgeVectors[] = {
|
||||||
{0.707f, -0.707f},
|
{0.707f, -0.707f},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CollisionQuad gCyliderColliderFaces[8];
|
||||||
|
|
||||||
struct CollisionCylinder gCylinderCollider = {
|
struct CollisionCylinder gCylinderCollider = {
|
||||||
0.3f,
|
0.3f,
|
||||||
0.35f,
|
0.35f,
|
||||||
gCylinderColliderEdgeVectors,
|
gCylinderColliderEdgeVectors,
|
||||||
sizeof(gCylinderColliderEdgeVectors) / sizeof(*gCylinderColliderEdgeVectors),
|
sizeof(gCylinderColliderEdgeVectors) / sizeof(*gCylinderColliderEdgeVectors),
|
||||||
|
gCyliderColliderFaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CollisionBox gRadioCollider = {
|
struct CollisionBox gRadioCollider = {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "raycasting.h"
|
#include "raycasting.h"
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
#include "../math/vector2.h"
|
#include "../math/vector2.h"
|
||||||
|
#include "./raycasting.h"
|
||||||
|
|
||||||
struct ColliderCallbacks gCollisionCylinderCallbacks = {
|
struct ColliderCallbacks gCollisionCylinderCallbacks = {
|
||||||
raycastCylinder,
|
raycastCylinder,
|
||||||
|
@ -14,6 +15,59 @@ struct ColliderCallbacks gCollisionCylinderCallbacks = {
|
||||||
collisionCylinderMinkowsiSum,
|
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) {
|
float collisionCylinderSolidMofI(struct ColliderTypeData* typeData, float mass) {
|
||||||
struct CollisionCylinder* cylinder = (struct CollisionCylinder*)typeData->data;
|
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, &ray->dir, &localRay.dir);
|
||||||
basisUnRotate(&cylinderObject->body->rotationBasis, &offset, &localRay.origin);
|
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 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ struct CollisionCylinder {
|
||||||
float halfHeight;
|
float halfHeight;
|
||||||
struct Vector2* edgeVectors;
|
struct Vector2* edgeVectors;
|
||||||
int edgeCount;
|
int edgeCount;
|
||||||
|
struct CollisionQuad* outsideFaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct ColliderCallbacks gCollisionCylinderCallbacks;
|
extern struct ColliderCallbacks gCollisionCylinderCallbacks;
|
||||||
|
|
|
@ -27,11 +27,14 @@ struct Vector2 gPlayerColliderEdgeVectors[] = {
|
||||||
{0.707f, -0.707f},
|
{0.707f, -0.707f},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CollisionQuad gPlayerColliderFaces[8];
|
||||||
|
|
||||||
struct CollisionCylinder gPlayerCollider = {
|
struct CollisionCylinder gPlayerCollider = {
|
||||||
0.25f,
|
0.25f,
|
||||||
0.7f,
|
0.7f,
|
||||||
gPlayerColliderEdgeVectors,
|
gPlayerColliderEdgeVectors,
|
||||||
sizeof(gPlayerColliderEdgeVectors) / sizeof(*gPlayerColliderEdgeVectors),
|
sizeof(gPlayerColliderEdgeVectors) / sizeof(*gPlayerColliderEdgeVectors),
|
||||||
|
gPlayerColliderFaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColliderTypeData gPlayerColliderData = {
|
struct ColliderTypeData gPlayerColliderData = {
|
||||||
|
|
|
@ -18,11 +18,14 @@ struct Vector2 gButtonCylinderEdgeVectors[] = {
|
||||||
{0.707f, -0.707f},
|
{0.707f, -0.707f},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CollisionQuad gButtonCylinderFaces[8];
|
||||||
|
|
||||||
struct CollisionCylinder gButtonCylinder = {
|
struct CollisionCylinder gButtonCylinder = {
|
||||||
0.5f,
|
0.5f,
|
||||||
0.3f,
|
0.3f,
|
||||||
gButtonCylinderEdgeVectors,
|
gButtonCylinderEdgeVectors,
|
||||||
sizeof(gButtonCylinderEdgeVectors) / sizeof(*gButtonCylinderEdgeVectors),
|
sizeof(gButtonCylinderEdgeVectors) / sizeof(*gButtonCylinderEdgeVectors),
|
||||||
|
gButtonCylinderFaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColliderTypeData gButtonCollider = {
|
struct ColliderTypeData gButtonCollider = {
|
||||||
|
|
|
@ -44,6 +44,8 @@ struct Quaternion gVerticalFlip = {0.0f, 1.0f, 0.0f, 0.0f};
|
||||||
|
|
||||||
#define STARTING_RENDER_DEPTH 2
|
#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) {
|
void renderPropsInit(struct RenderProps* props, struct Camera* camera, float aspectRatio, struct RenderState* renderState, u16 roomIndex) {
|
||||||
props->camera = *camera;
|
props->camera = *camera;
|
||||||
props->aspectRatio = aspectRatio;
|
props->aspectRatio = aspectRatio;
|
||||||
|
@ -150,7 +152,7 @@ void renderPropsNext(struct RenderProps* current, struct RenderProps* next, stru
|
||||||
if (toPortal < fromPortal) {
|
if (toPortal < fromPortal) {
|
||||||
vector3Negate(&next->cullingInfo.clippingPlanes[4].normal, &next->cullingInfo.clippingPlanes[4].normal);
|
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->currentDepth = current->currentDepth - 1;
|
||||||
next->fromPortalIndex = toPortal < fromPortal ? 0 : 1;
|
next->fromPortalIndex = toPortal < fromPortal ? 0 : 1;
|
||||||
|
|
Loading…
Reference in a new issue