Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: [C#] Mesh keeps moving when not focused  (Read 1301 times)
JaWSnl
Community Member
*
Posts: 2


« on: August 23, 2009, 12:28:06 PM »

Goodday,

this is my first post ever, i have looked for a solution for a while but cant find what I need to know. Here goes:

We are creating a 3d game. The question still is whether it will be an online game or an offline game.
I am using C#, and in the 3d world i now have a cube and a sphere. The cube is like a long wall (very thin and long, man height). The sphere has the diameter of a man. It starts on top of one end of the wall, end the moves to the other end of the wall. I use the following function which i call in my main loop.

Code: (C#)
        public void Move(int __speedFactor)
        {
            TV_3DVECTOR __scalemin = new TV_3DVECTOR();
            TV_3DVECTOR __scalemax = new TV_3DVECTOR();
            TV_3DVECTOR __position = _GlobeMesh.GetPosition();
            _CubeMesh.GetBoundingBox(ref __scalemin,ref __scalemax);

            if (__globeDirection == 0)
                if (__scalemax.x > __position.x)
                    _GlobeMesh.SetPosition(__position.x + __speedFactor * 0.01F * (float)_Tv.TimeElapsed(), __position.y, __position.z);
                else __globeDirection = 1;
            else
                if (__scalemin.x < __position.x)
                    _GlobeMesh.SetPosition(__position.x - __speedFactor * 0.01F * (float)_Tv.TimeElapsed(), __position.y, __position.z);
                else __globeDirection = 0;
        }

When i use alt-tab to stop the focus, there is no more rendering, it sleeps for a few hundred milliseconds, and then checks again for focus. But when I come back, the program moves the sphere again. But, since now more time has elapsed, the sphere is moved WAY further than the bounds between i want it to move (the length of the cube).

The question:
How do I make it so that when there is no focus, and the focus comes back, it throws away the time elapsed, and starts moving again from where it was before focus? Would it be wise to stop counting the time elapsed when stopping focus? Or would that give other problems later (given it could become an online game)?
Logged
jviper
Community Member
*
Posts: 2130

Discipline in training


« Reply #1 on: August 23, 2009, 01:45:50 PM »

The problem is the form does not loose focus when you press the alt key or move the form. So that explains why that above code would not work. If you place a stoppoint in the false portion of that statement, you notice that the stop point does not get hit when you press the alt key, or move the form.

However, here's what you can try: Find the MouseCapturedChanged event for your form. In that event, Render the Scene, then poll TV.AccurateTimeElapsed(). It seemed to work for me.

EDIT: Oh, and also, never poll  TV.AccurateTimeElapsed() untill after you have rendered.
« Last Edit: August 23, 2009, 02:27:04 PM by jviper » Logged

JAbstract.....Don't just imagine, make it happen!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks