Merge branch 'master' into portal-visual-fixes

This commit is contained in:
Weston 2023-04-02 11:55:47 -05:00 committed by GitHub
commit 030208e5d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 33 deletions

View file

@ -125,12 +125,9 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender
- [ ] Ambient background loop
## Current Bug TODO List (Hardware Verified) (High->Low priority)
- [ ] Player can clip through any level by placing one portal on wall and another portal right next to it on ground. #13
- [ ] Player can clip through chamber 7 by walking back up the stairs (near the top).
- [ ] player can clip through back of elevator by jumping and strafeing at the back corners while inside.
- [ ] Player can strap themselves in chamber 5 by following instructions issue #75
- [ ] Any grabbable object can be clipped through level by wall/floor portals method.
- [ ] Two wall portals can be placed on top of eachother in certain instances if on the same surface
- [ ] Player can trap themselves in chamber 5 by following instructions issue #75
- [ ] Two wall portals next to eachother can be used to clip any object out of any level by pushing it into corner, then dropping.
- [ ] Glass can be walked through from one side on multiple levels (0,1,4,...)
- [ ] Passing into a ceiling portal can sometimes mess with the player rotation
@ -140,5 +137,6 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender
- [ ] Door at end of room 2, chamber 10 isnt rendered properly
- [ ] various visual glitches when running NTSC on PAL console #65
- [ ] various visual glitches when running PAL on NTSC console #65
- [x] Can shoot portals while holding an object
- [x] Any grabbable object can be clipped through level by wall/floor portals method.
- [x] Player can clip through any level by placing one portal on wall and another portal right next to it on ground. #13
- [x] Can shoot portals while holding an object

View file

@ -3,11 +3,11 @@
#include "../util/time.h"
#define BREAK_CONSTRAINT_DISTANCE 2.0f
#define CLAMP_CONSTRAINT_DISTANCE 0.07f
int pointConstraintMoveToPoint(struct CollisionObject* object, struct Vector3* worldPoint, float maxImpulse, int teleportOnBreak, float movementScaleFactor) {
struct RigidBody* rigidBody = object->body;
struct Vector3 targetVelocity;
vector3Sub(worldPoint, &rigidBody->transform.position, &targetVelocity);
@ -18,8 +18,20 @@ int pointConstraintMoveToPoint(struct CollisionObject* object, struct Vector3* w
}
return 0;
}
vector3Scale(&targetVelocity, &targetVelocity, 1.0f / FIXED_DELTA_TIME);
if (teleportOnBreak){
if (fabsf(sqrtf(vector3DistSqrd(worldPoint, &rigidBody->transform.position))) > CLAMP_CONSTRAINT_DISTANCE){
while(sqrtf(vector3DistSqrd(worldPoint, &rigidBody->transform.position)) > CLAMP_CONSTRAINT_DISTANCE){
vector3Lerp(&rigidBody->transform.position, worldPoint, 0.01, &rigidBody->transform.position);
}
vector3Sub(worldPoint, &rigidBody->transform.position, &targetVelocity);
vector3Scale(&targetVelocity, &targetVelocity, (1.0f / FIXED_DELTA_TIME));
vector3Scale(&targetVelocity, &targetVelocity, 0.5);
rigidBody->velocity = targetVelocity;
return 1;
}
}
vector3Scale(&targetVelocity, &targetVelocity, (1.0f / FIXED_DELTA_TIME));
struct ContactManifold* contact = contactSolverNextManifold(&gContactSolver, object, NULL);

View file

@ -3,6 +3,7 @@
#include "rigid_body.h"
#include "collision_object.h"
#include "../math/mathf.h"
struct PointConstraint {
struct PointConstraint* nextConstraint;

View file

@ -82,6 +82,24 @@ float rigidBodyMassInverseAtLocalPoint(struct RigidBody* rigidBody, struct Vecto
return rigidBody->massInv + rigidBody->momentOfInertiaInv * vector3MagSqrd(&crossPoint);
}
void rigidBodyClampToPortal(struct RigidBody* rigidBody, struct Transform* portal) {
struct Vector3 localPoint;
transformPointInverseNoScale(portal, &rigidBody->transform.position, &localPoint);
//clamping the x and y of local point to a slightly smaller oval on the output portal
struct Vector3 clampedLocalPoint;
clampedLocalPoint = localPoint;
clampedLocalPoint.y /= 2.0f;
clampedLocalPoint.z = 0.0f;
while(sqrtf(vector3MagSqrd(&clampedLocalPoint))>PORTAL_EXIT_XY_CLAMP_DISTANCE){
vector3Scale(&clampedLocalPoint, &clampedLocalPoint, 0.90f);
}
clampedLocalPoint.y *= 2.0f;
localPoint.x = clampedLocalPoint.x;
localPoint.y = clampedLocalPoint.y;
transformPoint(portal, &localPoint, &rigidBody->transform.position);
}
int rigidBodyCheckPortals(struct RigidBody* rigidBody) {
if (!gCollisionScene.portalTransforms[0] || !gCollisionScene.portalTransforms[1]) {
@ -94,6 +112,14 @@ int rigidBodyCheckPortals(struct RigidBody* rigidBody) {
enum RigidBodyFlags newFlags = 0;
//if only touching one portal, clamp object to edges of that portal
if ((rigidBody->flags & RigidBodyIsTouchingPortalA) && !(rigidBody->flags & RigidBodyIsTouchingPortalB)){
rigidBodyClampToPortal(rigidBody, gCollisionScene.portalTransforms[0]);
}
else if ((rigidBody->flags & RigidBodyIsTouchingPortalB) && !(rigidBody->flags & RigidBodyIsTouchingPortalA)){
rigidBodyClampToPortal(rigidBody, gCollisionScene.portalTransforms[1]);
}
if (rigidBody->flags & RigidBodyIsTouchingPortalA) {
newFlags |= RigidBodyWasTouchingPortalA;
}

View file

@ -3,6 +3,7 @@
#include "../math/basis.h"
#include "../math/transform.h"
#include "../math/mathf.h"
#include "./collision.h"
#define KILL_PLANE_Y -10.0f
@ -10,6 +11,7 @@
#define RIGID_BODY_NO_ROOM 0xFFFF
#define MAX_PORTAL_SPEED (1000.0f / 64.0f)
#define PORTAL_EXIT_XY_CLAMP_DISTANCE (0.15f)
enum RigidBodyFlags {
RigidBodyFlagsInFrontPortal0 = (1 << 0),

View file

@ -32,10 +32,10 @@
struct Vector3 gGrabDistance = {0.0f, 0.0f, -1.5f};
struct Vector3 gCameraOffset = {0.0f, 0.0f, 0.0f};
struct Vector3 gPortalGunOffset = {0.150957, -0.153587, -0.355};
struct Vector3 gPortalGunShootOffset = {0.150957, -0.153587, 0.1};
struct Vector3 gPortalGunOffset = {0.120957, -0.113587, -0.20916};
struct Vector3 gPortalGunShootOffset = {0.120957, -0.113587, -0.08};
struct Vector3 gPortalGunForward = {0.1f, -0.1f, 1.0f};
struct Vector3 gPortalGunShootForward = {0.1f, -0.25f, 1.0f};
struct Vector3 gPortalGunShootForward = {0.3f, -0.25f, 1.0f};
struct Vector3 gPortalGunUp = {0.0f, 1.0f, 0.0f};
struct Vector2 gPlayerColliderEdgeVectors[] = {
@ -173,7 +173,7 @@ void playerInit(struct Player* player, struct Location* startLocation, struct Ve
dynamicSceneSetRoomFlags(player->dynamicId, ROOM_FLAG_FROM_INDEX(player->body.currentRoom));
pointConstraintInit(&player->gunConstraint, portalGunObject, 20.0f, 2.5f, 1, 0.9f);
pointConstraintInit(&player->gunConstraint, portalGunObject, 20.0f, 2.5f, 1, 0.5f);
contactSolverAddPointConstraint(&gContactSolver, &player->gunConstraint);
}
@ -389,11 +389,9 @@ void playerUpdateGunObject(struct Player* player) {
struct Vector3 offset;
if (player->flags & PlayerJustShotPortalGun){
player->flags &= ~PlayerJustShotPortalGun;
forward = gPortalGunShootForward;
offset = gPortalGunShootOffset;
}
else{
}else{
forward = gPortalGunForward;
offset = gPortalGunOffset;
}

View file

@ -4,6 +4,8 @@
#include "../physics/collision_cylinder.h"
#include "models/models.h"
#define PORTAL_GUN_RECOIL_TIME (0.18f)
struct Vector2 gGunColliderEdgeVectors[] = {
{0.0f, 1.0f},
{0.707f, 0.707f},
@ -37,16 +39,9 @@ void portalGunInit(struct PortalGun* portalGun, struct Transform* at){
portalGun->rigidBody.currentRoom = 0;
portalGun->rigidBody.velocity = gZeroVec;
portalGun->rigidBody.angularVelocity = gZeroVec;
portalGun->dynamicId = dynamicSceneAdd(portalGun, portalGunDummyRender, &portalGun->rigidBody.transform.position, 0.05f);
portalGun->portalGunVisible = 0;
portalGun->shootAnimationTimer = 0.0;
collisionObjectUpdateBB(&portalGun->collisionObject);
dynamicSceneSetRoomFlags(portalGun->dynamicId, ROOM_FLAG_FROM_INDEX(portalGun->rigidBody.currentRoom));
}
void portalGunDummyRender(void* data, struct DynamicRenderDataList* renderList, struct RenderState* renderState){
return;
}
void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* renderState){
@ -65,14 +60,22 @@ void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* render
}
}
void portalGunUpdate(struct PortalGun* portalGun, struct Player* player){
if (player->flags & (PlayerHasFirstPortalGun | PlayerHasSecondPortalGun)){
portalGun->portalGunVisible = 1;
}
else{
}else{
portalGun->portalGunVisible = 0;
}
dynamicSceneSetRoomFlags(portalGun->dynamicId, ROOM_FLAG_FROM_INDEX(portalGun->rigidBody.currentRoom));
if (player->flags & PlayerJustShotPortalGun && portalGun->shootAnimationTimer <= 0.0f){
portalGun->shootAnimationTimer = PORTAL_GUN_RECOIL_TIME;
}
if (portalGun->shootAnimationTimer >= 0.0f){
portalGun->shootAnimationTimer -= FIXED_DELTA_TIME;
if (portalGun->shootAnimationTimer <= 0.0f){
portalGun->shootAnimationTimer = 0.0f;
player->flags &= ~PlayerJustShotPortalGun;
}
}
}

View file

@ -8,16 +8,17 @@
#include "../physics/collision_object.h"
#include "../scene/dynamic_scene.h"
#include "../player/player.h"
#include "../util/time.h"
struct PortalGun {
struct CollisionObject collisionObject;
struct RigidBody rigidBody;
int portalGunVisible;
short dynamicId;
float shootAnimationTimer;
};
void portalGunInit(struct PortalGun* portalGun, struct Transform* at);
void portalGunDummyRender(void* data, struct DynamicRenderDataList* renderList, struct RenderState* renderState);
// void portalGunDummyRender(void* data, struct DynamicRenderDataList* renderList, struct RenderState* renderState);
void portalGunUpdate(struct PortalGun* portalGun, struct Player* player);
void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* renderState);

View file

@ -255,14 +255,21 @@ void sceneCheckPortals(struct Scene* scene) {
quatMultVector(&scene->player.lookTransform.rotation, &raycastRay.dir, &raycastRay.dir);
quatMultVector(&scene->player.lookTransform.rotation, &gUp, &playerUp);
if (controllerGetButtonDown(0, Z_TRIG) && (scene->player.flags & PlayerHasSecondPortalGun) && !playerIsGrabbing(&scene->player)) {
int bluePortalFlags;
if (scene->player.flags & PlayerHasSecondPortalGun){
bluePortalFlags = (L_TRIG);
}else{
bluePortalFlags = (L_TRIG | Z_TRIG | R_TRIG);
}
if (controllerGetButtonDown(0, Z_TRIG | R_TRIG) && (scene->player.flags & PlayerHasSecondPortalGun) && !playerIsGrabbing(&scene->player)) {
sceneFirePortal(scene, &raycastRay, &playerUp, 0, scene->player.body.currentRoom, 1, 0);
scene->player.flags |= PlayerJustShotPortalGun;
scene->last_portal_indx_shot=0;
soundPlayerPlay(soundsPortalgunShoot[0], 1.0f, 1.0f, NULL, NULL);
}
if (controllerGetButtonDown(0, R_TRIG | L_TRIG) && (scene->player.flags & PlayerHasFirstPortalGun) && !playerIsGrabbing(&scene->player)) {
if (controllerGetButtonDown(0, bluePortalFlags) && (scene->player.flags & PlayerHasFirstPortalGun) && !playerIsGrabbing(&scene->player)) {
sceneFirePortal(scene, &raycastRay, &playerUp, 1, scene->player.body.currentRoom, 1, 0);
scene->player.flags |= PlayerJustShotPortalGun;
scene->last_portal_indx_shot=1;