• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BlueSpud

Camera Interpolation

24 posts in this topic

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.

 

 

0

Share this post


Link to post
Share on other sites
 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 ___
0

Share this post


Link to post
Share on other sites

 

 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.

0

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites


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.

0

Share this post


Link to post
Share on other sites

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 ___
0

Share this post


Link to post
Share on other sites


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?

0

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

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 :P

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

-2

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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/

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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;
     */
}
0

Share this post


Link to post
Share on other sites

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 ___
0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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. 

0

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

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)

intp is time. intp is the time in between the ticks, which are going at a constant rate of 20 ticks per sec on, giver er take a bit of time here and there. Really the problem at hand is why the camera keeps accelerating and decelerating. 

0

Share this post


Link to post
Share on other sites

Is your camera tied to the player?

Does your player only update on logical ticks?

If so, does that mean your camera only updates its position on logical ticks?

 

If so, we have found the problem.

The camera should update every frame based on the interpolated position of the player—the position used for rendering every frame.

 

If this is not your problem, you will need to provide more information.

 

 

L. Spiro

Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

Is your camera tied to the player?
Does your player only update on logical ticks?
If so, does that mean your camera only updates its position on logical ticks?

If so, we have found the problem.
The camera should update every frame based on the interpolated position of the player—the position used for rendering every frame.

If this is not your problem, you will need to provide more information.


L. Spiro

the camera, right now is bound to the player. I have narrowed it down to using a higher resolution counter to make it look smooth. My problem not is it constantly accelerates and decelerates. The movement is on an interpolated tick.
0

Share this post


Link to post
Share on other sites
@BlueSpud
 
I do like that:
 
float frameTime = GetFrameTime();
float t = (frameTime * 2.0);


Vector3 vecStart = vecPos (current camera position);
Vector3 vecEnd = player->GetCamOffset() * ( player->GetWorldMatrix() );


if( Length(vecEnd - vecStart) > 0.0)
{

//interpolate
vecPos = vecStart + (vecEnd - vecStart) * t;


//camera variables
vecX = player->GetRotMatrix().GetX();
vecY = player->GetRotMatrix().GetY();
vecZ = player->GetRotMatrix().GetZ();

//camera view matrix
matView = MatrixLookAt(vecPos, player->GetPosition(), Vector3(0, 1, 0) );
}
 
Update the camera position by the half of the frame time based on the camera offset.
Edited by irlanrobson
0

Share this post


Link to post
Share on other sites

 

@BlueSpud
 
I do like that:
 
float frameTime = GetFrameTime();
float t = (frameTime * 2.0);


Vector3 vecStart = vecPos (current camera position);
Vector3 vecEnd = player->GetCamOffset() * ( player->GetWorldMatrix() );


if( Length(vecEnd - vecStart) > 0.0)
{

//interpolate
vecPos = vecStart + (vecEnd - vecStart) * t;


//camera variables
vecX = player->GetRotMatrix().GetX();
vecY = player->GetRotMatrix().GetY();
vecZ = player->GetRotMatrix().GetZ();

//camera view matrix
matView = MatrixLookAt(vecPos, player->GetPosition(), Vector3(0, 1, 0) );
}
 
Update the camera position by the half of the frame time based on the camera offset.

 

I ended up using time elapsed instead of time between the tick, but thanks anyways. To anyone else who stumbles upon this topic here is what I ended up doing:

- I used SDL_GetPreformenceCounter() because it has a much higher precision.

- I used elapsed time not the interpolation that Dewitter's game loop entails. This is because the time in between the tick is not very good because it can greatly stutter and even though the game loop is "frame rate independent" Values can vary and not ending up what you want.

 

The game and view is much smoother now, thanks to everyone who has helped.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0