2023-10-15 16:23:43 -04:00
|
|
|
|
#include "remoteplayer.h"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstring>
|
2023-11-18 14:16:24 -05:00
|
|
|
|
|
2023-11-13 16:02:13 -05:00
|
|
|
|
#include <thread>
|
|
|
|
|
#include <queue>
|
2023-10-15 16:23:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-18 14:16:24 -05:00
|
|
|
|
|
|
|
|
|
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){
|
2023-11-13 16:02:13 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-19 16:46:13 -05:00
|
|
|
|
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-11-13 16:02:13 -05:00
|
|
|
|
RemotePlayer::~RemotePlayer()
|
|
|
|
|
{
|
2023-11-14 22:17:00 -05:00
|
|
|
|
|
2023-10-15 16:23:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-18 14:16:24 -05:00
|
|
|
|
void RemotePlayer::Init()
|
2023-11-14 22:17:00 -05:00
|
|
|
|
{
|
2023-10-15 16:23:43 -04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemotePlayer::Feed(const netprot::Output out) {
|
|
|
|
|
|
2023-11-24 14:54:38 -05:00
|
|
|
|
m_position = Vector3f(out.position);
|
2023-12-06 13:43:33 -05:00
|
|
|
|
m_direction = Vector3f(out.direction);
|
2023-12-06 14:31:04 -05:00
|
|
|
|
|
2023-12-06 16:20:52 -05:00
|
|
|
|
std::cout << "Dead: " << out.states.dead << " Hit:" << out.states.hit << " Jump:" << out.states.jumping << " JumpShot: " << out.states.jumpshot << " Running: " << out.states.running << " Shooting: " << out.states.shooting << " Still: " << out.states.still << std::endl;
|
2023-12-06 15:51:55 -05:00
|
|
|
|
//std::cout << "powerUp " << out.states.powerup << std::endl;
|
2023-12-06 16:20:52 -05:00
|
|
|
|
current.states = out.states;
|
2023-12-06 14:31:04 -05:00
|
|
|
|
|
2023-11-24 14:54:38 -05:00
|
|
|
|
//current.position = out.position;
|
|
|
|
|
//current.direction = out.direction;
|
|
|
|
|
//current.states = out.states;
|
|
|
|
|
//current.id = out.id;
|
|
|
|
|
|
|
|
|
|
//if (current.position != previous.position)
|
|
|
|
|
//{
|
|
|
|
|
// Vector3f positionDelta = current.position - previous.position;
|
|
|
|
|
// m_position = current.position + positionDelta;
|
|
|
|
|
// m_direction = current.direction;
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if(current.direction != previous.direction)
|
|
|
|
|
//{
|
|
|
|
|
// m_direction = current.direction;
|
|
|
|
|
// current.direction = current.direction;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (current.states.shooting) {
|
|
|
|
|
// m_animstate = Anim::SHOOTING;
|
|
|
|
|
//}
|
|
|
|
|
//else if (current.states.jumping) {
|
|
|
|
|
// m_animstate = Anim::JUMPING;
|
|
|
|
|
//}
|
|
|
|
|
//else if (current.states.dead) {
|
|
|
|
|
// m_animstate = Anim::DEAD;
|
|
|
|
|
//}
|
|
|
|
|
//else if(current.states.powerup){
|
|
|
|
|
// m_animstate = Anim::POWERUP;
|
|
|
|
|
//}
|
|
|
|
|
//else if (current.states.still) {
|
|
|
|
|
// m_animstate = Anim::STILL;
|
|
|
|
|
//}
|
|
|
|
|
//else if (current.states.running) {
|
|
|
|
|
// m_animstate = Anim::RUNNING;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//previous.direction = current.direction;
|
|
|
|
|
//previous.position = current.position;
|
|
|
|
|
//previous.states = current.states;
|
|
|
|
|
//previous.id = current.id;
|
|
|
|
|
|
|
|
|
|
//m_direction = current.direction;
|
|
|
|
|
//m_position = current.position;
|
2023-11-13 16:02:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-02 15:19:46 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime, Player& camera)
|
2023-11-13 16:02:13 -05:00
|
|
|
|
{
|
2023-12-02 15:19:46 -05:00
|
|
|
|
|
2023-11-20 14:28:54 -05:00
|
|
|
|
float width = 1.f;
|
|
|
|
|
float height = 1.7f;
|
2023-12-04 19:05:36 -05:00
|
|
|
|
|
2023-12-04 16:45:46 -05:00
|
|
|
|
Vector3f DiffCam = GetPosition() - camera.GetPosition();
|
2023-12-04 17:02:15 -05:00
|
|
|
|
Vector3f UpCam = Vector3f(0.f, 1.f, 0.f);
|
2023-12-07 12:10:17 -05:00
|
|
|
|
|
2023-12-04 16:45:46 -05:00
|
|
|
|
Vector3f CrossA = DiffCam.Cross(UpCam);
|
|
|
|
|
Vector3f CrossB = DiffCam.Cross(CrossA);
|
2023-12-07 12:10:17 -05:00
|
|
|
|
|
2023-12-04 16:45:46 -05:00
|
|
|
|
CrossA.Normalize();
|
|
|
|
|
CrossB.Normalize();
|
2023-12-07 12:10:17 -05:00
|
|
|
|
|
2023-12-04 17:02:15 -05:00
|
|
|
|
Vector3f playerPosition = GetPosition() + Vector3f(0.f, -.75f, 0.f);
|
2023-12-07 12:10:17 -05:00
|
|
|
|
|
2023-12-04 17:02:15 -05:00
|
|
|
|
Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height);
|
|
|
|
|
Vector3f v1 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height);
|
2023-12-04 16:45:46 -05:00
|
|
|
|
Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height);
|
|
|
|
|
Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height);
|
2023-11-18 14:16:24 -05:00
|
|
|
|
|
2023-12-04 19:05:36 -05:00
|
|
|
|
Vector3f angleRemote = GetDirection();
|
2023-12-06 10:48:04 -05:00
|
|
|
|
Vector3f angleCam = (v1 - v2).Cross(v3 - v2);
|
2023-12-07 12:10:17 -05:00
|
|
|
|
|
2023-12-04 19:05:36 -05:00
|
|
|
|
angleCam.y = 0;
|
|
|
|
|
angleRemote.y = 0;
|
|
|
|
|
angleCam.Normalize();
|
|
|
|
|
angleRemote.Normalize();
|
|
|
|
|
|
|
|
|
|
float angle = angleRemote.Dot(angleCam);
|
|
|
|
|
int index = 0;
|
2023-12-06 13:46:24 -05:00
|
|
|
|
angle = -angle;
|
2023-12-06 10:48:04 -05:00
|
|
|
|
Vector3f side = angleRemote.Cross(angleCam);
|
2023-12-04 19:05:36 -05:00
|
|
|
|
|
2023-12-06 16:35:39 -05:00
|
|
|
|
static float time = 0.f;
|
2023-12-06 16:20:52 -05:00
|
|
|
|
static bool Shooting = false;
|
2023-12-07 12:10:17 -05:00
|
|
|
|
bool isLeft = side.y > 0;
|
2023-12-06 16:35:39 -05:00
|
|
|
|
|
|
|
|
|
time += elapsedTime;
|
|
|
|
|
if (time >= 200)
|
|
|
|
|
{
|
2023-12-06 17:02:36 -05:00
|
|
|
|
time -= 200;
|
|
|
|
|
if (!current.states.shooting)
|
|
|
|
|
Shooting = false;
|
2023-12-07 12:10:17 -05:00
|
|
|
|
else
|
2023-12-06 17:02:36 -05:00
|
|
|
|
Shooting = !Shooting;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-06 16:35:39 -05:00
|
|
|
|
|
2023-12-06 17:02:36 -05:00
|
|
|
|
|
2023-12-07 12:10:17 -05:00
|
|
|
|
if (angle >= 0.75) //Face - side positif
|
|
|
|
|
{
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if(current.states.shooting){
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 17;
|
|
|
|
|
else
|
|
|
|
|
index = 9;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 41;
|
|
|
|
|
else
|
|
|
|
|
index = 33;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping)
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 25;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= 0.25 && isLeft) //Frontleft
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 18;
|
|
|
|
|
else
|
|
|
|
|
index = 10;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 42;
|
|
|
|
|
else
|
|
|
|
|
index = 34;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping )
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 26;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 1;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= -0.25 && isLeft) //ProfileLeft
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 20;
|
|
|
|
|
else
|
|
|
|
|
index = 12;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot ) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 44;
|
|
|
|
|
else
|
|
|
|
|
index = 36;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping )
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 28;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 3;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= -0.75 && isLeft) //BackLeft
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 22;
|
|
|
|
|
else
|
|
|
|
|
index = 14;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 46;
|
|
|
|
|
else
|
|
|
|
|
index = 38;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping)
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 30;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 5;
|
|
|
|
|
}
|
2023-12-07 12:10:17 -05:00
|
|
|
|
else if (angle < -0.75) //Dos - side n<>gatif
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 24;
|
|
|
|
|
else
|
|
|
|
|
index = 16;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 48;
|
|
|
|
|
else
|
|
|
|
|
index = 40;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping )
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 32;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 7;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= 0.25 && !isLeft) //FrontRight
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 19;
|
|
|
|
|
else
|
|
|
|
|
index = 11;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 43;
|
|
|
|
|
else
|
|
|
|
|
index = 35;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping)
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 27;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 2;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= -0.25 && !isLeft) //ProfileRight
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 21;
|
|
|
|
|
else
|
|
|
|
|
index = 13;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 45;
|
|
|
|
|
else
|
|
|
|
|
index = 37;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping)
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 29;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 4;
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-06 10:48:04 -05:00
|
|
|
|
else if (angle >= -0.75 && !isLeft) //BackRight
|
2023-12-06 16:20:52 -05:00
|
|
|
|
{
|
|
|
|
|
if (current.states.shooting) {
|
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 23;
|
|
|
|
|
else
|
|
|
|
|
index = 15;
|
|
|
|
|
}
|
2023-12-07 12:43:16 -05:00
|
|
|
|
else if (current.states.jumpshot) {
|
2023-12-06 16:20:52 -05:00
|
|
|
|
if (Shooting)
|
|
|
|
|
index = 47;
|
|
|
|
|
else
|
|
|
|
|
index = 39;
|
|
|
|
|
}
|
2023-12-07 12:31:04 -05:00
|
|
|
|
else if (current.states.jumping)
|
2023-12-06 16:20:52 -05:00
|
|
|
|
index = 31;
|
|
|
|
|
else if (current.states.running && current.states.still)
|
|
|
|
|
index = 6;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 19:05:36 -05:00
|
|
|
|
|
|
|
|
|
|
2023-11-15 08:27:51 -05:00
|
|
|
|
float u, v, w, h;
|
2023-12-02 15:19:46 -05:00
|
|
|
|
|
2023-11-19 16:46:13 -05:00
|
|
|
|
shader.Use();
|
2023-11-15 08:27:51 -05:00
|
|
|
|
atlas.Bind();
|
2023-12-04 19:05:36 -05:00
|
|
|
|
atlas.TextureIndexToCoord(index, u, v, w, h);
|
2023-11-19 16:46:13 -05:00
|
|
|
|
|
2023-11-20 15:02:02 -05:00
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
glBlendEquation(GL_FUNC_ADD);
|
|
|
|
|
|
2023-11-19 16:46:13 -05:00
|
|
|
|
glLoadMatrixf(tran.GetMatrix().GetInternalValues());
|
|
|
|
|
glBegin(GL_QUADS);
|
2023-12-02 15:19:46 -05:00
|
|
|
|
glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z);
|
|
|
|
|
glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z);
|
|
|
|
|
glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z);
|
|
|
|
|
glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z);
|
2023-11-20 15:02:02 -05:00
|
|
|
|
|
2023-12-02 15:19:46 -05:00
|
|
|
|
glEnd();
|
2023-11-20 15:02:02 -05:00
|
|
|
|
|
|
|
|
|
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
|
|
|
|
glBlendEquation(GL_FUNC_SUBTRACT);
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
2023-11-15 08:27:51 -05:00
|
|
|
|
shader.Disable();
|
2023-12-02 15:19:46 -05:00
|
|
|
|
|
2023-11-13 16:02:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError)
|
|
|
|
|
{
|
|
|
|
|
texture.Load(filename, useMipmaps);
|
|
|
|
|
if (!texture.IsValid()) {
|
|
|
|
|
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
|
|
|
|
if (stopOnError)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|