Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifdef DVSENGINE_EXPORTS
- #define DVSENGINE_API __declspec(dllexport)
- #else
- #define DVSENGINE_API __declspec(dllimport)
- #pragma comment(lib,"DVSEngine.lib")
- #endif
- #define _USE_MATH_DEFINES
- #define _CRT_SECURE_NO_WARNINGS
- #define _CRT_NON_CONFORMING_WCSTOK
- #define _CRT_NON_CONFORMING_SWPRINTFS
- #pragma comment(lib,"winmm.lib")
- #pragma comment(lib,"ftgl_dynamic_MT.lib")
- #pragma comment(lib,"DevIL.lib")
- #pragma comment(lib,"ILUT.lib")
- #pragma comment(lib,"ILU.lib")
- #pragma comment(lib,"freetype.lib")
- #pragma comment(lib,"Shlwapi.lib")
- #include <windows.h>
- #include <gl/freeglut.h>
- #include <cmath>
- #include <cwchar>
- #include <string>
- #include <vector>
- #include <map>
- #include <memory>
- #include <Shlwapi.h>
- #include <io.h>
- #include <il/ilu.h>
- #include <ftgl/FTFont.h>
- #include <ftgl/FTGLBitmapFont.h>
- #include <ftgl/FTGLOutlineFont.h>
- using namespace std;
- typedef unsigned char byte;
- #define V4toxyzw(t) t.x, t.y, t.z, t.w
- #define V4toxyz(t) t.x, t.y, t.z
- #define V4toxy(t) t.x, t.y
- #define max3(a,b,c) (max(a,max(b,c)))
- #define min3(a,b,c) (min(a,min(b,c)))
- #define FONT_DIR "Resources/Fonts/%s"
- #define MODEL_DIR "Resources/Models/%s"
- #define RESOURCE_DIR "Resources"
- #define DIV_TYPE_AABB 0
- #define DIV_TYPE_SPHERE 1
- namespace DVSEngine {
- class V3 {
- public:
- DVSENGINE_API V3() { x = y = z = 0.0f; }
- DVSENGINE_API V3(float X, float Y) { x = X; y = Y; }
- DVSENGINE_API V3(float X, float Y, float Z) { x = X; y = Y; z = Z; }
- float x, y, z;
- };
- class V4 {
- public:
- DVSENGINE_API V4();
- DVSENGINE_API V4(float X, float Y);
- DVSENGINE_API V4(int X, int Y);
- DVSENGINE_API V4(float X, float Y, float Z);
- DVSENGINE_API V4(int X, int Y, int Z);
- DVSENGINE_API V4(float X, float Y, float Z, float W);
- DVSENGINE_API V4(const V3 &v);
- DVSENGINE_API V4(const V4 &v);
- DVSENGINE_API V4(const POINT &v);
- DVSENGINE_API operator V3();
- DVSENGINE_API operator float*();
- DVSENGINE_API void operator=(V4 v); // ������������� �������� =
- DVSENGINE_API V4 operator-();
- DVSENGINE_API V4 operator-(V4 v); // ������������� �������� -
- DVSENGINE_API V4 operator+(V4 v); // ������������� �������� +
- DVSENGINE_API V4 operator*(V4 v); // ������������� �������� *
- DVSENGINE_API V4 operator/(V4 v); // ������������� �������� /
- DVSENGINE_API V4 operator+(float f); // ������������� �������� +
- DVSENGINE_API V4 operator-(float f); // ������������� �������� -
- DVSENGINE_API V4 operator*(float f); // ������������� �������� *
- DVSENGINE_API V4 operator/(float f); // ������������� �������� /
- DVSENGINE_API void operator +=(V4 v); // ������������� �������� +=
- DVSENGINE_API void operator -=(V4 v); // ������������� �������� -=
- DVSENGINE_API void operator *=(V4 v); // ������������� �������� *=
- DVSENGINE_API void operator /=(V4 v); // ������������� �������� /=
- DVSENGINE_API void operator +=(float f); // ������������� �������� +=
- DVSENGINE_API void operator -=(float f); // ������������� �������� -=
- DVSENGINE_API void operator *=(float f); // ������������� �������� *=
- DVSENGINE_API void operator /=(float f); // ������������� �������� /=
- DVSENGINE_API bool operator ==(V4 v); // ������������� �������� ==
- DVSENGINE_API bool operator !=(V4 v); // ������������� �������� !=
- DVSENGINE_API V4 Cross(V4 v1, V4 v2); // ���������� Cross Product �������� v1 � v2.
- DVSENGINE_API V4 Cross(V4 v1, V4 v2, V4 v3); // ���������� Cross Product �������� v1, v2, V4.
- DVSENGINE_API float DotProduct3(V4 v1); // ��������� ������������ 3 �� v1
- DVSENGINE_API float DotProduct4(V4 v1); // ��������� ������������ 4 �� v1
- DVSENGINE_API float GetLength(); // ���������� ������ ������� �������
- DVSENGINE_API V4 Normal(); // ����������� ������
- DVSENGINE_API void Normalize(V4 Triangle[]); // ������� ������� ������������
- DVSENGINE_API V4 GetRotatedX(float angle);
- DVSENGINE_API V4 GetRotatedY(float angle);
- DVSENGINE_API V4 GetRotatedZ(float angle);
- DVSENGINE_API V4 GetRotatedAxis(float angle, V4 axis);
- DVSENGINE_API void maxXYZ(V4 v);
- DVSENGINE_API void minXYZ(V4 v);
- DVSENGINE_API void set(float f);
- float x, y, z, w;
- };
- struct SPHERE {
- V4 position;
- float radius;
- };
- struct BOX {
- V4 minV, maxV;
- };
- struct RAY {
- V4 begin, end;
- };
- struct PLANE {
- V4 p1, p2, p3, normal;
- };
- struct Div {
- operator SPHERE() {
- return SPHERE{ { V4toxyz(v1) }, v1.w };
- }
- operator BOX() {
- return BOX{ { V4toxyz(v1) },{ V4toxyz(v2) } };
- }
- operator RAY() {
- return RAY{ { V4toxyz(v1) },{ V4toxyz(v2) } };
- }
- V4 v1, v2;
- };
- struct PolygonS {
- V4 p1, p2, p3;
- V4 normal;
- char *texture;
- V4 tp1, tp2, tp3;
- };
- struct DebugS {
- bool showModel = true;
- bool showDiv = false;
- bool showNormal = false;
- bool noclip = false;
- bool fly = false;
- };
- enum FrustumSide {
- RIGHT = 0, // ������ ������� ��������
- LEFT = 1, // ����� ������� ��������
- BOTTOM = 2, // ������ ������� ��������
- TOP = 3, // ������� ������� ��������
- BACK = 4, // ������ ������� ��������
- FRONT = 5 // ��������
- };
- class Quaternion {
- public:
- DVSENGINE_API Quaternion();
- DVSENGINE_API Quaternion(V4 v);
- DVSENGINE_API Quaternion(V4 v, float degrees, bool is_radian = true);
- DVSENGINE_API void Quaternion::CreateFromAxisAngle(V4 v, float degrees);
- DVSENGINE_API void Quaternion::CreateFromAxisRadian(V4 v, float angle);
- DVSENGINE_API Quaternion *Quaternion::mul(Quaternion*);
- DVSENGINE_API Quaternion *Quaternion::sum(Quaternion*);
- DVSENGINE_API Quaternion *Quaternion::Inverse();
- DVSENGINE_API float Quaternion::QMagnitude();
- DVSENGINE_API Quaternion rotate(Quaternion q);
- DVSENGINE_API Quaternion rotate(V4 q);
- static DVSENGINE_API Quaternion rotate(Quaternion *q, Quaternion *p);
- static DVSENGINE_API Quaternion rotate(V4 qv, Quaternion *p);
- static DVSENGINE_API Quaternion rotate(Quaternion *q, V4 v, float a, bool i = true);
- static DVSENGINE_API Quaternion rotate(V4 qv, V4 pv, float a, bool i = true);
- DVSENGINE_API operator V4();
- V4 v;
- };
- class Frustum {
- public:
- DVSENGINE_API void CalculateFrustum();
- DVSENGINE_API bool PointInFrustum(V4 p);
- DVSENGINE_API bool SphereInFrustum(V4 p, float radius);
- DVSENGINE_API bool CubeInFrustum(V4 p, float size);
- private:
- V4 m_Frustum[6];
- };
- class CFont {
- public:
- DVSENGINE_API CFont(char *ttf, int FSize, float FDepth);
- FTGLBitmapFont *Font;
- DVSENGINE_API void Print(V4 p, V4 c, wstring text);
- DVSENGINE_API void Printf(V4 p, V4 c, wstring fmt, ...);
- };
- class Console {
- public:
- DVSENGINE_API Console();
- DVSENGINE_API void toggle();
- DVSENGINE_API void draw();
- DVSENGINE_API void print(wstring s);
- DVSENGINE_API void println(wstring string);
- DVSENGINE_API void parseln(wstring string);
- DVSENGINE_API Console operator << (wstring string);
- bool is_open = false;
- wstring stack[10];
- bool newLine = false;
- std::map <wstring, void(*)()> funcs;
- vector<wstring> param;
- };
- class Camera {
- public:
- DVSENGINE_API Camera();
- DVSENGINE_API void Look();
- DVSENGINE_API void FirstPersonView(int mx, int my);
- DVSENGINE_API void ThirdPersonView();
- DVSENGINE_API void setPosition(V4 position);
- DVSENGINE_API void setViewTo(V4 viewTo);
- DVSENGINE_API void lockView();
- DVSENGINE_API void unlockView();
- V4 Position, LookPos;
- V4 View;
- V4 Up;
- V4 Strafe;
- bool locked, needMouseZoom;
- float Sensitivity;
- float Zoom, ZoomLimit;
- };
- #ifndef DVSENGINE_UNUSE_MODEL
- class Model {
- public:
- struct ModelPart {
- char name[40];
- unsigned int listId;
- vector<PolygonS> polygons;
- unsigned short divType;
- Div div;
- bool is_static;
- };
- DVSENGINE_API Model(char *modelfile, V4 color = V4{ 1.0f,1.0f,1.0f });
- DVSENGINE_API void loadModel(char *modelfile);
- DVSENGINE_API void calculateDiv();
- DVSENGINE_API void drawPart(ModelPart *mpart);
- DVSENGINE_API void buildPart(ModelPart *mpart);
- DVSENGINE_API void drawModel(V4 position);
- unsigned short divType;
- Div div;
- vector<ModelPart> parts;
- V4 color;
- };
- #endif
- #ifndef DVSENGINE_UNUSE_OBJECT
- class Object {
- public:
- DVSENGINE_API Object(float _mass, V4 _pos, char *modelfile);
- DVSENGINE_API void setPreTickFunc(void f());
- DVSENGINE_API void setPreDrawFunc(void f());
- DVSENGINE_API void tick(float dt);
- DVSENGINE_API void tick();
- DVSENGINE_API void draw();
- DVSENGINE_API void applyVelocity(V4 _velocity);
- DVSENGINE_API void applyForce(V4 _force);
- DVSENGINE_API void applyGravity();
- DVSENGINE_API void applyFriction();
- void(*preTick)(), (*preDraw)();
- bool is_static;
- #ifndef DVSENGINE_UNUSE_OBJECT
- Model *model;
- #endif
- float mass;
- V4 moving;
- V4 position;
- V4 velocity;
- V4 force;
- };
- #endif
- #ifndef DVSENGINE_UNUSE_PHYSICS
- class Physics {
- public:
- DVSENGINE_API Physics();
- DVSENGINE_API Physics(float g);
- DVSENGINE_API bool getIntersection(Object o1, Object o2);
- float g;
- };
- #endif
- #pragma region ����������
- #pragma region ������ �������������� �������
- DVSENGINE_API short sign(int a);
- // ���� ��������� ����� �������
- DVSENGINE_API float Distance(V4 vPoint1, V4 vPoint2);
- // ���� ��������� �� ����� �� ���������
- DVSENGINE_API float PlaneDistance(V4 Normal, V4 Point);
- // ���� ��������� ����� �� �����
- DVSENGINE_API V4 ClosestPointOnLine(V4 vA, V4 vB, V4 vPoint);
- // ���� ��������� ����� �� ���������
- DVSENGINE_API V4 ClosestPointOnPlane(PolygonS p, V4 vPoint);
- // ��������� ���� ����� ���������
- DVSENGINE_API float AngleBetweenVectors(V4 Vector1, V4 Vector2);
- // ���������� ������ ����� ����� � ������ �������
- DVSENGINE_API V4 getBezierPoint(vector<V4> pts, float t);
- #pragma endregion
- #pragma region ������� ��� ��������
- // ����������, ����� �� ����� ������ ������������
- DVSENGINE_API bool InsidePolygon(V4 vIntersection, PLANE poly);
- // ����������, ���������� �� ����� ��������� � ����������
- DVSENGINE_API bool ClassifySphere(SPHERE Sph, PLANE poly, float &distance);
- // ����������, ���������� �� ����� ��������� � ����������
- DVSENGINE_API bool ClassifyPoint(V4 TestV, PLANE poly, float &distance);
- DVSENGINE_API float SquaredDistPointAABB(V4 pointV, BOX aabb);
- // ����������, ���������� �� ����� �����-���� ����� ������������
- DVSENGINE_API bool LineSphereCollision(V4 linep1, V4 linep2, SPHERE Sph);
- // ����������, ���������� �� ����� �����-���� ����� ������������
- DVSENGINE_API bool EdgeSphereCollision(SPHERE Sph, PLANE Pla);
- // ���������� ����� �� ����� � AABB
- DVSENGINE_API bool PointInAABB(V4 PointV, BOX tBox);
- #pragma endregion
- #pragma endregion
- #pragma region �����
- char **CommandLineToArgvA(PCHAR CmdLine, int* _argc);
- wchar_t keyboardRuToEng(wchar_t c);
- DVSENGINE_API void split(wstring &s, const wchar_t* delim, vector<wstring> & v);
- DVSENGINE_API wstring format(wstring fmt_str, ...);
- #pragma endregion
- #pragma region �������
- DVSENGINE_API void to2D();
- DVSENGINE_API void backTo3D();
- DVSENGINE_API void CalculateFrameRate();
- DVSENGINE_API void draw2DTexturedSquare(V4 p1, V4 p2, V4 c, V4 tp1 = V4(), V4 tp2 = V4());
- DVSENGINE_API GLuint LoadTexture(string dir, string F);
- DVSENGINE_API GLuint LoadTexture(string F);
- #pragma endregion
- #pragma region ������
- DVSENGINE_API void exitA();
- DVSENGINE_API void toggle();
- DVSENGINE_API void setFPS();
- #pragma endregion
- #pragma region MAIN
- class MAIN;
- class MAINDestructor {
- private:
- MAIN *p_instance;
- public:
- ~MAINDestructor();
- DVSENGINE_API void initialize(MAIN* p);
- };
- class MAIN {
- private:
- static MAIN* p_instance;
- static MAINDestructor destroyer;
- protected:
- ~MAIN() {}
- friend class MAINDestructor;
- friend void IdleF();
- friend void IdleF(int v) { IdleF(); }
- friend void DisplayF();
- friend void DisplayF(int v) { glutPostRedisplay(); }
- friend void ReshapeF(int width, int height);
- friend void MouseF(int button, int state, int x, int y);
- friend void ActionMouseF(int x, int y);
- friend void PassiveMouseF(int x, int y);
- friend void KeyPressF(byte ch, int x, int y);
- friend void KeyReleaseF(byte ch, int x, int y);
- friend void KeySpecPressF(int ch, int x, int y);
- friend void KeySpecReleaseF(int ch, int x, int y);
- public:
- static DVSENGINE_API MAIN *getInstance();
- DVSENGINE_API void setWindow(int *argcp, char **argv);
- DVSENGINE_API char **setWindow(char *exeName, LPSTR cmdLine, int *argc);
- DVSENGINE_API void createWindow(char *title, V4 bounds);
- DVSENGINE_API void setDIFunc(void _I(), void _D3d(), void _D2d()) { I = _I, D3d = _D3d, D2d = _D2d; }
- DVSENGINE_API void setMFuncs(void _M(int button, int state, int x, int y), void _Ma(int x, int y), void _Mp(int x, int y)) { M = _M, Ma = _Ma, Mp = _Mp; }
- DVSENGINE_API void setKFuncs(void _Kp(byte ch, int x, int y), void _Kr(byte ch, int x, int y)) { Kp = _Kp, Kr = _Kr; }
- DVSENGINE_API void setKsFuncs(void _Ksp(int ch, int x, int y), void _Ksr(int ch, int x, int y)) { Ksp = _Ksp, Ksr = _Ksr; }
- DVSENGINE_API void Init(void In());
- DVSENGINE_API void Start();
- #pragma region ���. �������
- DVSENGINE_API void pointerToCenter(bool visibleCursor);
- DVSENGINE_API void setMaxFPS(int maxFPS);
- #pragma endregion
- #pragma region GLUT �������
- void(*I)(), (*D3d)(), (*D2d)();
- void(*M)(int, int, int, int), (*Ma)(int, int), (*Mp)(int, int);
- void(*Kp)(byte, int, int), (*Kr)(byte, int, int);
- void(*Ksp)(int, int, int), (*Ksr)(int, int, int);
- #pragma endregion
- int Width, Height;
- int FPS, FPSlimit, ThoudevFps;
- float dT;
- POINT mouse;
- bool Pause;
- wstring tmpStr;
- CFont *arial_16;
- float time;
- bool kbd[256];
- bool is_alt = false;
- bool is_ctrl = false;
- bool is_shift = false;
- DebugS debug;
- Console cout;
- Camera *camera;
- map<string, GLuint> textures;
- #ifndef DVSENGINE_UNUSE_PHYSICS
- Physics *physics;
- #endif
- #ifndef DVSENGINE_UNUSE_OBJECT
- vector<Object *> objs;
- #endif
- };
- #pragma endregion
- extern MAIN *MC;
- };
- #ifndef DVSENGINE_EXPORTS
- using namespace DVSEngine;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement