Initial Commit
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
#include "Common.h"
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
// Rev-engineered from https://github.com/blitz-research/blitz3d/blob/master/compiler/declnode.cpp
|
||||
#define BBVARTYPE_GLOBAL 0
|
||||
#define BBVARTYPE_INT 1
|
||||
#define BBVARTYPE_FLOAT 2
|
||||
#define BBVARTYPE_UNUSED 3
|
||||
#define BBVARTYPE_STRING 4
|
||||
#define BBVARTYPE_TYPE 5
|
||||
#define BBVARTYPE_ARRAY 6
|
||||
|
||||
struct BBVar {
|
||||
int Type = -1;
|
||||
};
|
||||
|
||||
struct BBVarGlobal {
|
||||
int GlobalType = -1;
|
||||
int* Value;
|
||||
};
|
||||
|
||||
struct BBVarInt : BBVar {
|
||||
int Value;
|
||||
};
|
||||
|
||||
struct BBVarFloat : BBVar {
|
||||
float Value;
|
||||
};
|
||||
|
||||
struct BBVarUnused : BBVar {
|
||||
// Not a Dim, as you can see here:
|
||||
// https://github.com/blitz-research/blitz3d/blob/master/compiler/stmtnode.cpp#L86
|
||||
};
|
||||
|
||||
struct BBVarString : BBVar {
|
||||
int Length;
|
||||
char* Value;
|
||||
};
|
||||
|
||||
struct BBVarElement;
|
||||
struct BBVarType : BBVar {
|
||||
BBVarElement used, free;
|
||||
int fieldCount; // Field Info follows (Exactly <fieldCount> int pointers to variable struct)
|
||||
int* fields[];
|
||||
};
|
||||
|
||||
struct BBVarElement {
|
||||
int* currentPtr; // Points towards fields.
|
||||
int* nextPtr, prevPtr;
|
||||
BBVarType* BBStructPtr;
|
||||
int refCount; // Fields usually follow here, may be at another location, see currentPtr.
|
||||
//BBVar* fields[];
|
||||
};
|
||||
|
||||
struct BBVarArray : BBVar {
|
||||
int Size; //???
|
||||
BBVar* ArrayType;
|
||||
};
|
||||
|
||||
std::string BBVar_Serialize(void* obj) {
|
||||
std::stringstream myStream;
|
||||
|
||||
BBVar* var = (BBVar*)obj;
|
||||
switch (var->Type) {
|
||||
case BBVARTYPE_GLOBAL:
|
||||
BBVarGlobal* varGlobal = (BBVarGlobal*)obj;
|
||||
myStream << "[Global] " << BBVar_Serialize(varGlobal->Value) << std::endl;
|
||||
break;
|
||||
case BBVARTYPE_INT:
|
||||
BBVarInt* varInt = (BBVarInt*)obj;
|
||||
myStream << "Int" << std::endl;
|
||||
break;
|
||||
case BBVARTYPE_FLOAT:
|
||||
BBVarFloat* varFloat = (BBVarFloat*)obj;
|
||||
myStream << "Float" << std::endl;
|
||||
break;
|
||||
case BBVARTYPE_UNUSED:
|
||||
BBVarUnused* varUnused = (BBVarUnused*)obj;
|
||||
myStream << "Unused" << std::endl;
|
||||
break;
|
||||
case BBVARTYPE_STRING:
|
||||
BBVarString* varString = (BBVarString*)obj;
|
||||
myStream << "String" << std::endl;
|
||||
break;
|
||||
case BBVARTYPE_TYPE:
|
||||
BBVarType* varType = (BBVarType*)obj;
|
||||
myStream << BBVarType_Serialize(varType);
|
||||
break;
|
||||
case BBVARTYPE_ARRAY:
|
||||
BBVarArray* varArray = (BBVarArray*)obj;
|
||||
myStream << "Array = " << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
return myStream.str();
|
||||
}
|
||||
|
||||
std::string BBVarType_Serialize(BBVarType* obj, unsigned int indent = 0) {
|
||||
std::stringstream myStream;
|
||||
|
||||
std::stringstream myPaddingSS;
|
||||
for (unsigned int pad = 0; pad < indent; pad++) {
|
||||
myPaddingSS << " ";
|
||||
}
|
||||
std::string myPadding = myPaddingSS.str();
|
||||
|
||||
myStream << myPadding << "Type {" << std::endl;
|
||||
for (unsigned int fld = 0; fld < obj->fieldCount; fld++) {
|
||||
myStream << myPadding << " (" << fld << ") => " << BBVar_Serialize(obj->fields[fld]) << std::endl;
|
||||
}
|
||||
myStream << myPadding << "}" << std::endl;
|
||||
|
||||
return myStream.str();
|
||||
}
|
||||
|
||||
DLL_EXPORT(char*) SerializeObject(void* obj) {
|
||||
return strdup(BBVar_Serialize(obj).c_str());
|
||||
}
|
||||
|
||||
// Laut Mark Sibly:
|
||||
struct BBType {
|
||||
int obj_size;
|
||||
BBObj usedList, freeList;
|
||||
};
|
||||
|
||||
struct BBObj {
|
||||
BBObj *curr;
|
||||
BBObj *next, *prev;
|
||||
int* bbtype;
|
||||
int ref_cnt;
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "Matrix3.h"
|
||||
|
||||
|
||||
void Matrix3::set(Matrix3 &M)
|
||||
{
|
||||
if (this != &M) {
|
||||
this->X.set(M.X);
|
||||
this->Y.set(M.Y);
|
||||
this->Z.set(M.Z);
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix3::set(Vector3 &X, Vector3 &Y, Vector3 &Z)
|
||||
{
|
||||
this->X.set(X);
|
||||
this->Y.set(Y);
|
||||
this->Z.set(Z);
|
||||
}
|
||||
|
||||
void Matrix3::set(float &XX, float &XY, float &XZ, float &YX, float &YY, float &YZ, float &ZX, float &ZY, float &ZZ)
|
||||
{
|
||||
this->X.set(XX, XY, XZ);
|
||||
this->Y.set(YX, YY, YZ);
|
||||
this->Z.set(ZX, ZY, ZZ);
|
||||
}
|
||||
|
||||
void Matrix3::rotate(float &pitch, float &yaw, float &roll)
|
||||
{
|
||||
this->X.mul(cos(yaw) * cos(roll), -sin(roll), sin(yaw));
|
||||
this->Y.mul(sin(roll), cos(pitch) * cos(roll), -sin(pitch));
|
||||
this->Z.mul(-sin(yaw), sin(pitch), cos(pitch) * cos(yaw));
|
||||
}
|
||||
|
||||
void Matrix3::angles(float &pitch, float &yaw, float &roll)
|
||||
{
|
||||
// ToDo
|
||||
}
|
||||
|
||||
void Matrix3::transpose()
|
||||
{
|
||||
Matrix3 temp;
|
||||
|
||||
temp.set(*this);
|
||||
this->X.set(temp.X.X, temp.Y.X, temp.Z.X);
|
||||
this->Y.set(temp.X.Y, temp.Y.Y, temp.Z.Y);
|
||||
this->Z.set(temp.X.Z, temp.Y.Z, temp.Z.Z);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include "dllmain.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
struct Matrix3 {
|
||||
Vector3 X, Y, Z;
|
||||
|
||||
void set(Matrix3 &M);
|
||||
void set(Vector3 &X, Vector3 &Y, Vector3 &Z);
|
||||
void set(float &XX, float &XY, float &XZ, float &YX, float &YY, float &YZ, float &ZX, float &ZY, float &ZZ);
|
||||
|
||||
void rotate(float &pitch, float &yaw, float &roll);
|
||||
void angles(float &pitch, float &yaw, float &roll);
|
||||
|
||||
void transpose();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
#pragma once
|
||||
#include "Vector2.h"
|
||||
|
||||
void Vector2::set(const float &o)
|
||||
{
|
||||
this->X = o;
|
||||
this->Y = o;
|
||||
}
|
||||
void Vector2::set(const float &x, const float &y)
|
||||
{
|
||||
this->X = x;
|
||||
this->Y = y;
|
||||
}
|
||||
void Vector2::set(const Vector2 &o)
|
||||
{
|
||||
if (this != &o) {
|
||||
this->X = o.X;
|
||||
this->Y = o.Y;
|
||||
}
|
||||
}
|
||||
|
||||
void Vector2::add(const float &o)
|
||||
{
|
||||
this->X += o;
|
||||
this->Y += o;
|
||||
}
|
||||
void Vector2::add(const float &x, const float &y)
|
||||
{
|
||||
this->X += x;
|
||||
this->Y += y;
|
||||
}
|
||||
void Vector2::add(const Vector2 &o)
|
||||
{
|
||||
this->X += o.X;
|
||||
this->Y += o.Y;
|
||||
}
|
||||
|
||||
void Vector2::sub(const float &o)
|
||||
{
|
||||
this->X -= o;
|
||||
this->Y -= o;
|
||||
}
|
||||
void Vector2::sub(const float &x, const float &y)
|
||||
{
|
||||
this->X -= x;
|
||||
this->Y -= y;
|
||||
}
|
||||
void Vector2::sub(const Vector2 &o)
|
||||
{
|
||||
this->X -= o.X;
|
||||
this->Y -= o.Y;
|
||||
}
|
||||
|
||||
void Vector2::mul(const float &o)
|
||||
{
|
||||
this->X *= o;
|
||||
this->Y *= o;
|
||||
}
|
||||
void Vector2::mul(const float &x, const float &y)
|
||||
{
|
||||
this->X *= x;
|
||||
this->Y *= y;
|
||||
}
|
||||
void Vector2::mul(const Vector2 &o)
|
||||
{
|
||||
this->X *= o.X;
|
||||
this->Y *= o.Y;
|
||||
}
|
||||
|
||||
void Vector2::div(const float &o)
|
||||
{
|
||||
this->X /= o;
|
||||
this->Y /= o;
|
||||
}
|
||||
void Vector2::div(const float &x, const float &y)
|
||||
{
|
||||
this->X /= x;
|
||||
this->Y /= y;
|
||||
}
|
||||
void Vector2::div(const Vector2 &o)
|
||||
{
|
||||
this->X /= o.X;
|
||||
this->Y /= o.Y;
|
||||
}
|
||||
|
||||
float Vector2::length()
|
||||
{
|
||||
return (float)sqrt((this->X * this->X) + (this->Y * this->Y));
|
||||
}
|
||||
float Vector2::distance(const float &x, const float &y)
|
||||
{
|
||||
float X = this->X - x;
|
||||
float Y = this->Y - y;
|
||||
return (float)sqrt((X * X) + (Y * Y));
|
||||
}
|
||||
float Vector2::distance(const Vector2 &o)
|
||||
{
|
||||
float X = this->X - o.X;
|
||||
float Y = this->Y - o.Y;
|
||||
return (float)sqrt((X * X) + (Y * Y));
|
||||
}
|
||||
|
||||
float Vector2::dot(const float &x, const float &y)
|
||||
{
|
||||
return (this->X * x) + (this->Y * y);
|
||||
}
|
||||
float Vector2::dot(const Vector2 &o)
|
||||
{
|
||||
return (this->X * o.X) + (this->Y * o.Y);
|
||||
}
|
||||
void Vector2::normalize()
|
||||
{
|
||||
this->div(this->length());
|
||||
}
|
||||
|
||||
void Vector2::rotate(const float rotation)
|
||||
{
|
||||
float mX = cos(rotation);
|
||||
float mY = sin(rotation);
|
||||
|
||||
float X = this->X * mX + this->Y * mY; this->X = X;
|
||||
float Y = this->X * mY + this->X * mX; this->Y = Y;
|
||||
}
|
||||
void Vector2::rotateAround(const float &x, const float &y, const float &rotation)
|
||||
{
|
||||
this->sub(x, y);
|
||||
this->rotate(rotation);
|
||||
this->add(x, y);
|
||||
}
|
||||
void Vector2::rotateAround(const Vector2 &o, const float &rotation)
|
||||
{
|
||||
this->sub(o);
|
||||
this->rotate(rotation);
|
||||
this->add(o);
|
||||
}
|
||||
|
||||
float Vector2::deltaRotation() {
|
||||
return (float)(atan2(this->Y, this->X) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector2::deltaRotation(const float &x, const float &y)
|
||||
{
|
||||
return (float)(atan2(this->Y - y, this->X - x) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector2::deltaRotation(const Vector2 &o)
|
||||
{
|
||||
return (float)(atan2(this->Y - o.Y, this->X - o.X) * (180.0 / M_PI));
|
||||
}
|
||||
|
||||
char* Vector2::serialize()
|
||||
{
|
||||
char* data = new char[9];
|
||||
|
||||
memcpy(data, this->Xc, 4);
|
||||
memcpy(data + 4, this->Yc, 4);
|
||||
data[8] = 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
void Vector2::deserialize(char* o)
|
||||
{
|
||||
memcpy(o, this->Xc, 4);
|
||||
memcpy(o + 4, this->Yc, 4);
|
||||
}
|
||||
|
||||
/* ------------------------- Exported Functionality ------------------------- */
|
||||
DLL_EXPORT void Vector2_Set(Vector2* a, float o) {
|
||||
a->set(o);
|
||||
}
|
||||
DLL_EXPORT void Vector2_SetP(Vector2* a, float x, float y) {
|
||||
a->set(x, y);
|
||||
}
|
||||
DLL_EXPORT void Vector2_SetV(Vector2* a, Vector2* b) {
|
||||
a->set(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector2_Add(Vector2* a, float o) {
|
||||
a->add(o);
|
||||
}
|
||||
DLL_EXPORT void Vector2_AddP(Vector2* a, float x, float y) {
|
||||
a->add(x, y);
|
||||
}
|
||||
DLL_EXPORT void Vector2_AddV(Vector2* a, Vector2* b) {
|
||||
a->add(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector2_Sub(Vector2* a, float o) {
|
||||
a->sub(o);
|
||||
}
|
||||
DLL_EXPORT void Vector2_SubP(Vector2* a, float x, float y) {
|
||||
a->sub(x, y);
|
||||
}
|
||||
DLL_EXPORT void Vector2_SubV(Vector2* a, Vector2* b) {
|
||||
a->sub(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector2_Mul(Vector2* a, float o) {
|
||||
a->mul(o);
|
||||
}
|
||||
DLL_EXPORT void Vector2_MulP(Vector2* a, float x, float y) {
|
||||
a->mul(x, y);
|
||||
}
|
||||
DLL_EXPORT void Vector2_MulV(Vector2* a, Vector2* b) {
|
||||
a->mul(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector2_Div(Vector2* a, float o) {
|
||||
a->div(o);
|
||||
}
|
||||
DLL_EXPORT void Vector2_DivP(Vector2* a, float x, float y) {
|
||||
a->div(x, y);
|
||||
}
|
||||
DLL_EXPORT void Vector2_DivV(Vector2* a, Vector2* b) {
|
||||
a->div(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector2_Length(Vector2* a) {
|
||||
return (float)a->length();
|
||||
}
|
||||
DLL_EXPORT float Vector2_DistanceP(Vector2* a, float x, float y) {
|
||||
return (float)a->distance(x, y);
|
||||
}
|
||||
DLL_EXPORT float Vector2_DistanceV(Vector2* a, Vector2* b) {
|
||||
return (float)a->distance(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector2_DotP(Vector2* a, float x, float y) {
|
||||
return (float)a->dot(x, y);
|
||||
}
|
||||
DLL_EXPORT float Vector2_DotV(Vector2* a, Vector2* b) {
|
||||
return (float)a->dot(*b);
|
||||
}
|
||||
DLL_EXPORT void Vector2_Normalize(Vector2* a) {
|
||||
a->normalize();
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector2_Rotate(Vector2* a, float rotation) {
|
||||
a->rotate(rotation);
|
||||
}
|
||||
DLL_EXPORT void Vector2_RotateAroundP(Vector2* a, float x, float y, float rotation) {
|
||||
a->rotateAround(x, y, rotation);
|
||||
}
|
||||
DLL_EXPORT void Vector2_RotateAroundV(Vector2* a, Vector2* b, float rotation) {
|
||||
a->rotateAround(*b, rotation);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector2_DeltaRotation(Vector2* a) {
|
||||
return (float)a->deltaRotation();
|
||||
}
|
||||
DLL_EXPORT float Vector2_DeltaRotationP(Vector2* a, float x, float y) {
|
||||
return (float)a->deltaRotation(x, y);
|
||||
}
|
||||
DLL_EXPORT float Vector2_DeltaRotationV(Vector2* a, Vector2* b) {
|
||||
return (float)a->deltaRotation(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT char* Vector2_Serialize(Vector2* a) {
|
||||
return a->serialize();
|
||||
}
|
||||
DLL_EXPORT void Vector2_Deserialize(Vector2* a, char* o) {
|
||||
a->deserialize(o);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
#include "dllmain.h"
|
||||
#ifndef _USE_MATH_DEFINES
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#undef _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
struct Vector2 {
|
||||
union {
|
||||
float X;
|
||||
char Xc[4];
|
||||
};
|
||||
union {
|
||||
float Y;
|
||||
char Yc[4];
|
||||
};
|
||||
|
||||
void set(const float &o);
|
||||
void set(const float &x, const float &y);
|
||||
void set(const Vector2 &o);
|
||||
|
||||
void add(const float &o);
|
||||
void add(const float &x, const float &y);
|
||||
void add(const Vector2 &o);
|
||||
|
||||
void sub(const float &o);
|
||||
void sub(const float &x, const float &y);
|
||||
void sub(const Vector2 &o);
|
||||
|
||||
void mul(const float &o);
|
||||
void mul(const float &x, const float &y);
|
||||
void mul(const Vector2 &o);
|
||||
|
||||
void div(const float &o);
|
||||
void div(const float &x, const float &y);
|
||||
void div(const Vector2 &o);
|
||||
|
||||
float length();
|
||||
float distance(const float &x, const float &y);
|
||||
float distance(const Vector2 &o);
|
||||
|
||||
float dot(const float &x, const float &y);
|
||||
float dot(const Vector2 &o);
|
||||
void normalize();
|
||||
|
||||
void rotate(const float rotation);
|
||||
void rotateAround(const float &x, const float &y, const float &rotation);
|
||||
void rotateAround(const Vector2 &o, const float &rotation);
|
||||
float deltaRotation();
|
||||
float deltaRotation(const float &x, const float &y);
|
||||
float deltaRotation(const Vector2 &o);
|
||||
|
||||
char* serialize();
|
||||
void deserialize(char* o);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
#pragma once
|
||||
#include "Vector3.h"
|
||||
|
||||
void Vector3::set(const float &o)
|
||||
{
|
||||
this->X = o;
|
||||
this->Y = o;
|
||||
this->Z = o;
|
||||
}
|
||||
void Vector3::set(const float &x, const float &y, const float &z)
|
||||
{
|
||||
this->X = x;
|
||||
this->Y = y;
|
||||
this->Z = z;
|
||||
}
|
||||
void Vector3::set(const Vector3 &o)
|
||||
{
|
||||
if (this != &o) {
|
||||
this->X = o.X;
|
||||
this->Y = o.Y;
|
||||
this->Z = o.Z;
|
||||
}
|
||||
}
|
||||
|
||||
void Vector3::add(const float &o)
|
||||
{
|
||||
this->X += o;
|
||||
this->Y += o;
|
||||
this->Z += o;
|
||||
}
|
||||
void Vector3::add(const float &x, const float &y, const float &z)
|
||||
{
|
||||
this->X += x;
|
||||
this->Y += y;
|
||||
this->Z += z;
|
||||
}
|
||||
void Vector3::add(const Vector3 &o)
|
||||
{
|
||||
this->X += o.X;
|
||||
this->Y += o.Y;
|
||||
this->Z += o.Z;
|
||||
}
|
||||
|
||||
void Vector3::sub(const float &o)
|
||||
{
|
||||
this->X -= o;
|
||||
this->Y -= o;
|
||||
this->Z -= o;
|
||||
}
|
||||
void Vector3::sub(const float &x, const float &y, const float &z)
|
||||
{
|
||||
this->X -= x;
|
||||
this->Y -= y;
|
||||
this->Z -= z;
|
||||
}
|
||||
void Vector3::sub(const Vector3 &o)
|
||||
{
|
||||
this->X -= o.X;
|
||||
this->Y -= o.Y;
|
||||
this->Z -= o.Z;
|
||||
}
|
||||
|
||||
void Vector3::mul(const float &o)
|
||||
{
|
||||
this->X *= o;
|
||||
this->Y *= o;
|
||||
this->Z *= o;
|
||||
}
|
||||
void Vector3::mul(const float &x, const float &y, const float &z)
|
||||
{
|
||||
this->X *= x;
|
||||
this->Y *= y;
|
||||
this->Z *= z;
|
||||
}
|
||||
void Vector3::mul(const Vector3 &o)
|
||||
{
|
||||
this->X *= o.X;
|
||||
this->Y *= o.Y;
|
||||
this->Z *= o.Z;
|
||||
}
|
||||
|
||||
void Vector3::div(const float &o)
|
||||
{
|
||||
this->X /= o;
|
||||
this->Y /= o;
|
||||
this->Z /= o;
|
||||
}
|
||||
void Vector3::div(const float &x, const float &y, const float &z)
|
||||
{
|
||||
this->X /= x;
|
||||
this->Y /= y;
|
||||
this->Z /= z;
|
||||
}
|
||||
void Vector3::div(const Vector3 &o)
|
||||
{
|
||||
this->X /= o.X;
|
||||
this->Y /= o.Y;
|
||||
this->Z /= o.Z;
|
||||
}
|
||||
|
||||
float Vector3::length()
|
||||
{
|
||||
return sqrt(this->X * this->X + this->Y * this->Y + this->Z * this->Z);
|
||||
}
|
||||
float Vector3::distance(const float &x, const float &y, const float &z)
|
||||
{
|
||||
float X = (this->X - x);
|
||||
float Y = (this->Y - y);
|
||||
float Z = (this->Z - z);
|
||||
return sqrt(X * X + Y * Y + Z * Z);
|
||||
}
|
||||
float Vector3::distance(const Vector3 &o)
|
||||
{
|
||||
float X = (this->X - o.X);
|
||||
float Y = (this->Y - o.Y);
|
||||
float Z = (this->Z - o.Z);
|
||||
return sqrt(X * X + Y * Y + Z * Z);
|
||||
}
|
||||
|
||||
float Vector3::dot(const float &x, const float &y, const float &z)
|
||||
{
|
||||
return (this->X * x) + (this->Y * y) + (this->Z * z);
|
||||
}
|
||||
float Vector3::dot(const Vector3 &o)
|
||||
{
|
||||
return (this->X * o.X) + (this->Y * o.Y) + (this->Z * o.Z);
|
||||
}
|
||||
Vector3 Vector3::cross(const float &x, const float &y, const float &z)
|
||||
{
|
||||
Vector3* data = new Vector3();
|
||||
data->X = (this->Y * z) - (this->Z * y);
|
||||
data->Y = (this->Z * x) - (this->X * z);
|
||||
data->Z = (this->X * y) - (this->Y * x);
|
||||
return *data;
|
||||
}
|
||||
Vector3 Vector3::cross(const Vector3 &o)
|
||||
{
|
||||
Vector3* data = new Vector3();
|
||||
data->X = (this->Y * o.Z) - (this->Z * o.Y);
|
||||
data->Y = (this->Z * o.X) - (this->X * o.Z);
|
||||
data->Z = (this->X * o.Y) - (this->Y * o.X);
|
||||
return *data;
|
||||
}
|
||||
void Vector3::normalize()
|
||||
{
|
||||
this->div(this->length());
|
||||
}
|
||||
|
||||
void Vector3::rotate(float &pitch, float &yaw, float &roll)
|
||||
{
|
||||
float** matrix = new float*[3];
|
||||
matrix[0] = new float[3]; matrix[1] = new float[3]; matrix[2] = new float[3];
|
||||
matrix[0][0] = cos(yaw) * cos(roll); matrix[0][1] = -sin(roll); matrix[0][2] = sin(yaw);
|
||||
matrix[1][0] = sin(roll); matrix[1][1] = cos(pitch) * cos(roll); matrix[1][2] = -sin(pitch);
|
||||
matrix[2][0] = -sin(yaw); matrix[2][1] = sin(pitch); matrix[2][2] = cos(pitch) * cos(yaw);
|
||||
|
||||
float X = (this->X * matrix[0][0]) + (this->Y * matrix[0][1]) + (this->Z * matrix[0][2]);
|
||||
float Y = (this->X * matrix[1][0]) + (this->Y * matrix[1][1]) + (this->Z * matrix[1][2]);
|
||||
float Z = (this->X * matrix[2][0]) + (this->Y * matrix[2][1]) + (this->Z * matrix[2][2]);
|
||||
this->X = X; this->Y = Y; this->Z = Z;
|
||||
}
|
||||
void Vector3::rotateAround(const float &x, const float &y, const float &z, float &pitch, float &yaw, float &roll)
|
||||
{
|
||||
this->sub(x, y, z);
|
||||
this->rotate(pitch, yaw, roll);
|
||||
this->add(x, y, z);
|
||||
}
|
||||
void Vector3::rotateAround(Vector3 &o, float &pitch, float &yaw, float &roll)
|
||||
{
|
||||
this->sub(o);
|
||||
this->rotate(pitch, yaw, roll);
|
||||
this->add(o);
|
||||
}
|
||||
float Vector3::deltaPitch() {
|
||||
return (float)(atan(this->X / -this->Y) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector3::deltaPitch(const float &x, const float &y, const float &z)
|
||||
{
|
||||
return (float)(atan((this->X - x) / (-(this->Y - y))) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector3::deltaPitch(Vector3 &o)
|
||||
{
|
||||
return (float)(atan((this->X - o.X) / (-(this->Y - o.Y))) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector3::deltaYaw() {
|
||||
return (float)(atan(sqrt((this->X * this->X) + (this->Y * this->Y)) / this->Z) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector3::deltaYaw(const float &x, const float &y, const float &z)
|
||||
{
|
||||
float X = (this->X - x);
|
||||
float Y = (this->Y - y);
|
||||
return (float)(atan(sqrt((X * X) + (Y * Y)) / (this->Z - z)) * (180.0 / M_PI));
|
||||
}
|
||||
float Vector3::deltaYaw(Vector3 &o)
|
||||
{
|
||||
float X = (this->X - o.X);
|
||||
float Y = (this->Y - o.Y);
|
||||
return (float)(atan(sqrt((X * X) + (Y * Y)) / (this->Z - o.Z)) * (180.0 / M_PI));
|
||||
}
|
||||
|
||||
char* Vector3::serialize()
|
||||
{
|
||||
char* data = new char[13];
|
||||
|
||||
memcpy(data, this->Xc, 4);
|
||||
memcpy(data + 4, this->Yc, 4);
|
||||
memcpy(data + 8, this->Zc, 4);
|
||||
data[12] = 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
void Vector3::deserialize(char* o)
|
||||
{
|
||||
memcpy(o, this->Xc, 4);
|
||||
memcpy(o + 4, this->Yc, 4);
|
||||
memcpy(o + 8, this->Zc, 4);
|
||||
}
|
||||
|
||||
/* ------------------------- Exported Functionality ------------------------- */
|
||||
DLL_EXPORT void Vector3_Set(Vector3* a, float o) {
|
||||
a->set(o);
|
||||
}
|
||||
DLL_EXPORT void Vector3_SetP(Vector3* a, float x, float y, float z) {
|
||||
a->set(x, y, z);
|
||||
}
|
||||
DLL_EXPORT void Vector3_SetV(Vector3* a, Vector3* b) {
|
||||
a->set(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector3_Add(Vector3* a, float o) {
|
||||
a->add(o);
|
||||
}
|
||||
DLL_EXPORT void Vector3_AddP(Vector3* a, float x, float y, float z) {
|
||||
a->add(x, y, z);
|
||||
}
|
||||
DLL_EXPORT void Vector3_AddV(Vector3* a, Vector3* b) {
|
||||
a->add(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector3_Sub(Vector3* a, float o) {
|
||||
a->sub(o);
|
||||
}
|
||||
DLL_EXPORT void Vector3_SubP(Vector3* a, float x, float y, float z) {
|
||||
a->sub(x, y, z);
|
||||
}
|
||||
DLL_EXPORT void Vector3_SubV(Vector3* a, Vector3* b) {
|
||||
a->sub(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector3_Mul(Vector3* a, float o) {
|
||||
a->mul(o);
|
||||
}
|
||||
DLL_EXPORT void Vector3_MulP(Vector3* a, float x, float y, float z) {
|
||||
a->mul(x, y, z);
|
||||
}
|
||||
DLL_EXPORT void Vector3_MulV(Vector3* a, Vector3* b) {
|
||||
a->mul(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector3_Div(Vector3* a, float o) {
|
||||
a->div(o);
|
||||
}
|
||||
DLL_EXPORT void Vector3_DivP(Vector3* a, float x, float y, float z) {
|
||||
a->div(x, y, z);
|
||||
}
|
||||
DLL_EXPORT void Vector3_DivV(Vector3* a, Vector3* b) {
|
||||
a->div(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector3_Length(Vector3* a) {
|
||||
return (float)a->length();
|
||||
}
|
||||
DLL_EXPORT float Vector3_DistanceP(Vector3* a, float x, float y, float z) {
|
||||
return (float)a->distance(x, y, z);
|
||||
}
|
||||
DLL_EXPORT float Vector3_DistanceV(Vector3* a, Vector3* b) {
|
||||
return (float)a->distance(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector3_DotP(Vector3* a, float x, float y, float z) {
|
||||
return (float)a->dot(x, y, z);
|
||||
}
|
||||
DLL_EXPORT float Vector3_DotV(Vector3* a, Vector3* b) {
|
||||
return (float)a->dot(*b);
|
||||
}
|
||||
DLL_EXPORT void Vector3_CrossP(Vector3* a, float x, float y, float z, Vector3* out) {
|
||||
Vector3 temp = a->cross(x, y, z);
|
||||
*out = temp;
|
||||
}
|
||||
DLL_EXPORT void Vector3_CrossV(Vector3* a, Vector3* b, Vector3* out) {
|
||||
Vector3 temp = a->cross(*b);
|
||||
*out = temp;
|
||||
}
|
||||
DLL_EXPORT void Vector3_Normalize(Vector3* a) {
|
||||
a->normalize();
|
||||
}
|
||||
|
||||
DLL_EXPORT void Vector3_Rotate(Vector3* a, float pitch, float yaw, float roll) {
|
||||
a->rotate(pitch, yaw, roll);
|
||||
}
|
||||
DLL_EXPORT void Vector3_RotateAroundP(Vector3* a, float x, float y, float z, float pitch, float yaw, float roll) {
|
||||
a->rotateAround(x, y, z, pitch, yaw, roll);
|
||||
}
|
||||
DLL_EXPORT void Vector3_RotateAroundV(Vector3* a, Vector3* b, float pitch, float yaw, float roll) {
|
||||
a->rotateAround(*b, pitch, yaw, roll);
|
||||
}
|
||||
|
||||
DLL_EXPORT float Vector3_DeltaPitchP(Vector3* a, float x, float y, float z) {
|
||||
return (float)a->deltaPitch(x, y, z);
|
||||
}
|
||||
DLL_EXPORT float Vector3_DeltaPitchV(Vector3* a, Vector3* b) {
|
||||
return (float)a->deltaPitch(*b);
|
||||
}
|
||||
DLL_EXPORT float Vector3_DeltaYawP(Vector3* a, float x, float y, float z) {
|
||||
return (float)a->deltaYaw(x, y, z);
|
||||
}
|
||||
DLL_EXPORT float Vector3_DeltaYawV(Vector3* a, Vector3* b) {
|
||||
return (float)a->deltaYaw(*b);
|
||||
}
|
||||
|
||||
DLL_EXPORT char* Vector3_Serialize(Vector3* a) {
|
||||
return a->serialize();
|
||||
}
|
||||
DLL_EXPORT void Vector3_Deserialize(Vector3* a, char* s) {
|
||||
a->deserialize(s);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
#include "dllmain.h"
|
||||
#ifndef _USE_MATH_DEFINES
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#undef _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
struct Vector3 {
|
||||
union {
|
||||
float X;
|
||||
char Xc[4];
|
||||
};
|
||||
union {
|
||||
float Y;
|
||||
char Yc[4];
|
||||
};
|
||||
union {
|
||||
float Z;
|
||||
char Zc[4];
|
||||
};
|
||||
|
||||
void set(const float &o);
|
||||
void set(const float &x, const float &y, const float &z);
|
||||
void set(const Vector3 &o);
|
||||
|
||||
void add(const float &o);
|
||||
void add(const float &x, const float &y, const float &z);
|
||||
void add(const Vector3 &o);
|
||||
|
||||
void sub(const float &o);
|
||||
void sub(const float &x, const float &y, const float &z);
|
||||
void sub(const Vector3 &o);
|
||||
|
||||
void mul(const float &o);
|
||||
void mul(const float &x, const float &y, const float &z);
|
||||
void mul(const Vector3 &o);
|
||||
|
||||
void div(const float &o);
|
||||
void div(const float &x, const float &y, const float &z);
|
||||
void div(const Vector3 &o);
|
||||
|
||||
float length();
|
||||
float distance(const float &x, const float &y, const float &z);
|
||||
float distance(const Vector3 &o);
|
||||
|
||||
float dot(const float &x, const float &y, const float &z);
|
||||
float dot(const Vector3 &o);
|
||||
Vector3 cross(const float &x, const float &y, const float &z);
|
||||
Vector3 cross(const Vector3 &o);
|
||||
void normalize();
|
||||
|
||||
void rotate(float &pitch, float &yaw, float &roll);
|
||||
void rotateAround(const float &x, const float &y, const float &z, float &pitch, float &yaw, float &roll);
|
||||
void rotateAround(Vector3 &o, float &pitch, float &yaw, float &roll);
|
||||
float deltaPitch();
|
||||
float deltaPitch(const float &x, const float &y, const float &z);
|
||||
float deltaPitch(Vector3 &o);
|
||||
float deltaYaw();
|
||||
float deltaYaw(const float &x, const float &y, const float &z);
|
||||
float deltaYaw(Vector3 &o);
|
||||
|
||||
char* serialize();
|
||||
void deserialize(char* o);
|
||||
};
|
||||
Reference in New Issue
Block a user