View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

# Camera Interpolation

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

24 replies to this topic

### #1BlueSpud  Members

Posted 04 September 2013 - 02:15 PM

Hello,

I've been working with my own game engine for awhile now and I've been trying to get the input and controls to flow much more like a AAA FPS game, or at least a decent indie one. I've posted several topics in the past on this issue about making a smooth camera, and at the time of posting them, I had been satisfied with the results. Now however, I feel that it is not quite smooth enough, and I've switched the whole engine to SDL so I have control over the loop. (previously I was using GLUT). After changing everything to SDL, the mouse is smooth as butter, but the camera movement (walking) is still stutters and looks bad. I've implemented the last of Dwitter's game loop, the one with interpolation, and here is the relevant code:

int main (int argc,  char** argv)
{
arg1 = argc;
arg2 = argv;
engineInit();
//the loop has to stay here
//kill all extra threads so they don't cause problems after we quit
//gameloop
SDL_Event event;
bool running = true;

const int TPS = 20;
const int SKIP_TICKS = 1000 / TPS;
const int MAX_FRAMESKIP = 5;
int loops;
long lastSec = 0;
long nextGameTick = SDL_GetTicks();

while (running)
{
while (SDL_PollEvent(&event)) {
//do crap with events
switch (event.type)
{
int x,y,button;
case SDL_QUIT:
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();
cout << "The window has been closed.\n";
running = false;
break;
case SDL_MOUSEMOTION:
SDL_GetMouseState(&x, &y);
passiveMouse(x,y);
break;
case SDL_MOUSEBUTTONDOWN :
button =  SDL_GetMouseState(&x, &y);
mouseFunc(button,1,x,y);
break;
case SDL_KEYDOWN:
keyboardDownFunc(event.key.keysym.sym);
break;
case SDL_KEYUP:
keyboardUpFunc(event.key.keysym.sym);
break;
default:

break;
}

}
loops = 0;
while (SDL_GetTicks()> nextGameTick && loops < MAX_FRAMESKIP) {
nextGameTick+=SKIP_TICKS;
loops++;
TickHandler.tps++;
TickHandler.onTick();

int tickTime = int(SDL_GetTicks()/1000);
if (tickTime > lastSec+1)
{
TickHandler.tps = 0;
lastSec = tickTime;
}
}
TickHandler.interpolation = double(SDL_GetTicks() + SKIP_TICKS - nextGameTick )
/ double( SKIP_TICKS );
TickHandler.onRender();
render();
}
Console.consoleActivated = false;
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;
}



TickHandler.onRender() calls a few interpolated functions and here is the one that controls movement of the camera:

void renderTick(float intp)
{
if (cameraPlayer == true)
{
Physics.pos3 = -camy;
Physics.collisions();
Input.applyGravity();
if (Input.walking == true)
Input.moveCameraFirstPerson(1*intp);
else
{
roll = 0;
Input.change = false;
}
}

}

And here is the move camera first person:

void inputs::moveCameraFirstPerson(float speed)
{
speed = speed*walkspeed;
float radx = ((yaw+addedAngle)*MPI/180);
camx -= (sinf(radx)/10)*speed;
camz += (cosf(radx)/10)*speed;

Physics.pos1 = -camx;
Physics.pos2 = -camz;

if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*3.1415926535/180);
camx += (sinf(radx)/20)*speed;
camz -= (cosf(radx)/20)*speed;
Physics.collided = false;

}
Client.x = camx;
Client.z = camz;
Client.y = camy;

Projectile.x = camx;
Projectile.z = camz;
}



I'd love if I could get this all sorted out, any help or reference would be appreciated.

Thanks.

### #2WiredCat  Members

Posted 08 September 2013 - 11:08 AM

Why you
void inputs::moveCameraFirstPerson(float speed)
{
speed = speed*walkspeed;
you pass almost const float

at least change speed = speed*walkspeed; to float tmp; tmp = speed*walkspeed; and why you use walkspeed?]

remember that every mouse movement the game forces to draw new eye look at point so mouse movement as is is not dependant on time ( you don't use timefactor there)

to smooth camera movement you should use better timer (i use for win32 QueryPerformanceTimer), that done the trick for me

You should also separate drawing routine from mouse movements (that drawing is made independent)

you can also

make character to turn from one eyepoint to another in fixed time vaule lets say 22 ms and then blend two scenes or more

it wont be much help but you can go here http://www.sulaco.co.za/opengl_project_Basic_3D_engine.htm and downlaod source that will show you how to move mouse (with average of two frame times) almost the same as your code (OpenGLApp.dpr - winmain func) if you use queryperformancetimer there instead of average two frames from gettickcount) i could tell you more precise but i can't now.

Edited by ___, 08 September 2013 - 11:43 AM.

### #3BlueSpud  Members

Posted 08 September 2013 - 05:15 PM

Why you
void inputs::moveCameraFirstPerson(float speed)
{
speed = speed*walkspeed;
you pass almost const float

at least change speed = speed*walkspeed; to float tmp; tmp = speed*walkspeed; and why you use walkspeed?]

remember that every mouse movement the game forces to draw new eye look at point so mouse movement as is is not dependant on time ( you don't use timefactor there)

to smooth camera movement you should use better timer (i use for win32 QueryPerformanceTimer), that done the trick for me

You should also separate drawing routine from mouse movements (that drawing is made independent)

you can also

make character to turn from one eyepoint to another in fixed time vaule lets say 22 ms and then blend two scenes or more

it wont be much help but you can go here http://www.sulaco.co.za/opengl_project_Basic_3D_engine.htm and downlaod source that will show you how to move mouse (with average of two frame times) almost the same as your code (OpenGLApp.dpr - winmain func) if you use queryperformancetimer there instead of average two frames from gettickcount) i could tell you more precise but i can't now.

walkspeed is another variable for things like sprinting and crouching. The mouse movement is very smooth, it is the camera 'walking' that is jittery. The update function isn't being called faster than a millisecond, so I really don't need the precision of a performance counter.

### #4WiredCat  Members

Posted 09 September 2013 - 08:19 AM

ok my bad about this mosue movement it was about camera lol, anyway you should do better timing believe me.

another thing is that if you divide a float by in example 180 you will get integer result

ex. 3.1415926535/180 should be 3.14159265350f / 180.0f same for void inputs::moveCameraFirstPerson(float speed) you cannot pass integer to float unless you cast it to a

Input.moveCameraFirstPerson(1.0f*float(intp));

or if you have something more complex then you use (float)var

the average timer ticks can also smooth your movement but i prefer queryperformancetimer

however i do not see here time independant variable

since you move character, by telling what direction it is going, multiplying that direction by speed value and than you have to multiply it by time (ofc in seconds for SI)

### #5BlueSpud  Members

Posted 09 September 2013 - 01:03 PM

ok my bad about this mosue movement it was about camera lol, anyway you should do better timing believe me.

another thing is that if you divide a float by in example 180 you will get integer result

ex. 3.1415926535/180 should be 3.14159265350f / 180.0f same for void inputs::moveCameraFirstPerson(float speed) you cannot pass integer to float unless you cast it to a

Input.moveCameraFirstPerson(1.0f*float(intp));

or if you have something more complex then you use (float)var

the average timer ticks can also smooth your movement but i prefer queryperformancetimer

however i do not see here time independant variable

since you move character, by telling what direction it is going, multiplying that direction by speed value and than you have to multiply it by time (ofc in seconds for SI)

I didn't know that whole float thing, and I changed the code to do that. Unfortunately, query performance counter seems to fluctuate really badly. It could be a problem in my code, but I don't really think so. Speed when passed to the function is time, the independent variable.

### #6Sponji  Members

Posted 09 September 2013 - 02:19 PM

another thing is that if you divide a float by in example 180 you will get integer result

There is nothing wrong with dividing a float with an integer, it will result as a float. But dividing an integer with an integer will not give you a float, 1 / 3 = 0.

Derp

### #7WiredCat  Members

Posted 10 September 2013 - 01:39 AM

i wonder if you use it like this:

CStopWatch * timin;

timin = new CStopWatch();

timin->startTimer();

get time



double l;
timin->stopTimer();

l = timin->getElapsedTime();
FRAME_TIME = float(l);
timin->startTimer();


cpp



//---------------------------------------------------------------------------

#pragma hdrstop

#include "Timer.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

double CStopWatch::LIToSecs( LARGE_INTEGER & L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ;
}

CStopWatch::CStopWatch(){
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency ) ;
}

void CStopWatch::startTimer( ) {
QueryPerformanceCounter(&timer.start) ;
}

void CStopWatch::stopTimer( ) {
QueryPerformanceCounter(&timer.stop) ;
}

double CStopWatch::getElapsedTime() {
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) ;
}



h



//---------------------------------------------------------------------------

#ifndef TimerH
#define TimerH
#include "windows.h"
//---------------------------------------------------------------------------

typedef struct {
LARGE_INTEGER start;
LARGE_INTEGER stop;
} stopWatch;

class CStopWatch {

private:
stopWatch timer;
LARGE_INTEGER frequency;
double LIToSecs( LARGE_INTEGER & L) ;
public:
CStopWatch() ;
void startTimer( ) ;
void stopTimer( ) ;
double getElapsedTime() ;
};
#endif
//         LARGE_INTEGER liFrequency;
//		::QueryPerformanceFrequency(&liFrequency);
//		return ((double)GetElapsed() / (double)liFrequency.QuadPart);



There is nothing wrong with dividing a float with an integer, it will result as a float. But dividing an integer with an integer will not give you a float, 1 / 3 = 0.

It depends on the compiler, mine won't pass (you multiply int by float you get int)

however reply to this topic if you still have a problem, we will search for another solution

maybe you should post a video with that camera problem, i found jittering in my cam but i used better timer

Edited by ___, 10 September 2013 - 01:54 AM.

### #8Sponji  Members

Posted 10 September 2013 - 01:57 AM

It depends on the compiler, mine won't pass (you multiply int by float you get int)

And what compiler are you using, if I may ask?

Derp

### #9BlueSpud  Members

Posted 10 September 2013 - 04:47 AM

i wonder if you use it like this:

CStopWatch * timin;

timin = new CStopWatch();

timin->startTimer();

get time



double l;
timin->stopTimer();

l = timin->getElapsedTime();
FRAME_TIME = float(l);
timin->startTimer();

cpp


//---------------------------------------------------------------------------

#pragma hdrstop

#include "Timer.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

double CStopWatch::LIToSecs( LARGE_INTEGER & L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ;
}

CStopWatch::CStopWatch(){
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency ) ;
}

void CStopWatch::startTimer( ) {
QueryPerformanceCounter(&timer.start) ;
}

void CStopWatch::stopTimer( ) {
QueryPerformanceCounter(&timer.stop) ;
}

double CStopWatch::getElapsedTime() {
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) ;
}


h


//---------------------------------------------------------------------------

#ifndef TimerH
#define TimerH
#include "windows.h"
//---------------------------------------------------------------------------

typedef struct {
LARGE_INTEGER start;
LARGE_INTEGER stop;
} stopWatch;

class CStopWatch {

private:
stopWatch timer;
LARGE_INTEGER frequency;
double LIToSecs( LARGE_INTEGER & L) ;
public:
CStopWatch() ;
void startTimer( ) ;
void stopTimer( ) ;
double getElapsedTime() ;
};
#endif
//         LARGE_INTEGER liFrequency;
//		::QueryPerformanceFrequency(&liFrequency);
//		return ((double)GetElapsed() / (double)liFrequency.QuadPart);



There is nothing wrong with dividing a float with an integer, it will result as a float. But dividing an integer with an integer will not give you a float, 1 / 3 = 0.

It depends on the compiler, mine won't pass (you multiply int by float you get int)

however reply to this topic if you still have a problem, we will search for another solution

maybe you should post a video with that camera problem, i found jittering in my cam but i used better timer

Thanks for all the code, but I do want to make this cross platform, that why I chose opengl. I don't actually have a windows machine, do I've been using wine to emulate a windows compiler, but I'm not really coding on it. I don't have the time right now but later I will post a video of the camera trying different solutions.

And something for you: I didn't read through all your code but I noticed you used quey preformence frequency which I read can fluctuate on the CPU.

### #10WiredCat  Members

Posted 10 September 2013 - 09:59 AM

i use RAD STUDIO 2007,

if its only for win and linux you can use queryperf if not i don't know.

i can only say to you that you are doing all wrong

like:

while (SDL_GetTicks()> nextGameTick && loops < MAX_FRAMESKIP) { - that means you skipframes but do not count time properly

TickHandler.interpolation = double(SDL_GetTicks() + SKIP_TICKS - nextGameTick ) - whats the purpose of this anyway.

if you get time between frames you should count every frame even skipped frame. Really its hard for me to explain, i bet your camera is jumping from one point to another

because when you skip in example 5 frames and the time will be 5 seconds then you will jump to unknown destination.

, or it just doesn't process frames that are processed faster than 1 milisecond)

anyway i can't help you unless you show more code and a video of your camera movement

### #11BlueSpud  Members

Posted 10 September 2013 - 02:06 PM

I have a repository that can be found here:

- removed

This does not include all the shaders and model files that I'm loading in, but that shouldn't be a problem. Don't make fun of me, I know a lot of the code is inconsistent and sloppy, I've been just trying to get everything working and then clean everything up.

Here is the video:

http://youtu.be/O9PP3qb8waM

That is with my tps at 1 using SDL_getTicks(); I think that you're right and my loop code is at fault.

Edited by BlueSpud, 10 September 2013 - 04:02 PM.

### #12WiredCat  Members

Posted 10 September 2013 - 03:08 PM

okj so if we almost knwo whats the problem i think you should check

http://www.sulaco.co.za/opengl_project_Basic_3D_engine.htm

and see OpenGlApp.dpr file for source

its object pascal but its not a big deal (and uses win32 loops) but everything is the same just use it as your template and make loop like there, then see if problem still occurs, however try disabling collision check and see if problem is still present, i found same camera behaviour with bad collision checks.

oh and code sorry but i haev to log in, i dont want to make another account ;] i want to know how you execute

void renderTick(float intp);

/ anyway still too less accurate timing/

### #13BlueSpud  Members

Posted 10 September 2013 - 04:03 PM

okj so if we almost knwo whats the problem i think you should check

http://www.sulaco.co.za/opengl_project_Basic_3D_engine.htm

and see OpenGlApp.dpr file for source

its object pascal but its not a big deal (and uses win32 loops) but everything is the same just use it as your template and make loop like there, then see if problem still occurs, however try disabling collision check and see if problem is still present, i found same camera behaviour with bad collision checks.

oh and code sorry but i haev to log in, i dont want to make another account ;] i want to know how you execute

void renderTick(float intp);

/ anyway still too less accurate timing/

The sampled code didn't help, thanks though. Here is the render code, though it doesn't say much:

void World::worldRender()
{
start = mach_absolute_time();
Physics.calculateCrouch();
crouch = Physics.crouch;

Physics.calculateJump();
camy -= Physics.jump/15;
Physics.calculateLean();

//obj1.testMeshAgainstMesh(&ModelRegistry.models[obj2.model].m);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//render skybox
glLoadIdentity();
renderSkybox();
//skybox.renderObject();
glLoadIdentity();
renderViewModel();

renderCamera();
glMatrixMode(GL_MODELVIEW);
GLfloat position[] = {-Lighting.x,-Lighting.y,-Lighting.z,1};
glLightfv(GL_LIGHT0, GL_POSITION, position);
glDisable(GL_LIGHTING);

Lighting.setupDepthImage();
glLoadIdentity();

for (int i = 0; i < objects.size(); i++)
{
objects[i].renderObjectForDepth();
}
Lighting.finishDepthImage();

for (int i = 0; i < objects.size(); i++)
{
objects[i].renderObject();
}

renderCamera();
glTranslatef(-test.position.x, test.position.y, -test.position.z);
//glutSolidSphere(1, 20, 20);
test.updateParticle(1);

SDL_GL_SwapWindow(window);
glLoadIdentity();
}

Even when using the performance counter the problem still exists.

Here is my understanding of the game loop. (I really just copy and pasted most of it) - the comments are my explanation

while (running)
{
while (SDL_PollEvent(&event)) {
//do crap with events
switch (event.type)
{
int x,y,button;
case SDL_QUIT:
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();
cout << "The window has been closed.\n";
running = false;
break;
case SDL_MOUSEMOTION:
SDL_GetMouseState(&x, &y);
passiveMouse(x,y);
break;
case SDL_MOUSEBUTTONDOWN :
button = SDL_GetMouseState(&x, &y);
mouseFunc(button,1,x,y);
break;
case SDL_KEYDOWN:
keyboardDownFunc(event.key.keysym.sym);
break;
case SDL_KEYUP:
keyboardUpFunc(event.key.keysym.sym);
break;
default:

break;
}

}
loops = 0;
//this says if right now is after when we though the next game tick was supposed to be, then we start dropping frames to maintain the TPS
while (SDL_GetTicks()> nextGameTick && loops < MAX_FRAMESKIP) {
//when we expect the next tick to be based on the TPS
nextGameTick+=SKIP_TICKS;
//if we've already done 5 ticks, we are forced to render a frame, incrementing the counter for that
loops++;
//my own thing to check the tps, but it stays constant at 20
TickHandler.tps++;
//the game logic, collision, sending to the server, etc.
TickHandler.onTick();

//this is mine too so i get an accurate ticks per SECOND.
int tickTime = int(SDL_GetTicks()/1000);
if (tickTime > lastSec+1)
{
TickHandler.tps = 0;
lastSec = tickTime;
}
}
//calculating the render interpolation (copy and pasted)
TickHandler.interpolation = double(SDL_GetTicks() + SKIP_TICKS - nextGameTick )
/ double( SKIP_TICKS );
//do the logic such as moving for rendering, mostly visual stuff using the interpolation
TickHandler.onRender();
//render the frame with all the computations of the interpolated values
render();
}
Console.consoleActivated = false;
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();

Edited by BlueSpud, 10 September 2013 - 07:54 PM.

### #14WiredCat  Members

Posted 11 September 2013 - 07:08 AM

try disabling collision, i think theres problem, since i had same behaviour with bad collision calculation.

you didint show me where and how you execute void renderTick(float intp);

anyway how do you handle input? yes i see

keyboardDownFunc(event.key.keysym.sym);

but what if you hit forward button whats the code

again:

speed = speed*walkspeed;
float radx = ((yaw+addedAngle)*MPI/180);
camx -= (sinf(radx)/10)*speed;
camz += (cosf(radx)/10)*speed;

Physics.pos1 = -camx;
Physics.pos2 = -camz;

if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*3.1415926535/180);
camx += (sinf(radx)/20)*speed;
camz -= (cosf(radx)/20)*speed;

dont change const variable

speed= speed * something; change it = make  a different var

you camera seems to move like in cosine or sine function it accelerates and then deaccelerates again and again and again. maybe you pass it to  movespeed/  that magic float intp

and the mystery why you divide sine and cosine by 20 or 10?

### #15BlueSpud  Members

Posted 11 September 2013 - 12:31 PM

try disabling collision, i think theres problem, since i had same behaviour with bad collision calculation.

you didint show me where and how you execute void renderTick(float intp);

anyway how do you handle input? yes i see

keyboardDownFunc(event.key.keysym.sym);

but what if you hit forward button whats the code

again:

speed = speed*walkspeed;
float radx = ((yaw+addedAngle)*MPI/180);
camx -= (sinf(radx)/10)*speed;
camz += (cosf(radx)/10)*speed;

Physics.pos1 = -camx;
Physics.pos2 = -camz;

if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*3.1415926535/180);
camx += (sinf(radx)/20)*speed;
camz -= (cosf(radx)/20)*speed;

dont change const variable

speed= speed * something; change it = make  a different var

you camera seems to move like in cosine or sine function it accelerates and then deaccelerates again and again and again. maybe you pass it to  movespeed/  that magic float intp

and the mystery why you divide sine and cosine by 20 or 10?

try disabling collision, i think theres problem, since i had same behaviour with bad collision calculation.

you didint show me where and how you execute void renderTick(float intp);

anyway how do you handle input? yes i see

keyboardDownFunc(event.key.keysym.sym);

but what if you hit forward button whats the code

again:

speed = speed*walkspeed;
float radx = ((yaw+addedAngle)*MPI/180);
camx -= (sinf(radx)/10)*speed;
camz += (cosf(radx)/10)*speed;

Physics.pos1 = -camx;
Physics.pos2 = -camz;

if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*3.1415926535/180);
camx += (sinf(radx)/20)*speed;
camz -= (cosf(radx)/20)*speed;

dont change const variable

speed= speed * something; change it = make  a different var

you camera seems to move like in cosine or sine function it accelerates and then deaccelerates again and again and again. maybe you pass it to  movespeed/  that magic float intp

and the mystery why you divide sine and cosine by 20 or 10?

The sine and cosign division were slowing it down before I put in speed, but I neglected it. Replaced and put in the speed (to make it go a bit slower.) onRender() just calls a bunch of function pointers here is the code for it:

void tickHandler::onRender()
{
for (int i = 0; i< intfuncs.size();i++)
{
intfuncs[i](interpolation);
}
}

intfuncs is a vector:

  std::vector<void(*)(double intp)>intfuncs;

I changed the math on speed to be a new variable. The new movement code is:

void inputs::moveCameraFirstPerson(double speed)
{
double newspeed = (speed*(double)walkspeed)/10;
float radx = ((yaw+addedAngle)*MPI/180.0f);
camx -= (sinf(radx))*newspeed;
camz += (cosf(radx))*newspeed;

Physics.pos1 = -camx;
Physics.pos2 = -camz;

if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*MPI/180.0f);
camx += (sinf(radx))*newspeed;
camz -= (cosf(radx))*newspeed;
Physics.collided = false;

}
/*
Client.x = camx;
Client.z = camz;
Client.y = camy;

Projectile.x = camx;
Projectile.z = camz;
*/
}

### #16WiredCat  Members

Posted 11 September 2013 - 02:13 PM

oh you still divide by 10 not 10.0 [  double newspeed = (speed*(double)walkspeed)/10; ]

well, you don't divide sine or cosine to get slower movement, since this sine and cosine is your direction versor (normalized vector) then you multiple it by speed and time

camx -= sinf(move_angle_direction * pi_divided_by_180 ) * speed * time;
camz += cosf(move_angle_direction * pi_divided_by_180 ) * speed * time;

anyway

MPI/180.0f you could make a const float that is: its a lot eaisier for you and you won't make terrible mistake with ()



const float imopi = 0.017453292519943295769236907684886;

i ask for a code that executes this code:



void renderTick(float intp)
{
if (cameraPlayer == true)
{
Physics.pos3 = -camy;
Physics.collisions();
Input.applyGravity();
if (Input.walking == true)
Input.moveCameraFirstPerson(1*intp);
else
{
roll = 0;
Input.change = false;
}
}

}

i wanted to know values of float intp

and you show me an array of vectors or what

forgive me but i dont quite understand that:

void tickHandler::onRender()
{
for (int i = 0; i< intfuncs.size();i++)
{
intfuncs[i](interpolation);
}
}

intfuncs is a vector:
std::vector<void(*)(double intp)>intfuncs;

but i truly believe you set intp for rendertick function from this array right? are you changing it time or what? why you dont use constant variable for test purposes

===============================

but dont bother about it now i found that you told me that

void inputs::moveCameraFirstPerson(float speed) the speed is your time so i wish you mutiple it by 1.0 not 1 and make it real float since i think intp is your time ? (since you pass time to it - void renderTick(float intp) ]  and is it a float? really is it a float? or you just pass integer value there  (from  int tickTime = int(SDL_GetTicks()/1000);) you should make float time = float(tickTime);

you can't write renderTick(tickTime);

or you exec renderTick with this vector of int array? don't quite understand why you use vectors for simple player speed movement since its just one BLE BLE BLE BLEBLE

HERE LOL

int tickTime = int(SDL_GetTicks()/1000);

That i didn't find it earlier:

tickTime should be float

you divide 300 by 1000 what you can get with integer number calculation yes!!! integer only it shoould be float

float tickTime = float(SDL_GetTicks()) / 1000.0f;

but earlier part of my post is important too.

Edited by ___, 11 September 2013 - 02:19 PM.

### #17BlueSpud  Members

Posted 11 September 2013 - 02:41 PM

oh you still divide by 10 not 10.0 [  double newspeed = (speed*(double)walkspeed)/10; ]

well, you don't divide sine or cosine to get slower movement, since this sine and cosine is your direction versor (normalized vector) then you multiple it by speed and time

camx -= sinf(move_angle_direction * pi_divided_by_180 ) * speed * time;
camz += cosf(move_angle_direction * pi_divided_by_180 ) * speed * time;

anyway

MPI/180.0f you could make a const float that is: its a lot eaisier for you and you won't make terrible mistake with ()



const float imopi = 0.017453292519943295769236907684886;

i ask for a code that executes this code:



void renderTick(float intp)
{
if (cameraPlayer == true)
{
Physics.pos3 = -camy;
Physics.collisions();
Input.applyGravity();
if (Input.walking == true)
Input.moveCameraFirstPerson(1*intp);
else
{
roll = 0;
Input.change = false;
}
}

}

i wanted to know values of float intp

and you show me an array of vectors or what

forgive me but i dont quite understand that:

void tickHandler::onRender()
{
for (int i = 0; i< intfuncs.size();i++)
{
intfuncs[i](interpolation);
}
}

intfuncs is a vector:
std::vector<void(*)(double intp)>intfuncs;

but i truly believe you set intp for rendertick function from this array right? are you changing it time or what? why you dont use constant variable for test purposes

===============================

but dont bother about it now i found that you told me that

void inputs::moveCameraFirstPerson(float speed) the speed is your time so i wish you mutiple it by 1.0 not 1 and make it real float since i think intp is your time ? (since you pass time to it - void renderTick(float intp) ]  and is it a float? really is it a float? or you just pass integer value there  (from  int tickTime = int(SDL_GetTicks()/1000);) you should make float time = float(tickTime);

you can't write renderTick(tickTime);

or you exec renderTick with this vector of int array? don't quite understand why you use vectors for simple player speed movement since its just one BLE BLE BLE BLEBLE

HERE LOL

int tickTime = int(SDL_GetTicks()/1000);

That i didn't find it earlier:

tickTime should be float

you divide 300 by 1000 what you can get with integer number calculation yes!!! integer only it shoould be float

float tickTime = float(SDL_GetTicks()) / 1000.0f;

but earlier part of my post is important too.

I'm so sorry about giving you the wrong function XD. My brain is a bit scrambled right now. tickTime

technically isn't part of the game loop. It is just supposed to calculate about a second so I can print out the TPS and set it to 0 after a second. The vector is the list of interpolated functions, thats where the update for the movement is. I standardized MPI/180 because it made logical sense. Still the problem presents itself, even after disabling the collision detection.the performance counter is definitely the way to go, nice and smooth, but I need to figure out why its constantly accelerating and decelerating (I got rid of the division, do luck).

### #18WiredCat  Members

Posted 11 September 2013 - 03:17 PM

did you notice big red text?

The vector is the list of interpolated functions, thats where the update for the movement is.

I still dont get it.  list of interpolated movement functions?

### #19BlueSpud  Members

Posted 11 September 2013 - 03:22 PM

did you notice big red text?

The vector is the list of interpolated functions, thats where the update for the movement is.

I still dont get it.  list of interpolated movement functions?

I had sent the wrong thing. What I sent is the function for calling all the functions on the render. The vector is all of their pointers. The tickTime variable is just an approximation. It doesn't effect the movement in any way. I had used it to print out the ticks per second while I was writing the game loop.

### #20WiredCat  Members

Posted 11 September 2013 - 06:03 PM

so you don't use time for movement. and that is really bad. since s = v * t; (distance travelled  is equal to velocity multiplied by time)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.