Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************TIMER.H******************************/
- #pragma once
- class Timer
- {
- public:
- bool WaitMilliSeconds(unsigned long int seconds) //Now THIS is how you do a fucking timer
- {
- static unsigned long secondsPassed;
- static unsigned long startTime = GetTickCount();
- static bool initTime = false;
- static bool timePassed = false;
- if (!initTime)
- {
- startTime = GetTickCount();
- initTime = true;
- }
- secondsPassed = (GetTickCount() - startTime);
- if (secondsPassed > seconds) {
- secondsPassed = 0;
- startTime = GetTickCount();
- timePassed = true;
- initTime = false;
- return true;
- }
- else
- return false;
- }
- };
- /*******************END OF TIMER.H**********************************/
- /*******************MapObjects.h************************************/
- #pragma once
- #include <d3d11.h>
- #include <DirectXMath.h>
- #include <SimpleMath.h>
- using namespace DirectX;
- class Object
- {
- public:
- int iIndex = 0;
- int Type = 0; //3D Mesh type to be drawn
- Object();
- //Create an Object at X, Y, and Z coordinates
- Object(float x, float y, float z, int type);
- void Rotate(float x, int axis); //0 = x, 1 = y, 2 = z
- void RotateOnTimer(float x, float y, float z, float time);
- void Scale(float x, float y, float z);
- void Translate(float x, float y, float z);
- void Update();
- DirectX::SimpleMath::Matrix GetMatrix();
- protected:
- float rot = 0.00f;
- DirectX::SimpleMath::Matrix m_World;
- DirectX::SimpleMath::Matrix m_Proj;
- DirectX::SimpleMath::Matrix m_View;
- DirectX::SimpleMath::Matrix m_Scale;
- DirectX::SimpleMath::Matrix m_Translate;
- DirectX::SimpleMath::Matrix m_Rotate;
- DirectX::SimpleMath::Vector3 m_vMeshPosition;
- DirectX::SimpleMath::Vector3 m_vMeshAt;
- DirectX::SimpleMath::Vector3 m_vMeshUp;
- };
- /******************************END OF MAPOBJECTS.H*******************************/
- /*****************************MAPOBJECTS.CPP************************************/
- #include "MapObjects.h"
- #include "Timers.h"
- #include "Globals.h"
- #define _CRT_SECURE_NO_WARNINGS
- #define _CRT_SECURE_NO_DEPRECATE
- #pragma warning( disable : 4005)
- #pragma warning( disable : 4996)
- using namespace DirectX;
- std::vector <Timer> ObjectTimers(NUM_OF_OBJECTS);
- Object::Object()
- {
- m_vMeshPosition = { 0.0f, 0.0f, 0.0f };
- m_vMeshAt = { 1.0f, 0.0f, 0.0f };
- m_vMeshUp = { 0.0f, 1.0f, 0.0f };
- }
- //Create an Object at X, Y, and Z coordinates
- Object::Object(float x, float y, float z, int type)
- {
- Type = type;
- iIndex = g_ObjectIndex; //Set this object's unique index number to the current number of objects made prior
- g_ObjectIndex++; //Increase the total number of objects that have been created thus far
- m_vMeshPosition = { x , y , z };
- m_vMeshAt = { 0.0f, 0.0f, 0.0f }; //Eye position (Always should be 0.0fx3)
- m_vMeshUp = { 0.0f, 1.0f, 0.0f };
- m_World = XMMatrixIdentity(); //Set Matrix Identity
- m_View = XMMatrixLookAtLH(m_vMeshAt, m_vMeshPosition, m_vMeshUp);
- m_Proj = XMMatrixPerspectiveFovLH(0.4f*XM_PI, (float)(Width / Height), 1.0f, 100.0f);
- Translate(m_vMeshPosition.x, m_vMeshPosition.y, m_vMeshPosition.z); //Translate object to coordinates fed into constructor
- Scale(1.0f, 1.0f, 1.0f); //Scale Object to its own normal size
- Rotate(0.0f, 0); //Rotate X
- Rotate(0.0f, 1); //Rotate Y
- Rotate(0.0f, 2); //Rotate Z
- m_World = m_Scale * m_Rotate * m_Translate;
- }
- void Object::Rotate(float x, int axis) //0 = x, 1 = y, 2 = z
- {
- if (axis == 0)
- m_Rotate = XMMatrixRotationX(x);
- else if (axis == 1)
- m_Rotate = XMMatrixRotationY(x);
- else if (axis == 2)
- m_Rotate = XMMatrixRotationZ(x);
- }
- void Object::RotateOnTimer(float x, float y, float z, float time)
- {
- char temp[100];
- sprintf(temp, "iIndex: %d...", iIndex);
- if (x)
- Rotate(x + rot, 0);
- if (y)
- Rotate(y + rot, 1);
- if (z)
- Rotate(z + rot, 2);
- if(iIndex == 0)
- if (ObjectTimers[iIndex].WaitMilliSeconds((unsigned long)time))
- {
- //Error("penis");
- rot += 0.005f;
- sprintf(temp, "iIndex: %d ROTATING", iIndex);
- Console(temp);
- }
- if (iIndex == 1)
- if (ObjectTimers[iIndex].WaitMilliSeconds((unsigned long)time))
- {
- //Error("penis");
- rot += 0.005f;
- sprintf(temp, "iIndex: %d ROTATING", iIndex);
- Console(temp);
- }
- /*else if(iIndex == 1)
- if (ObjectTimers[1].WaitMilliSeconds((unsigned long)time))
- {
- Console("Attempting to rotate [1]");
- rot += 0.005f;
- }*/
- }
- void Object::Scale(float x, float y, float z)
- {
- m_Scale = XMMatrixScaling(x, y, z);
- }
- void Object::Translate(float x, float y, float z)
- {
- m_Translate = XMMatrixTranslation(x, y, z);
- }
- void Object::Update()
- {
- m_World = m_Scale * m_Rotate * m_Translate; //Scale, Rotate, THEN Translate after rotation, not before, otherwise object will not conform to proper coords
- }
- DirectX::SimpleMath::Matrix Object::GetMatrix()
- {
- return m_World;
- }
- /*****************************************END OF MAPOBJECTS.CPP****************/
- Why does on ObjectTimers[0] return true, but anything above 0 returns false? i.e, if I do (if !ObjectTimers[1].WaitMilliseconds(..), the object WILL rotate).
Add Comment
Please, Sign In to add comment