forked from teamnwah/openmw-tes3coop
Preparing for clothes/armor
parent
07d0203a3c
commit
57299571d5
File diff suppressed because it is too large
Load Diff
@ -1,197 +0,0 @@
|
||||
#ifndef OENGINE_BULLET_PMOVE_H
|
||||
#define OENGINE_BULLET_PMOVE_H
|
||||
/*
|
||||
This source file is a *modified* version of various header files from the Quake 3 Arena source code,
|
||||
which was released under the GNU GPL (v2) in 2005.
|
||||
Quake 3 Arena is copyright (C) 1999-2005 Id Software, Inc.
|
||||
*/
|
||||
|
||||
#include <Ogre.h>
|
||||
#include <OgreMath.h>
|
||||
#include <float.h>
|
||||
#include "trace.h"
|
||||
#include "physic.hpp"
|
||||
|
||||
|
||||
//#include "GameMath.h"
|
||||
//#include "GameTime.h"
|
||||
|
||||
// Forwards-declare it!
|
||||
|
||||
/*#ifndef COMPILING_PMOVE
|
||||
#include "Scene.h"
|
||||
extern SceneInstance* global_lastscene;
|
||||
#endif*/
|
||||
|
||||
static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2);
|
||||
|
||||
#define MAX_CLIP_PLANES 5
|
||||
#define OVERCLIP 1.001f
|
||||
//#define STEPSIZE 18 // 18 is way too much
|
||||
#define STEPSIZE (18 / 2)
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846f
|
||||
#endif
|
||||
#define YAW 0
|
||||
#define PITCH /*1*/2
|
||||
#define ROLL /*2*/1
|
||||
#define SHORT2ANGLE(x) ( (x) * (360.0f / 65536.0f) )
|
||||
#define ANGLE2SHORT(x) ( (const short)( (x) / (360.0f / 65536.0f) ) )
|
||||
#define GENTITYNUM_BITS 10 // don't need to send any more
|
||||
#define MAX_GENTITIES (1 << GENTITYNUM_BITS)
|
||||
#define ENTITYNUM_NONE (MAX_GENTITIES - 1)
|
||||
#define ENTITYNUM_WORLD (MAX_GENTITIES - 2)
|
||||
#define MIN_WALK_NORMAL 0.7f // can't walk on very steep slopes
|
||||
#define JUMP_VELOCITY (270 * 1)
|
||||
#define PS_PMOVEFRAMECOUNTBITS 6
|
||||
#define MINS_Z -24
|
||||
#define DEFAULT_VIEWHEIGHT 26
|
||||
#define CROUCH_VIEWHEIGHT 12
|
||||
#define DEAD_VIEWHEIGHT (-16)
|
||||
#define CONTENTS_SOLID 1 // an eye is never valid in a solid
|
||||
#define CONTENTS_LAVA 8
|
||||
#define CONTENTS_SLIME 16
|
||||
#define CONTENTS_WATER 32
|
||||
#define CONTENTS_FOG 64
|
||||
static const float pm_accelerate = 10.0f;
|
||||
static const float pm_stopspeed = 100.0f;
|
||||
static const float pm_friction = 6.0f;
|
||||
static const float pm_flightfriction = 3.0f;
|
||||
static const float pm_waterfriction = 1.0f;
|
||||
static const float pm_airaccelerate = 1.0f;
|
||||
static const float pm_swimScale = 0.50f;
|
||||
static const float pm_duckScale = 0.25f;
|
||||
static const float pm_flyaccelerate = 8.0f;
|
||||
static const float pm_wateraccelerate = 4.0f;
|
||||
|
||||
enum pmtype_t : unsigned char
|
||||
{
|
||||
PM_NORMAL, // can accelerate and turn
|
||||
PM_NOCLIP, // noclip movement
|
||||
PM_SPECTATOR, // still run into walls
|
||||
PM_DEAD, // no acceleration or turning, but free falling
|
||||
PM_FREEZE, // stuck in place with no control
|
||||
PM_INTERMISSION, // no movement or status bar
|
||||
PM_SPINTERMISSION // no movement or status bar
|
||||
};
|
||||
|
||||
enum waterlevel_t : unsigned char
|
||||
{
|
||||
WL_DRYLAND = 0,
|
||||
WL_ANKLE,
|
||||
WL_WAIST,
|
||||
WL_UNDERWATER
|
||||
};
|
||||
|
||||
|
||||
//#include "bprintf.h"
|
||||
|
||||
struct playerMove
|
||||
{
|
||||
struct playerStruct
|
||||
{
|
||||
playerStruct() : gravity(50.0f), speed(320.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NORMAL), pm_time(0)
|
||||
{
|
||||
origin = Ogre::Vector3(733.164f,1000.0f, 839.432f);
|
||||
velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
viewangles = Ogre::Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
delta_angles[0] = delta_angles[1] = delta_angles[2] = 0;
|
||||
|
||||
lastframe_origin.x = lastframe_origin.y = lastframe_origin.z = 0;
|
||||
lerp_multiplier.x = lerp_multiplier.y = lerp_multiplier.z = 0;
|
||||
}
|
||||
|
||||
inline void SpeedUp(void)
|
||||
{
|
||||
printf("speed up to: %f\n", speed);
|
||||
speed *= 1.25f;
|
||||
}
|
||||
|
||||
inline void SpeedDown(void)
|
||||
{
|
||||
printf("speed down to %f\n", speed);
|
||||
speed /= 1.25f;
|
||||
}
|
||||
|
||||
Ogre::Vector3 velocity;
|
||||
Ogre::Vector3 origin;
|
||||
float gravity; // default = 800
|
||||
float speed; // default = 320
|
||||
|
||||
int commandTime; // the time at which this command was issued (in milliseconds)
|
||||
|
||||
int pm_time;
|
||||
|
||||
Ogre::Vector3 viewangles;
|
||||
|
||||
int groundEntityNum;
|
||||
|
||||
int pmove_framecount;
|
||||
|
||||
int watertype;
|
||||
waterlevel_t waterlevel;
|
||||
|
||||
signed short delta_angles[3];
|
||||
|
||||
pmtype_t move_type;
|
||||
|
||||
float last_compute_time;
|
||||
Ogre::Vector3 lastframe_origin;
|
||||
Ogre::Vector3 lerp_multiplier;
|
||||
} ps;
|
||||
|
||||
struct playercmd
|
||||
{
|
||||
enum CMDstateChange
|
||||
{
|
||||
NO_CHANGE,
|
||||
KEYDOWN,
|
||||
KEYUP
|
||||
};
|
||||
|
||||
playercmd() : forwardmove(0), rightmove(0), upmove(0), serverTime(50), ducking(false),
|
||||
activating(false), lastActivatingState(false), procActivating(NO_CHANGE),
|
||||
dropping(false), lastDroppingState(false), procDropping(NO_CHANGE)
|
||||
{
|
||||
angles[0] = angles[1] = angles[2] = 0;
|
||||
}
|
||||
|
||||
int serverTime;
|
||||
|
||||
short angles[3];
|
||||
|
||||
signed char forwardmove;
|
||||
signed char rightmove;
|
||||
signed char upmove;
|
||||
|
||||
bool ducking;
|
||||
bool activating; // if the user is holding down the activate button
|
||||
bool dropping; // if the user is dropping an item
|
||||
|
||||
bool lastActivatingState;
|
||||
bool lastDroppingState;
|
||||
|
||||
CMDstateChange procActivating;
|
||||
CMDstateChange procDropping;
|
||||
} cmd;
|
||||
|
||||
playerMove() : msec(50), pmove_fixed(false), pmove_msec(50), waterHeight(0), isInterior(true), hasWater(false)
|
||||
{
|
||||
}
|
||||
|
||||
int msec;
|
||||
int pmove_msec;
|
||||
bool pmove_fixed;
|
||||
int waterHeight;
|
||||
bool hasWater;
|
||||
bool isInterior;
|
||||
//Object* traceObj;
|
||||
OEngine::Physic::PhysicEngine* mEngine;
|
||||
};
|
||||
|
||||
void Pmove (playerMove* const pmove);
|
||||
void Ext_UpdateViewAngles(playerMove* const pm);
|
||||
void AngleVectors( const Ogre::Vector3& angles, Ogre::Vector3* const forward, Ogre::Vector3* const right, Ogre::Vector3* const up) ;
|
||||
#endif
|
@ -1,188 +0,0 @@
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, const float rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass) //Traceobj was a Aedra Object
|
||||
{
|
||||
|
||||
//if (!traceobj)
|
||||
// return;
|
||||
|
||||
//if (!traceobj->incellptr)
|
||||
// return;
|
||||
|
||||
const Ogre::Vector3 rayDir = end - start;
|
||||
|
||||
// Nudge starting point backwards
|
||||
//const Position3D nudgestart = start + (rayDir * -0.1f); // by 10% (isn't that too much?)
|
||||
//const Position3D nudgestart = start;
|
||||
|
||||
NewPhysTraceResults out;
|
||||
//std::cout << "Starting trace\n";
|
||||
Ogre::Vector3 startReplace = Ogre::Vector3(650,950, 45);
|
||||
Ogre::Vector3 endReplace = startReplace;
|
||||
endReplace.y -= .25;
|
||||
|
||||
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, rotation, 0.0f), isInterior, enginePass);
|
||||
if(hasHit)
|
||||
std::cout << "Has hit\n";
|
||||
if (out.fraction < 0.001f)
|
||||
results->startsolid = true;
|
||||
else
|
||||
results->startsolid = false;
|
||||
|
||||
|
||||
//results->allsolid = out.startSolid;
|
||||
|
||||
// If outside and underground, we're solid
|
||||
/*if (isInterior)
|
||||
{
|
||||
const Ogre::Vector3 height = GetGroundPosition(start, CellCoords(traceCell->data->gridX, traceCell->data->gridY) );
|
||||
if (start.yPos - height.yPos < (-2.0f * BBHalfExtents.yPos) )
|
||||
{
|
||||
results->allsolid = true;
|
||||
}
|
||||
else
|
||||
results->allsolid = false;
|
||||
}*/
|
||||
|
||||
// If inside and out of the tree, we're solid
|
||||
//else
|
||||
//{
|
||||
results->allsolid = out.startSolid;
|
||||
//std::cout << "allsolid" << results->allsolid << "\n";
|
||||
//}
|
||||
|
||||
if (!hasHit)
|
||||
{
|
||||
results->endpos = end;
|
||||
results->planenormal = Ogre::Vector3(0.0f, 1.0f, 0.0f);
|
||||
results->entityNum = ENTITYNUM_NONE;
|
||||
results->fraction = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
results->fraction = out.fraction;
|
||||
results->planenormal = out.hitNormal;
|
||||
results->endpos = rayDir * results->fraction + start;
|
||||
results->entityNum = ENTITYNUM_WORLD;
|
||||
/*bprintf("Start: (%f, %f, %f) End: (%f, %f, %f) TraceDir: (%f, %f, %f) HitNormal: (%f, %f, %f) Fraction: %f Hitpos: (%f, %f, %f) CompensatedHitpos: (%f, %f, %f)\n",
|
||||
start.xPos, start.yPos, start.zPos,
|
||||
end.xPos, end.yPos, end.zPos,
|
||||
rayDir.xPos, rayDir.yPos, rayDir.zPos,
|
||||
results->planenormal.xPos, results->planenormal.yPos, results->planenormal.zPos, results->fraction,
|
||||
out.endPos.xPos, out.endPos.yPos, out.endPos.zPos,
|
||||
results->endpos.xPos, results->endpos.yPos, results->endpos.zPos);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <const traceWorldType traceType>
|
||||
const bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end,
|
||||
const Ogre::Vector3& BBHalfExtents, const Ogre::Vector3& rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass)
|
||||
{
|
||||
//if (!traceobj->incellptr)
|
||||
// return false;
|
||||
//if(enginePass->dynamicsWorld->getCollisionObjectArray().at(60)->getCollisionShape()->isConvex())
|
||||
// std::cout << "It's convex\n";
|
||||
|
||||
|
||||
|
||||
const btVector3 btstart(start.x, start.y, start.z);
|
||||
const btVector3 btend(end.x, end.y, end.z);
|
||||
const btQuaternion btrot(rotation.y, rotation.x, rotation.z);
|
||||
|
||||
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||
const btTransform from(btrot, btstart);
|
||||
const btTransform to(btrot, btend);
|
||||
float x = from.getOrigin().getX();
|
||||
float y = from.getOrigin().getY();
|
||||
float z = from.getOrigin().getZ();
|
||||
float x2 = to.getOrigin().getX();
|
||||
float y2 = to.getOrigin().getY();
|
||||
float z2 = to.getOrigin().getZ();
|
||||
|
||||
std::cout << "BtFrom: " << x << "," << y << "," << z << "\n";
|
||||
std::cout << "BtTo: " << x2 << "," << y2 << "," << z2 << "\n";
|
||||
//std::cout << "BtTo: " << to.getOrigin().getX() << "," << to.getOrigin().getY() << "," << to.getOrigin().getZ() << "\n";
|
||||
|
||||
|
||||
btCollisionWorld::ClosestConvexResultCallback
|
||||
newTraceCallback(btstart, btend);
|
||||
|
||||
newTraceCallback.m_collisionFilterMask = (traceType == collisionWorldTrace) ? Only_Collision : Only_Pickup;
|
||||
|
||||
|
||||
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
||||
//newTraceCallback.
|
||||
|
||||
|
||||
//std::cout << "NUM: " << enginePass->dynamicsWorld->getNumCollisionObjects() << "\n";
|
||||
|
||||
// Copy the hit data over to our trace results struct:
|
||||
out->fraction = newTraceCallback.m_closestHitFraction;
|
||||
|
||||
Ogre::Vector3& outhitnormal = out->hitNormal;
|
||||
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||
|
||||
outhitnormal.x = tracehitnormal.x();
|
||||
outhitnormal.y = tracehitnormal.y();
|
||||
outhitnormal.z = tracehitnormal.z();
|
||||
|
||||
Ogre::Vector3& outhitpos = out->endPos;
|
||||
const btVector3& tracehitpos = newTraceCallback.m_hitPointWorld;
|
||||
|
||||
outhitpos.x = tracehitpos.x();
|
||||
outhitpos.y = tracehitpos.y();
|
||||
outhitpos.z= tracehitpos.z();
|
||||
|
||||
// StartSolid test:
|
||||
{
|
||||
out->startSolid = false;
|
||||
//btCollisionObject collision;
|
||||
//collision.setCollisionShape(const_cast<btBoxShape* const>(&newshape) );
|
||||
|
||||
//CustomContactCallback crb;
|
||||
|
||||
//world.world->contactTest(&collision, crb);
|
||||
//out->startSolid = crb.hit;
|
||||
|
||||
// If outside and underground, we're solid
|
||||
if (!isInterior) //Check if we are interior
|
||||
{
|
||||
}
|
||||
|
||||
// If inside and out of the tree, we're solid
|
||||
else
|
||||
{
|
||||
btVector3 aabbMin, aabbMax;
|
||||
enginePass->broadphase->getBroadphaseAabb(aabbMin, aabbMax);
|
||||
//std::cout << "AABBMIN" << aabbMin.getX() <<"," <<aabbMin.getY() << "," << aabbMin.getZ() << "\n";
|
||||
//std::cout << "AABBMAX" << aabbMax.getX() <<"," <<aabbMax.getY() << "," << aabbMax.getZ() << "\n";
|
||||
//std::cout << "AABBMAX" << aabbMax << "\n";
|
||||
if (!TestPointAgainstAabb2(aabbMin, aabbMax, *(const btVector3* const)&(start) ) )
|
||||
{
|
||||
//We're solid
|
||||
out->startSolid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bool hasHit = newTraceCallback.hasHit();
|
||||
|
||||
if(hasHit)
|
||||
std::cout << "HIT\n";
|
||||
|
||||
|
||||
return hasHit;
|
||||
}
|
Loading…
Reference in New Issue