introduces ios support? still needs metal
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
#include "baseentity.h"
|
||||
#include "baseplayer.h"
|
||||
#include "cglm/mat4.h"
|
||||
#include "cglm/util.h"
|
||||
#include "cglm/io.h"
|
||||
#include "cglm/vec2.h"
|
||||
#include "cglm/vec3.h"
|
||||
#include "console.h"
|
||||
#include "engine.h"
|
||||
#include "input.h"
|
||||
#include "math3d.h"
|
||||
#include "physics.h"
|
||||
#include "physics_gen.h"
|
||||
|
||||
#define STEP_SIZE 0.3f
|
||||
#define PLAYER_WIDTH 0.5f
|
||||
#define PLAYER_HEIGHT 1.8f
|
||||
#define EPSILON 0.0005f
|
||||
|
||||
class CMOBAPlayer: public CBasePlayer
|
||||
{
|
||||
public:
|
||||
@@ -18,9 +24,15 @@ public:
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
|
||||
void AirAccelerate();
|
||||
void Accelerate( float fDelta, vec2 wishDir, float fWishSpeed, float fAcceleration );
|
||||
void Move( float fDelta );
|
||||
void Accelerate( void );
|
||||
void AirAccelerate( void );
|
||||
int ClipVelocity( vec3 in, vec3 normal, vec3 &out, float fOverbounce );
|
||||
void FlyMove( void );
|
||||
void GroundMove( void );
|
||||
void AirMove( void );
|
||||
void CategorizePosition( void );
|
||||
void Friction( void );
|
||||
void PlayerMove( void );
|
||||
|
||||
|
||||
bool bIsForward = 0;
|
||||
@@ -33,14 +45,25 @@ public:
|
||||
bool bIsProning = 0;
|
||||
bool bIsFiring = 0;
|
||||
bool bIsFiring2 = 0;
|
||||
float fStamina;
|
||||
|
||||
float m_fDelta = 0;
|
||||
|
||||
float fPitch = 0;
|
||||
float fYaw = 0;
|
||||
|
||||
vec3 m_velocity;
|
||||
enum {
|
||||
PLAYER_GROUNDED,
|
||||
PLAYER_FLYING,
|
||||
} m_playerState;
|
||||
vec3 m_velocity = {0,0,0};
|
||||
vec3 m_prevVelocity = {0,0,0};
|
||||
|
||||
vec2 forward = {};
|
||||
vec2 right = {};
|
||||
|
||||
CPxBoxMesh mesh;
|
||||
CPxRigidBody rigidbody;
|
||||
CPxRigidKinematicPosition rigidbody;
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Precache()
|
||||
@@ -50,26 +73,7 @@ void CMOBAPlayer::Precache()
|
||||
|
||||
void CMOBAPlayer::Spawn()
|
||||
{
|
||||
mesh.m_fRadius[0] = 0.3;
|
||||
mesh.m_fRadius[1] = 0.3;
|
||||
mesh.m_fRadius[2] = 0.8;
|
||||
mesh.Spawn();
|
||||
px_matrix m = {};
|
||||
m.m[0] = 1;
|
||||
m.m[5] = 1;
|
||||
m.m[10] = 1;
|
||||
m.m[15] = 1;
|
||||
m.m[12] = m_position[0];
|
||||
m.m[13] = m_position[1];
|
||||
m.m[14] = m_position[2];
|
||||
rigidbody.Spawn(&mesh, m, {
|
||||
.gravity_scale = 1,
|
||||
.continous = true,
|
||||
.lockrotx = 1,
|
||||
.lockroty = 1,
|
||||
.lockrotz = 1,
|
||||
.dominance = 127,
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -83,68 +87,84 @@ void CMOBAPlayer::Destroy()
|
||||
|
||||
}
|
||||
|
||||
void CMOBAPlayer::AirAccelerate()
|
||||
void CMOBAPlayer::AirAccelerate( void )
|
||||
{
|
||||
m_velocity[2] -= 9.8 * m_fDelta;
|
||||
}
|
||||
|
||||
void CMOBAPlayer::Accelerate( void )
|
||||
{
|
||||
vec2 wishdir = {(float)bIsForward-bIsBack, (float)bIsLeft-bIsRight};
|
||||
vec3 velocityDifference;
|
||||
vec3 acceleration;
|
||||
glm_vec2_rotate(wishdir, fYaw, wishdir);
|
||||
glm_vec2_normalize(wishdir);
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
m_velocity[i] += (wishdir[i]*6 - m_velocity[i]) * m_fDelta/0.25;
|
||||
}
|
||||
|
||||
void CMOBAPlayer::Friction( void )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void CMOBAPlayer::FlyMove( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMOBAPlayer::Accelerate( float fDelta, vec2 wishDir, float fWishSpeed, float fAcceleration )
|
||||
void CMOBAPlayer::GroundMove( void )
|
||||
{
|
||||
float fCurrentSpeed = glm_vec2_dot(wishDir, m_velocity);
|
||||
float fAddSpeed = fWishSpeed - fCurrentSpeed;
|
||||
if ( fAddSpeed < 0 )
|
||||
return;
|
||||
float fAccelSpeed = fAcceleration*fDelta*fWishSpeed;
|
||||
if ( fAccelSpeed > fAddSpeed )
|
||||
fAccelSpeed = fAddSpeed;
|
||||
glm_vec2_scale(wishDir, fAccelSpeed, m_velocity);
|
||||
m_velocity[2] = 0;
|
||||
Accelerate();
|
||||
}
|
||||
|
||||
void CMOBAPlayer::Move( float fDelta )
|
||||
void CMOBAPlayer::CategorizePosition( void )
|
||||
{
|
||||
vec2 forward = {(float)bIsForward-(float)bIsBack,0};
|
||||
vec2 right = {0,(float)bIsLeft-(float)bIsRight};
|
||||
vec2 wishDir;
|
||||
float fWishSpeed;
|
||||
px_vec3 p;
|
||||
px_cast_result r;
|
||||
p.m[0] = m_position[0];
|
||||
p.m[1] = m_position[1];
|
||||
p.m[2] = m_position[2];
|
||||
r = px_box_cast(px, PLAYER_WIDTH/2, PLAYER_WIDTH/2, PLAYER_HEIGHT/2, p, (px_vec3){}, (px_vec3){0,0,-0.01}, 1);
|
||||
|
||||
glm_vec2_rotate(forward, fYaw, forward);
|
||||
glm_vec2_rotate(forward, fYaw, forward);
|
||||
glm_vec2_add(forward, right, wishDir);
|
||||
fWishSpeed = glm_vec2_distance(wishDir, (vec3){0,0,0});
|
||||
|
||||
if (fWishSpeed != 0)
|
||||
if (r.hit)
|
||||
{
|
||||
glm_vec2_divs(wishDir, fWishSpeed, wishDir);
|
||||
fWishSpeed = 10;
|
||||
m_playerState = PLAYER_GROUNDED;
|
||||
} else {
|
||||
glm_vec2_zero(wishDir);
|
||||
m_playerState = PLAYER_FLYING;
|
||||
}
|
||||
|
||||
Accelerate(fDelta, wishDir, fWishSpeed, 5.5);
|
||||
}
|
||||
|
||||
void CMOBAPlayer::PlayerMove( void )
|
||||
{
|
||||
CategorizePosition();
|
||||
|
||||
GroundMove();
|
||||
|
||||
vec3 velocity;
|
||||
for ( int i = 0; i < 3; i++ )
|
||||
velocity[i] = (m_prevVelocity[i] + m_velocity[i]) * 0.5;
|
||||
|
||||
for ( int i = 0; i < 3; i++ )
|
||||
m_position[i] += velocity[i] * m_fDelta;
|
||||
|
||||
for ( int i = 0; i < 3; i++ )
|
||||
m_prevVelocity[i] = m_velocity[i];
|
||||
|
||||
CategorizePosition();
|
||||
}
|
||||
|
||||
void CMOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
m_position[0] = rigidbody.GetPosition().m[0];
|
||||
m_position[1] = rigidbody.GetPosition().m[1];
|
||||
m_position[2] = rigidbody.GetPosition().m[2];
|
||||
px_vec3 v = rigidbody.GetVelocity();
|
||||
px_vec3 p = rigidbody.GetPosition();
|
||||
float x = g_fAxisValues[AXIS_MOUSE_X];
|
||||
float y = g_fAxisValues[AXIS_MOUSE_Y];
|
||||
fPitch = glm_rad(x);
|
||||
fYaw = glm_rad(y);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_velocity[i] = v.m[i];
|
||||
m_fDelta = fDelta;
|
||||
|
||||
px_cast_result r = px_box_cast(px, 0.3,0.3,0.01, {p.m[0],p.m[1],p.m[2]-0.79f}, {0,0,0}, {0,0,-1}, 1);
|
||||
if (r.hit)
|
||||
{
|
||||
Move(fDelta);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
v.m[i] = m_velocity[i];
|
||||
|
||||
rigidbody.SetVelocity(v);
|
||||
PlayerMove();
|
||||
};
|
||||
|
||||
void PlayerForward(int argc, char **argv) {if (g_localClient.pBasePlayer) ((CMOBAPlayer*)g_localClient.pBasePlayer)->bIsForward = true;};
|
||||
|
||||
Reference in New Issue
Block a user