所以现在在c ++我有第一人称相机,控件还可以,相机移动正常。但我唯一的问题是相机的速度不是预期的,让我解释一下:
(3D场景)
10个对象 - >相机速度很快
1000对象 - >慢速相机速度
所以基本上我所做的就是多次与时间这样:
Newpos + = Speed * DeltaTime;
但是当我的程序有负载时,相机速度会下降很多!那么这里发生了什么,我做错了什么?
时间码(结果似乎很好,它们在几秒钟内):
double DeltaTime::milliseconds_now()
{
static LARGE_INTEGER s_frequency;
static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency);
if (s_use_qpc) {
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
return (1000LL * now.QuadPart) / s_frequency.QuadPart;
} else {
return GetTickCount();
}
}
void DeltaTime::OnStart()
{
//ticks = (float)GetTickCount();
QueryPerformanceFrequency( &m_liPerformanceFrequency);
}
float DeltaTime::GetDelta()
{
return ((float)dTime/(float)1000000.0f);
}
void DeltaTime::OnFinish()
{
if (timeFirst)
{
//ticks = 0;
dTime = 0;
timeFirst = false;
return;
}
//ticks = ((float)ticks = (float)GetTickCount() - (float)ticks);
QueryPerformanceCounter( &liPerformanceCount);
dTime = double(liPerformanceCount.QuadPart)/double(m_liPerformanceFrequency.QuadPart);
}
帧:
void OnFrame(...)
{
...
timeHandler.OnFinish();
timeHandler.OnStart();
...
}
谢谢
答案 0 :(得分:0)
不知何故,我两次调用on start函数,但现在无论如何系统都被修改了。