Thread: Pixle Calc. Problem

  1. #1
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195

    Question Pixle Calc. Problem

    For the game i have been making i have been using some physics to create realistic, parabolic, movments.

    i first use Vf = Vi + at to find the next velocity from the last one
    then i change Vi = Vf in order to create the change in velocity
    then DeltaY = Vi(Sin(theta)(DeltaTime) - 1/2(Gravity(DeltaTime^2)
    then DeltaX = Vi(Cos(theta)(DeltaTime)
    (i love physics)

    the problem is that since i am having this program run at 60 frames per second i use 1/60 for my DeltaTime, right. but the chance from one position to the next it to small becouse the time change it to small so the object dose not move becouse you cant draw part of a pixle, and if i up the time frame it of corse moves way to fast.

    Any one with any tricks on the subject plz tell me and thank you for your input
    Last edited by loopshot; 03-14-2005 at 10:03 PM.

  2. #2
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    Sorry chance should me change

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Make your time based movement depend on time, not frames. That way you can have any frame rate you want and the motion still takes the same amount of time.

  4. #4
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195

    Thumbs up

    k thanks for your help

  5. #5
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    I have been looking around and have not been able to find any thing one implementing time, can some one point me in the right direction, that would be great.

    it would also be great if some one could explain a little about how to implement what Perspective was talking about, after some thought i dont really understand how that would help me with my pixle problem becouse i would still be using small incremets of time, which would still not show up when the flote converts to int.

    thanks for the help
    Last edited by loopshot; 03-18-2005 at 07:44 AM.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I have been looking around and have not been able to find any thing one implementing time, can some one point me in the right direction, that would be great.
    I know we discussed this on the game programming forum because Shakti and I use different timing methods and there is a post here which talks about both approaches.

    Do a search on TimeGetTime() and GetTickCount().

  7. #7
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    I Searched TimeGetTime() and GetTickCount() in different cominations them seprate and i did not find much but i will look them up on msdn i guess, i did not see the posts before becouse i was searching for just time implemetation, and time tracking, time ect.
    thanks for listing the functions though

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You should probably look into high-resolution timers. Those other timers are junk.

    QueryPerformanceFrequency
    QueryPerformanceCounter
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    Thanks Mr Wizard

    another question that i have is, when seting up all of this time stuff for when to recalculate every thing, do i check the time, and have it continue to loop my program, then check agian for == or greater than, or do i loop though only that specific spot untill the condition it met then continue though my program.(remember this is a game and the time period is the time between when to calculate my physics agian)

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    The way I do it (thanks to some guy over at www.gamedev.net):
    Code:
    // This function is called ONCE each frame
    float Val2Proc()
    {
    	static double       time_elapsed;
    	static __int64      pc1, pc2;
    	static __int64      pf;
    
    	QueryPerformanceCounter((LARGE_INTEGER*)&pc2);
    
    	time_elapsed = double(pc2-pc1) / double(pf);
    	QueryPerformanceFrequency((LARGE_INTEGER*)&pf);
    	QueryPerformanceCounter((LARGE_INTEGER*)&pc1);
    
            // procPower is a global float i have. 50 is a number I just chose.
    	procPower = (float)time_elapsed*50.0f;    
    	return (float)time_elapsed;
    }
    Then, I multiply everything that should be timebased (like cameraspeed, the speed of an object) with procPower. There are lots of ways you could do it, this is one. most likely not the best way but I think it does the job just fine.
    Last edited by Shakti; 03-18-2005 at 02:11 PM.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    QueryPerformanceCounter((LARGE_INTEGER*)&pc2);
    That's the one I was looking for not GetTickCount().

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Depending on what hardware you support, always remember that the machine the game will want to run on / is capable of running on might not have harware timers. I personally support both hardware and multimedia timers in all my games for older computers.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Depending on what hardware you support, always remember that the machine the game will want to run on / is capable of running on might not have harware timers. I personally support both hardware and multimedia timers in all my games for older computers.
    Every system running windows XP/98 SE/2K can use those functions. They are part of the API. If you are not using Windows then of course you will have to use your platform's equivalent. All and I mean ALL CPUS have hardware timers.

  14. #14
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    thanks alot for all of your help

  15. #15
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    Shakti, why do you return (float)time_elapsed;, when you have already set procPower to what you want? is it just to make the function more usefull by allowing the coder to also use it to return the time elapsed between frames if needed?

    Also, why in "procPower = (float)time_elapsed*50.0f;" do you multiply time_elapsed by 50?

    Also, why in "time_elapsed = double(pc2-pc1) / double(pf);" do you divide by the frequency pf?
    Last edited by loopshot; 03-22-2005 at 01:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM