Make player a cpp.

This commit is contained in:
2024-01-14 17:01:57 -05:00
parent fe10af70be
commit 291659bf5b
4 changed files with 51 additions and 41 deletions

View File

@@ -25,7 +25,7 @@ public:
bool debug = true;
uint64_t tickCount = 0;
uint64_t frameCount = 0;
float frameDelta = NULL;
float frameDelta = 0;
GLenum glError = GL_NO_ERROR;
float nearPlane = 0.01f;
float farPlane = 100.0f;

View File

@@ -14,7 +14,7 @@ public:
std::vector<LinearAlgebra::Vector3> angles;
//We won't even need that many positions anyways.
int16_t index = -1;
LinearAlgebra::Vector3 start = {NULL, NULL, NULL};
LinearAlgebra::Vector3 start = {0.0, 0.0, 0.0};
float velocity;
float lastDistance;
bool loop = false;

View File

@@ -2,9 +2,9 @@
#include <iostream>
#include <cmath>
#include <types/collision/collision.h>
#include <engine/engine.h>
#include <types/vertex.h>
#include <cstdint>
#include <types/moby.h>
class Player : public Moby {
public:
bool alive;
@@ -17,41 +17,9 @@ public:
//The "camera point" is the position the camera will want to be while following the player.
//We will probably end up having a different camera point class controlled by the "world".
LinearAlgebra::Vector3 cameraPoint (float distance) {
LinearAlgebra::Vector3 behindPosition = this->position;
LinearAlgebra::Vector3 reverseDirection = this->bAngle();
behindPosition.x -= reverseDirection.x * distance;
behindPosition.y -= reverseDirection.y * distance;
behindPosition.z -= reverseDirection.z * distance;
LinearAlgebra::Vector3 cameraPoint (float distance);
return behindPosition;
}
void update(float elapsed) override {}
void pre_render() override {
geometry = engine->world->getPlayerBaseGeometry();
geometry.scale(0.75f);
boundingBox = Collision::calculateBoundingBox(&geometry, angle);
position = {0,-2,0};
//std::cout << "Occluded: " << occluded << std::endl;
this->angle.y += 64*engine->frameDelta;
//this->angle.x = 1;
}
void render() override {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glTranslatef(position.x ,position.y,position.z);
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
geometry.draw();
glPopMatrix();
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(position.x ,position.y,position.z);
boundingBox.draw();
glPopMatrix();
}
void update(float elapsed) override;
void pre_render() override;
void render() override;
};

42
src/types/player.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <types/player.h>
#include <types/collision/collision.h>
void Player::pre_render() {
geometry = engine->world->getPlayerBaseGeometry();
geometry.scale(0.75f);
boundingBox = Collision::calculateBoundingBox(&geometry, angle);
position = {0,-2,0};
//std::cout << "Occluded: " << occluded << std::endl;
this->angle.y += 64*engine->frameDelta;
//this->angle.x = 1;
}
void Player::render() {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glTranslatef(position.x ,position.y,position.z);
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
geometry.draw();
glPopMatrix();
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(position.x ,position.y,position.z);
boundingBox.draw();
glPopMatrix();
}
LinearAlgebra::Vector3 Player::cameraPoint(float distance) {
LinearAlgebra::Vector3 behindPosition = this->position;
LinearAlgebra::Vector3 reverseDirection = this->bAngle();
behindPosition.x -= reverseDirection.x * distance;
behindPosition.y -= reverseDirection.y * distance;
behindPosition.z -= reverseDirection.z * distance;
return behindPosition;
}
void Player::update(float elapsed) {
}