Camera and input fixes

This commit is contained in:
Jack Andersen 2017-12-15 14:19:15 -10:00
parent ce6a3aa50c
commit ce2ed8cec6
6 changed files with 94 additions and 76 deletions

View File

@ -131,56 +131,79 @@ static void PopulateAreaFields(DEAFBABE& db,
db.memSize = 0; db.memSize = 0;
} }
class MaterialPool
{
std::unordered_map<u64, int> m_materials;
public:
template <class M, class V>
int AddOrLookup(const M& mat, V& vec)
{
auto search = m_materials.find(mat.material);
if (search != m_materials.end())
return search->second;
auto idx = int(vec.size());
vec.push_back(mat);
m_materials[mat.material] = idx;
return idx;
}
};
template<class DEAFBABE> template<class DEAFBABE>
void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh) void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh)
{ {
db.materials.reserve(colMesh.materials.size() * 2); using BlendMat = hecl::BlenderConnection::DataStream::ColMesh::Material;
for (const hecl::BlenderConnection::DataStream::ColMesh::Material& mat : colMesh.materials)
auto MakeMat = [](const BlendMat& mat, bool flipFace) -> typename DEAFBABE::Material
{ {
db.materials.emplace_back(); typename DEAFBABE::Material dbMat = {};
db.materials.back().setUnknown(mat.unknown); dbMat.setUnknown(mat.unknown);
db.materials.back().setSurfaceStone(mat.surfaceStone); dbMat.setSurfaceStone(mat.surfaceStone);
db.materials.back().setSurfaceMetal(mat.surfaceMetal); dbMat.setSurfaceMetal(mat.surfaceMetal);
db.materials.back().setSurfaceGrass(mat.surfaceGrass); dbMat.setSurfaceGrass(mat.surfaceGrass);
db.materials.back().setSurfaceIce(mat.surfaceIce); dbMat.setSurfaceIce(mat.surfaceIce);
db.materials.back().setPillar(mat.pillar); dbMat.setPillar(mat.pillar);
db.materials.back().setSurfaceMetalGrating(mat.surfaceMetalGrating); dbMat.setSurfaceMetalGrating(mat.surfaceMetalGrating);
db.materials.back().setSurfacePhazon(mat.surfacePhazon); dbMat.setSurfacePhazon(mat.surfacePhazon);
db.materials.back().setSurfaceDirt(mat.surfaceDirt); dbMat.setSurfaceDirt(mat.surfaceDirt);
db.materials.back().setSurfaceLava(mat.surfaceLava); dbMat.setSurfaceLava(mat.surfaceLava);
db.materials.back().setSurfaceSPMetal(mat.surfaceSPMetal); dbMat.setSurfaceSPMetal(mat.surfaceSPMetal);
db.materials.back().setSurfaceStoneRock(mat.surfaceStoneRock); dbMat.setSurfaceStoneRock(mat.surfaceStoneRock);
db.materials.back().setSurfaceSnow(mat.surfaceSnow); dbMat.setSurfaceSnow(mat.surfaceSnow);
db.materials.back().setSurfaceMudSlow(mat.surfaceMudSlow); dbMat.setSurfaceMudSlow(mat.surfaceMudSlow);
db.materials.back().setSurfaceFabric(mat.surfaceFabric); dbMat.setSurfaceFabric(mat.surfaceFabric);
db.materials.back().setHalfPipe(mat.halfPipe); dbMat.setHalfPipe(mat.halfPipe);
db.materials.back().setSurfaceMud(mat.surfaceMud); dbMat.setSurfaceMud(mat.surfaceMud);
db.materials.back().setSurfaceGlass(mat.surfaceGlass); dbMat.setSurfaceGlass(mat.surfaceGlass);
db.materials.back().setUnused3(mat.unused3); dbMat.setUnused3(mat.unused3);
db.materials.back().setUnused4(mat.unused4); dbMat.setUnused4(mat.unused4);
db.materials.back().setSurfaceShield(mat.surfaceShield); dbMat.setSurfaceShield(mat.surfaceShield);
db.materials.back().setSurfaceSand(mat.surfaceSand); dbMat.setSurfaceSand(mat.surfaceSand);
db.materials.back().setSurfaceMothOrSeedOrganics(mat.surfaceMothOrSeedOrganics); dbMat.setSurfaceMothOrSeedOrganics(mat.surfaceMothOrSeedOrganics);
db.materials.back().setSurfaceWeb(mat.surfaceWeb); dbMat.setSurfaceWeb(mat.surfaceWeb);
db.materials.back().setProjectilePassthrough(mat.projPassthrough); dbMat.setProjectilePassthrough(mat.projPassthrough);
db.materials.back().setSolid(mat.solid); dbMat.setSolid(mat.solid);
db.materials.back().setU20(mat.u20); dbMat.setU20(mat.u20);
db.materials.back().setCameraPassthrough(mat.camPassthrough); dbMat.setCameraPassthrough(mat.camPassthrough);
db.materials.back().setSurfaceWood(mat.surfaceWood); dbMat.setSurfaceWood(mat.surfaceWood);
db.materials.back().setSurfaceOrganic(mat.surfaceOrganic); dbMat.setSurfaceOrganic(mat.surfaceOrganic);
db.materials.back().setU24(mat.u24); dbMat.setU24(mat.u24);
db.materials.back().setSurfaceRubber(mat.surfaceRubber); dbMat.setSurfaceRubber(mat.surfaceRubber);
db.materials.back().setSeeThrough(mat.seeThrough); dbMat.setSeeThrough(mat.seeThrough);
db.materials.back().setScanPassthrough(mat.scanPassthrough); dbMat.setScanPassthrough(mat.scanPassthrough);
db.materials.back().setAiPassthrough(mat.aiPassthrough); dbMat.setAiPassthrough(mat.aiPassthrough);
db.materials.back().setCeiling(mat.ceiling); dbMat.setCeiling(mat.ceiling);
db.materials.back().setWall(mat.wall); dbMat.setWall(mat.wall);
db.materials.back().setFloor(mat.floor); dbMat.setFloor(mat.floor);
db.materials.back().setAiBlock(mat.aiBlock); dbMat.setAiBlock(mat.aiBlock);
db.materials.back().setJumpNotAllowed(mat.jumpNotAllowed); dbMat.setJumpNotAllowed(mat.jumpNotAllowed);
db.materials.back().setSpiderBall(mat.spiderBall); dbMat.setSpiderBall(mat.spiderBall);
db.materials.back().setScrewAttackWallJump(mat.screwAttackWallJump); dbMat.setScrewAttackWallJump(mat.screwAttackWallJump);
} dbMat.setFlipFace(flipFace);
return dbMat;
};
MaterialPool matPool;
db.materials.reserve(colMesh.materials.size() * 2);
zeus::CAABox fullAABB; zeus::CAABox fullAABB;
@ -209,16 +232,8 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS
db.triangleEdgeConnections.reserve(colMesh.trianges.size()); db.triangleEdgeConnections.reserve(colMesh.trianges.size());
for (const auto& tri : colMesh.trianges) for (const auto& tri : colMesh.trianges)
{ {
if (tri.flip) int triMatIdx = matPool.AddOrLookup(MakeMat(colMesh.materials[tri.matIdx], tri.flip), db.materials);
{ db.triMats.push_back(triMatIdx);
db.triMats.push_back(db.materials.size());
db.materials.push_back(db.materials[tri.matIdx]);
db.materials.back().setFlipFace(true);
}
else
{
db.triMats.push_back(tri.matIdx);
}
db.triangleEdgeConnections.emplace_back(); db.triangleEdgeConnections.emplace_back();
db.triangleEdgeConnections.back().edges[0] = tri.edges[0]; db.triangleEdgeConnections.back().edges[0] = tri.edges[0];
@ -227,9 +242,9 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS
for (int e=0 ; e<3 ; ++e) for (int e=0 ; e<3 ; ++e)
{ {
db.edgeMats[tri.edges[e]] = tri.matIdx; db.edgeMats[tri.edges[e]] = triMatIdx;
for (int v=0 ; v<2 ; ++v) for (int v=0 ; v<2 ; ++v)
db.vertMats[colMesh.edges[e].verts[v]] = tri.matIdx; db.vertMats[colMesh.edges[e].verts[v]] = triMatIdx;
} }
} }
db.triMatsCount = colMesh.trianges.size(); db.triMatsCount = colMesh.trianges.size();

View File

@ -86,7 +86,6 @@ void CFirstPersonCamera::CalculateGunFollowOrientationAndTransform(zeus::CTransf
{ {
zeus::CVector3f gunFrontVec = x190_gunFollowXf.frontVector(); zeus::CVector3f gunFrontVec = x190_gunFollowXf.frontVector();
gunFrontVec.z = 0.f; gunFrontVec.z = 0.f;
if (gunFrontVec.canBeNormalized()) if (gunFrontVec.canBeNormalized())
gunFrontVec.normalize(); gunFrontVec.normalize();
@ -95,16 +94,15 @@ void CFirstPersonCamera::CalculateGunFollowOrientationAndTransform(zeus::CTransf
if (rVecNoZ.canBeNormalized()) if (rVecNoZ.canBeNormalized())
rVecNoZ.normalize(); rVecNoZ.normalize();
gunXf = zeus::CQuaternion::lookAt(gunFrontVec, rVecNoZ, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * gunXf = zeus::CQuaternion::lookAt(gunFrontVec, rVecNoZ, 2.f * M_PIF).toTransform() *
x190_gunFollowXf.getRotation(); x190_gunFollowXf.getRotation();
zeus::CVector3f newgunFront = gunXf.frontVector(); zeus::CVector3f newgunFront = gunXf.frontVector();
if (newgunFront.canBeNormalized()) if (newgunFront.canBeNormalized())
newgunFront.normalize(); newgunFront.normalize();
float angle = newgunFront.dot(rVec); float angle = newgunFront.dot(rVec);
angle = std::min(angle, 1.f); angle = zeus::clamp(-1.f, angle, 1.f);
gunQ = zeus::CQuaternion::lookAt(newgunFront, rVec, zeus::clamp(0.f, std::acos(angle) / dt, 1.f) * dt); gunQ = zeus::CQuaternion::lookAt(newgunFront, rVec, zeus::clamp(0.f, std::acos(angle) / dt, 1.f) * dt);
} }
@ -136,7 +134,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
vec.normalize(); vec.normalize();
} }
rVec = zeus::CQuaternion::lookAt({0.f, 1.f, 0.f}, rVec, zeus::CRelAngle::FromDegrees(360.f)).transform(vec); rVec = zeus::CQuaternion::lookAt({0.f, 1.f, 0.f}, rVec, 2.f * M_PIF).transform(vec);
} }
zeus::CVector3f eyePos = player->GetEyePosition(); zeus::CVector3f eyePos = player->GetEyePosition();
@ -198,11 +196,11 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
float angle = zeus::clamp(0.f, (player->x29c_fallCameraTimer - g_tweakPlayer->GetFallCameraPitchDownStart()) / float angle = zeus::clamp(0.f, (player->x29c_fallCameraTimer - g_tweakPlayer->GetFallCameraPitchDownStart()) /
g_tweakPlayer->GetFallCameraPitchDownFull(), 1.f) * g_tweakPlayer->GetFallCameraPitchDownFull(), 1.f) *
g_tweakPlayer->GetFallCameraPitchDownAngle(); g_tweakPlayer->GetFallCameraPitchDownAngle();
//rVec.x = 0.f; rVec.x = 0.f;
//rVec.y = std::cos(angle); rVec.y = std::cos(angle);
//rVec.z = -std::sin(angle); rVec.z = -std::sin(angle);
//rVec = playerXf.rotate(rVec); rVec = playerXf.rotate(rVec);
} }
} }
break; break;
@ -253,7 +251,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
angle = zeus::clamp(-1.f, angle, 1.f); angle = zeus::clamp(-1.f, angle, 1.f);
float clampedAngle = zeus::clamp(0.f, std::acos(angle) / scaledDt, 1.f); float clampedAngle = zeus::clamp(0.f, std::acos(angle) / scaledDt, 1.f);
if (angle > 0.999f || x18c_lockCamera || player->x374_orbitLockEstablished) if (angle > 0.999f || x18c_lockCamera || player->x374_orbitLockEstablished)
qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, zeus::CRelAngle::FromDegrees(360.f)); qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, 2.f * M_PIF);
else else
qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, scaledDt * clampedAngle); qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, scaledDt * clampedAngle);
@ -271,7 +269,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
rVecCpy.normalize(); rVecCpy.normalize();
gunXf = gunXf =
zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, 2.f * M_PIF).toTransform() *
x190_gunFollowXf.getRotation(); x190_gunFollowXf.getRotation();
gunFrontVec = gunXf.frontVector(); gunFrontVec = gunXf.frontVector();
@ -283,7 +281,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
//angle = zeus::clamp(-1.f, angle, 1.f); //angle = zeus::clamp(-1.f, angle, 1.f);
//angle = zeus::clamp(0.f, std::acos(angle) / sdt, 1.f); //angle = zeus::clamp(0.f, std::acos(angle) / sdt, 1.f);
qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)); qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, 2.f * M_PIF);
} }
break; break;
} }
@ -301,7 +299,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
if (rVecCpy.canBeNormalized()) if (rVecCpy.canBeNormalized())
rVecCpy.normalize(); rVecCpy.normalize();
gunXf = zeus::CQuaternion::lookAt(gunFront, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * gunXf = zeus::CQuaternion::lookAt(gunFront, rVecCpy, 2.f * M_PIF).toTransform() *
x190_gunFollowXf.getRotation(); x190_gunFollowXf.getRotation();
gunFront = gunXf.frontVector(); gunFront = gunXf.frontVector();
if (gunFront.canBeNormalized()) if (gunFront.canBeNormalized())
@ -328,8 +326,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
} }
x190_gunFollowXf = qGun.toTransform() * gunXf; x190_gunFollowXf = qGun.toTransform() * gunXf;
//SetTransform(x190_gunFollowXf * bobXf.getRotation()); SetTransform(x190_gunFollowXf * bobXf.getRotation());
SetTransform(playerXf);
x190_gunFollowXf.origin = eyePos; x190_gunFollowXf.origin = eyePos;
CActor::SetTranslation(eyePos + player->GetTransform().rotate(bobXf.origin)); CActor::SetTranslation(eyePos + player->GetTransform().rotate(bobXf.origin));
x190_gunFollowXf.orthonormalize(); x190_gunFollowXf.orthonormalize();

View File

@ -55,6 +55,12 @@ public:
m_leftDiv(leftDiv), m_leftDiv(leftDiv),
m_rightDiv(rightDiv) {} m_rightDiv(rightDiv) {}
~CInputGenerator()
{
if (smashAdapter)
smashAdapter->setCallback(nullptr);
}
/* Keyboard and mouse events are delivered on the main game /* Keyboard and mouse events are delivered on the main game
* thread as part of the app's main event loop. The OS is responsible * thread as part of the app's main event loop. The OS is responsible
* for buffering events in its own way, then boo flushes the buffer * for buffering events in its own way, then boo flushes the buffer

2
amuse

@ -1 +1 @@
Subproject commit 91b88c0568334c49a22c8f7bcc94f35e495f9a00 Subproject commit 3eba4cc1ac7cf08c23107302807e6d1adf9087db

2
hecl

@ -1 +1 @@
Subproject commit a7310a277f6c225dc6731b13a915b6cd1129ab24 Subproject commit 8e1909115231a7d83bf348d5afcc813180b77634

@ -1 +1 @@
Subproject commit 654374c1f28180b47f96a1524662756adfb1ac9c Subproject commit 0e4c7e20eab7e737fa114dab7fdeb5d54497fd5f