Time类
#ifndef Time_H
#define Time_H
#include "Window.h"
class Time
{
private:
static float _deltaTime;
static float _startTime;
static float _curTime;
friend void Window::SetDeltaTime(float time);
friend void Window::SetCurTime(float time);
friend void Window::SetStartTime(float time);
public:
static float GetDeltaTime();
static float GetCurTime();
static float GetStartTimee();
};
#endif
-------------------------
#include "Time.h"
float Time::_deltaTime = 0.0f;
float Time::_curTime = 0.0f;
float Time::_startTime = 0.0f;
float Time::GetDeltaTime()
{
return _deltaTime;
}
float Time::GetCurTime()
{
return _curTime;
}
float Time::GetStartTimee()
{
return _startTime;
}
在Windows中修改
void Window::Mainloop()
{
float starTime = glfwGetTime();
float currentFrame, lastFrame = starTime;
SetStartTime(starTime);
while (!glfwWindowShouldClose(Window::window_ptr))
{
currentFrame = glfwGetTime();
SetCurTime(currentFrame);
float deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
SetDeltaTime(deltaTime);
Input();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.05f, 0.05f, 0.05f, 1.0f);
glfwSwapBuffers(window_ptr);
glfwPollEvents();
}
}
void Window::SetDeltaTime(float time)
{
Time::_deltaTime = time;
}
void Window::SetStartTime(float time)
{
Time::_startTime = time;
}
void Window::SetCurTime(float time)
{
Time::_curTime = time;
}
|