0% found this document useful (0 votes)
16 views3 pages

Message

The document contains C++ code defining a VR locomotion system with classes for handling 3D vectors, VR rig transformations, and punch mechanics. It includes methods for calculating distances, applying forces, and managing the state of VR rigs during gameplay. The main function demonstrates an example usage of the punch mechanic within the VR environment.

Uploaded by

lukassmiller2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Message

The document contains C++ code defining a VR locomotion system with classes for handling 3D vectors, VR rig transformations, and punch mechanics. It includes methods for calculating distances, applying forces, and managing the state of VR rigs during gameplay. The main function demonstrates an example usage of the punch mechanic within the VR environment.

Uploaded by

lukassmiller2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <vector>

#include <unordered_map>
#include <cmath>

struct Vector3 {
float x, y, z;

Vector3() : x(0), y(0), z(0) {}


Vector3(float x, float y, float z) : x(x), y(y), z(z) {}

static float Distance(const Vector3& a, const Vector3& b) {


return std::sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +
(a.z - b.z) * (a.z - b.z));
}

Vector3 operator-(const Vector3& other) const {


return Vector3(x - other.x, y - other.y, z - other.z);
}

Vector3 Normalize() const {


float length = std::sqrt(x * x + y * y + z * z);
return Vector3(x / length, y / length, z / length);
}

Vector3 operator*(float scalar) const {


return Vector3(x * scalar, y * scalar, z * scalar);
}

void operator+=(const Vector3& other) {


x += other.x;
y += other.y;
z += other.z;
}
};

struct VRRig {
struct Transform {
Vector3 position;
};

Transform rightHandTransform;
Transform leftHandTransform;
Transform head;

VRRig() {
[Link] = Vector3();
[Link] = Vector3();
[Link] = Vector3();
}
};

struct Rigidbody {
Vector3 velocity;

Rigidbody() : velocity(Vector3()) {}

void ApplyForce(const Vector3& force) {


velocity += force;
}
};

class GorillaLocomotionPlayer {
public:
static GorillaLocomotionPlayer* Instance() {
static GorillaLocomotionPlayer instance;
return &instance;
}

Rigidbody* GetComponent() {
return &rigidbody;
}

private:
Rigidbody rigidbody;
};

class GorillaParent {
public:
static GorillaParent* Instance() {
static GorillaParent instance;
return &instance;
}

std::vector<VRRig> vrrigs;
};

class GorillaTagger {
public:
static GorillaTagger* Instance() {
static GorillaTagger instance;
return &instance;
}

VRRig* offlineVRRig;
};

class Punch {
public:
static float punchForce;
static float punchRange;
static std::unordered_map<VRRig*, Vector3> lastRightPositions;
static std::unordered_map<VRRig*, Vector3> lastLeftPositions;

static void PunchMod() {


VRRig* playerRig = GorillaTagger::Instance()->offlineVRRig;
Vector3 playerHeadPosition = playerRig->[Link];
Rigidbody* playerRigidbody = GorillaLocomotionPlayer::Instance()-
>GetComponent();

for (VRRig& otherRig : GorillaParent::Instance()->vrrigs) {


if (&otherRig == playerRig) continue;

CheckAndApplyPunch(&otherRig, [Link],
playerHeadPosition, playerRigidbody, lastRightPositions);
CheckAndApplyPunch(&otherRig, [Link],
playerHeadPosition, playerRigidbody, lastLeftPositions);
}
}
private:
static void CheckAndApplyPunch(VRRig* rig, VRRig::Transform& handTransform,
const Vector3& playerHeadPosition, Rigidbody* playerRigidbody,
std::unordered_map<VRRig*, Vector3>& lastPositions) {
Vector3 handPosition = [Link];
float distance = Vector3::Distance(handPosition, playerHeadPosition);

if (distance < punchRange) {


auto it = [Link](rig);
if (it != [Link]()) {
Vector3 lastPosition = it->second;
Vector3 punchDirection = (handPosition - lastPosition).Normalize();
playerRigidbody->ApplyForce(punchDirection * punchForce);
}
}

lastPositions[rig] = handPosition;
}
};

float Punch::punchForce = 10.0f;


float Punch::punchRange = 0.25f;
std::unordered_map<VRRig*, Vector3> Punch::lastRightPositions;
std::unordered_map<VRRig*, Vector3> Punch::lastLeftPositions;

int main() {
// Example usage (you'd probably trigger PunchMod() based on some game event)
Punch::PunchMod();
return 0;
}

You might also like