First commit in mathtesting

Added code for matrices, sceneobjects, and physics.
This commit is contained in:
Calvin Balke 2015-01-20 12:54:23 -08:00
parent 52c2756e5c
commit 3a55528fb5
19 changed files with 278 additions and 18 deletions

View file

@ -20,7 +20,7 @@
<ClCompile Include="source\DXAPI\NetConnection.cpp" />
<ClCompile Include="source\DXAPI\NetObject.cpp" />
<ClCompile Include="source\DXAPI\Player.cpp" />
<ClCompile Include="source\DXAPI\Point3F.cpp" />
<ClCompile Include="source\DXAPI\MatMath.cpp" />
<ClCompile Include="source\DXAPI\Projectile.cpp" />
<ClCompile Include="source\DXAPI\SceneObject.cpp" />
<ClCompile Include="source\DXAPI\ScriptObject.cpp" />
@ -43,7 +43,7 @@
<ClInclude Include="include\DXAPI\NetConnection.h" />
<ClInclude Include="include\DXAPI\NetObject.h" />
<ClInclude Include="include\DXAPI\Player.h" />
<ClInclude Include="include\DXAPI\Point3F.h" />
<ClInclude Include="include\DXAPI\MatMath.h" />
<ClInclude Include="include\DXAPI\Projectile.h" />
<ClInclude Include="include\DXAPI\SceneObject.h" />
<ClInclude Include="include\DXAPI\ScriptObject.h" />

View file

@ -33,9 +33,6 @@
<ClCompile Include="source\DXAPI\DXAPI.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\Point3F.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\FlyingVehicle.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
@ -87,6 +84,9 @@
<ClCompile Include="source\DXAPI\ScriptObject.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\MatMath.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\LinkerAPI.h">
@ -122,9 +122,6 @@
<ClInclude Include="include\DXAPI\NetObject.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\Point3F.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\FlyingVehicle.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
@ -146,5 +143,8 @@
<ClInclude Include="include\DXAPI\ScriptObject.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\MatMath.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -16,7 +16,7 @@
#include "LinkerAPI.h"
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/GameBase.h>
#include <DXAPI/NetObject.h>
#include <DXAPI/Player.h>

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/NetConnection.h>
#include <LinkerAPI.h>
#include <DXAPI/ShapeBase.h>

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/Projectile.h>
namespace DX

View file

@ -0,0 +1,181 @@
#pragma once
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#define M_PI 3.14159265359
inline float mDegToRad(float d)
{
return float((d * M_PI) / float(180));
}
inline float mRadToDeg(float r)
{
return float((r * 180.0) / M_PI);
}
inline double mDegToRad(double d)
{
return (d * M_PI) / double(180);
}
inline double mRadToDeg(double r)
{
return (r * 180.0) / M_PI;
}
namespace DX
{
struct Point {
float x;
float y;
float z;
};
/**
* @brief A class representing a referenced 3D vector of floats in Tribes 2.
*/
#define idx(r,c) (r*4 + c)
class MatrixF;
class Point3F
{
public:
Point3F();
Point3F(float &X, float &Y, float &Z);
float x;
float y;
float z;
};
class Angle
{
public:
Angle(float *mat){
float const *m = (float const *)mat;
float trace = m[idx(0, 0)] + m[idx(1, 1)] + m[idx(2, 2)];
if (trace > 0.0) {
float s = sqrt(trace + float(1));
w = s * 0.5;
s = 0.5 / s;
x = (m[idx(1,2)] - m[idx(2,1)]) * s;
y = (m[idx(2,0)] - m[idx(0,2)]) * s;
z = (m[idx(0,1)] - m[idx(1,0)]) * s;
} else {
float* q = &x;
unsigned int i = 0;
if (m[idx(1, 1)] > m[idx(0, 0)]) i = 1;
if (m[idx(2, 2)] > m[idx(i, i)]) i = 2;
unsigned int j = (i + 1) % 3;
unsigned int k = (j + 1) % 3;
float s = sqrt((m[idx(i, i)] - (m[idx(j, j)] + m[idx(k, k)])) + 1.0);
q[i] = s * 0.5;
s = 0.5 / s;
q[j] = (m[idx(i,j)] + m[idx(j,i)]) * s;
q[k] = (m[idx(i,k)] + m[idx(k, i)]) * s;
w = (m[idx(j,k)] - m[idx(k, j)]) * s;
angle = acos( w ) * 2;
float sinHalfAngle = sqrt(1 - w * w);
if (sinHalfAngle != 0)
{
axis.x=(x / sinHalfAngle);
axis.y=(y / sinHalfAngle);
axis.z=(z / sinHalfAngle);
}
else
{
axis.x=1.0;
axis.y=0;
axis.z=0;
}
}
}
void Angle::identity()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
w = 1.0f;
}
void Angle::normalize() {
float l = sqrt( x*x + y*y + z*z + w*w );
if( l == float(0.0) )
identity();
else
{
x /= l;
y /= l;
z /= l;
w /= l;
}
}
float angle;
Point axis;
float x,y,z,w,s;
};
class MatrixF
{
public:
MatrixF(float *inm) {
m=inm;
}
float *m;
void MatrixF::m_quatF_set_matF_C( float x, float y, float z, float w)
{
#define qidx(r,c) (r*4 + c)
float xs = x * 2.0f;
float ys = y * 2.0f;
float zs = z * 2.0f;
float wx = w * xs;
float wy = w * ys;
float wz = w * zs;
float xx = x * xs;
float xy = x * ys;
float xz = x * zs;
float yy = y * ys;
float yz = y * zs;
float zz = z * zs;
m[qidx(0,0)] = 1.0f - (yy + zz);
m[qidx(1,0)] = xy - wz;
m[qidx(2,0)] = xz + wy;
m[qidx(3,0)] = 0.0f;
m[qidx(0,1)] = xy + wz;
m[qidx(1,1)] = 1.0f - (xx + zz);
m[qidx(2,1)] = yz - wx;
m[qidx(3,1)] = 0.0f;
m[qidx(0,2)] = xz - wy;
m[qidx(1,2)] = yz + wx;
m[qidx(2,2)] = 1.0f - (xx + yy);
m[qidx(3,2)] = 0.0f;
m[qidx(0,3)] = 0.0f;
m[qidx(1,3)] = 0.0f;
m[qidx(2,3)] = 0.0f;
m[qidx(3,3)] = 1.0f;
#undef qidx
}
inline void getColumn(int col, Point3F *cptr)
{
cptr->x = m[col];
cptr->y = m[col+4];
cptr->z = m[col+8];
}
inline void setColumn(int col, Point3F *cptr)
{
m[col] = cptr->x;
m[col+4] = cptr->y;
m[col+8] = cptr->z;
}
MatrixF(Angle *ang) {
m_quatF_set_matF_C(ang->x,ang->y,ang->z,ang->w);
}
};
} // End NameSpace DX

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/SimObject.h>
#include <DXAPI/NetObject.h>
#include <LinkerAPI.h>

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/ShapeBase.h>
namespace DX

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/GameBase.h>
#include <LinkerAPI.h>

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/NetObject.h>
namespace DX
@ -12,5 +12,28 @@ namespace DX
Point3F position;
Point3F scale;
float * worldtoobj;
float * objtoworld;
Point3F objboxmin;
Point3F objboxmax;
Point3F worldboxmin;
Point3F worldboxmax;
Point3F worldspherecenter;
float &worldsphereradius;
float *renderobjtoworld;
float *renderworldtoobj;
void setTransform(float *matrixinput) {
unsigned int bpv=this->base_pointer_value;
unsigned int minp = (unsigned int) matrixinput;
__asm {
push minp
mov ecx,bpv
mov eax,bpv
mov eax,[eax]
add eax,0x74
call [eax]
}
}
};
} // End NameSpace DX

View file

@ -1,6 +1,6 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/ShapeBase.h>
namespace DX

View file

@ -13,7 +13,9 @@
#pragma once
#include <LinkerAPI.h>
void serverProcessReplacement(unsigned int timeDelta) ;
const char* conGetPosition(Linker::SimObject * obj, S32 argc, const char *argv[]);
const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]);
// Returns the address of an object in memory
const char* conGetAddress(Linker::SimObject *obj, S32 argc, const char *argv[]);

View file

@ -12,7 +12,7 @@
* @copyright (c) 2014 Robert MacGregor
*/
#include <DXAPI/Point3F.h>
#include <DXAPI/MatMath.h>
#include <DXAPI/DXAPI.h>
#include <LinkerAPI.h>

View file

@ -0,0 +1,14 @@
#include <DXAPI/MatMath.h>
namespace DX
{
Point3F::Point3F(float &X, float &Y, float &Z) : x(X), y(Y), z(Z)
{
}
Point3F::Point3F()
{
x=0;
y=0;
z=0;
}
}

View file

@ -4,6 +4,16 @@ namespace DX
{
SceneObject::SceneObject(unsigned int obj) : position(*(float*)(obj + 168), *(float*)(obj + 184), *(float*)(obj + 200)),
scale(*(float*)(obj + 284), *(float*)(obj + 288), *(float*)(obj + 292)),
worldtoobj((float*)(obj + 0xDC)),
objtoworld((float*)(obj+0x9C)),
objboxmin(*(float*)(obj + 296), *(float*)(obj + 300), *(float*)(obj + 304)),
objboxmax(*(float*)(obj + 308), *(float*)(obj + 312), *(float*)(obj + 316)),
worldboxmin(*(float*)(obj + 320), *(float*)(obj + 324), *(float*)(obj + 328)),
worldboxmax(*(float*)(obj + 332), *(float*)(obj + 336), *(float*)(obj + 340)),
worldspherecenter(*(float*)(obj + 344), *(float*)(obj + 348), *(float*)(obj + 352)),
worldsphereradius(*(float*)(obj+356)),
renderobjtoworld((float*)(obj+360)),
renderworldtoobj((float*)(obj+424)),
NetObject(obj)
{
}

View file

@ -4,9 +4,25 @@
#define endian(hex) (((hex & 0x000000FF) << 24)+((hex & 0x0000FF00) << 8)+((hex & 0x00FF0000)>>8)+((hex & 0xFF000000) >> 24))
#include <LinkerAPI.h>
#include <DXAPI/DXAPI.h>
#include <DXAPI/MatMath.h>
static float counter=0;
void serverProcessReplacement(unsigned int timeDelta) {
unsigned int servertickaddr=0x602350;
unsigned int serverthisptr=0x9E5EC0;
float basex=348.08;
float basey=-178.761;
float basez=113.037;
if (Sim::findObjectc("Team1TurretBaseLarge1")) {
basex+=counter/180.0;
DX::SceneObject sobj = DX::SceneObject((unsigned int)Sim::findObjectc("Team1TurretBaseLarge1"));
DX::MatrixF mat1=DX::MatrixF(sobj.objtoworld);
mat1.setColumn(3,&DX::Point3F(basex,basey,basez));
sobj.setTransform(mat1.m);
if (counter>=(30*180)){
counter=0;
}
counter+=1.0;
}
__asm
{
mov ecx,serverthisptr
@ -16,6 +32,20 @@ void serverProcessReplacement(unsigned int timeDelta) {
return;
}
const char* conGetPosition(Linker::SimObject * obj, S32 argc, const char *argv[]) {
char returnstr[256]="";
DX::SceneObject sobj = DX::SceneObject((unsigned int)obj);
if (obj!=NULL) {
unsigned int bpv = (sobj.base_pointer_value);
unsigned int *matrixptr =(unsigned int *) (bpv+0x9C);
float *matrix1=(float*) matrixptr;
DX::MatrixF mat1=DX::MatrixF(sobj.objtoworld);
DX::Point3F test=DX::Point3F();
mat1.getColumn(3,&test);
sprintf (returnstr,"%g %g %g",test.x,test.y,test.z);
}
return returnstr;
}
const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]) {
char test[256] = "";
char test2[256]="";

View file

@ -42,7 +42,7 @@ extern "C"
Con::addMethodS("GrenadeProjectile", "getposition", &conGrenadeProjectileGetPosition,"Accurately gets the position of the GrenadeProjectile", 2, 2);
Con::addMethodS("GrenadeProjectile", "getvelocity", &conGrenadeProjectileGetVelocity,"Gets the velocity of the GrenadeProjectile", 2, 2);
Con::addMethodB("Projectile", "makeNerf", &conProjectileMakeNerf,"Makes the Projectile deal no damage", 2, 2);
Con::addMethodS("SceneObject", "getPositionTest", &conGetPosition,"Gets the Rotation by alternate means as a test", 2, 2);
// TCPObject
#ifdef ENABLE_TCPOBJECT
Con::addMethodS("TCPObject", "connect", &conTCPObjectConnect, "Connects to a remote server", 3, 3);