Odd Behaviour when backing up

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ceisnaugle

Odd Behaviour when backing up

Post by ceisnaugle »

I've been experimenting with my own camera now and it all works extremely nice, except for one thing. (btw there is no time based movement yet this is just test code to make sure it works. Most of this was ripped from the FPS camera. It's also windows specific for the moment)

I was fooling around with movement and noticed that that when I hit the back key to back up it will render strangely the window will go black till I stop moving and then render properly. This only seems to happen if the movement rate is >= 1.0, anything below 1.0 is fine.

Any help would be appreciated, I also debugged the Target and it all seems fine even when backing up, its just very strange

Thanks,

Chris


Here is the test code:

void CCameraNode::CheckCameraKeys()
{
long ShiftKey, AltKey, KeyState;
float Multiplier;

Update = false;

// Get Key States
AltKey = GetAsyncKeyState(VK_MENU);
ShiftKey = GetAsyncKeyState(VK_SHIFT);

// Setup Movement Multiplier
Multiplier = 1.0f;

// Check for a Multiplier
if (ShiftKey == 1 || ShiftKey < 0) Multiplier = 2.0f;

// Check for Turns
KeyState = GetAsyncKeyState(VK_LEFT);
if (KeyState == 1 || KeyState < 0)
{
Yaw -= (0.5f * Multiplier);
if (Yaw < 0) Yaw += 360;

Update = true;
}
else
{
KeyState = GetAsyncKeyState(VK_RIGHT);
if (KeyState == 1 || KeyState < 0)
{
Yaw += (0.5f * Multiplier);
if (Yaw >= 360) Yaw -= 360;

Update = true;
}
}


// Check for Up and Down
// Up/Down
KeyState = GetAsyncKeyState(VK_NEXT);
if (KeyState == 1 || KeyState < 0)
{
Pitch += 1.0f;
if (Pitch > 85.0f) Pitch = 85.0f;

Update = true;
}
else
{
KeyState = GetAsyncKeyState(VK_PRIOR);
if (KeyState == 1 || KeyState < 0)
{
Pitch -= 1.0f;
if (Pitch < -85.0f) Pitch = -85.0f;

Update = true;
}
}


// Prepare for new Target etc
Target.set(0,0,1);

core::matrix4 Mat;
Mat.setRotationDegrees(core::vector3df(Pitch,Yaw,Roll));
Mat.transformVect(Target);

core::vector3df MoveDir = Target;
MoveDir.normalize();

// Check for Forward/back Movement
KeyState = GetAsyncKeyState(VK_UP);
if (KeyState == 1 || KeyState < 0)
{
Position += MoveDir * 1.0f;
Update = true;
}
else {
KeyState = GetAsyncKeyState(VK_DOWN);
if (KeyState == 1 || KeyState < 0)
{

// If this is ever set to 1.0f or higher it will do strange things
// to the screen when backing up, it will black out for a moment
// then reutrn when I let go of the key. If I increase it to
// 2.0 for example its flips me 180 on my view target and
// looks like I turned around and am walking the other way
// anything below 1.0 works fine
Position -= MoveDir * 1.0f;
Update = true;
}
}


// Do we need to update?
if (Update == true)
{
Camera->setPosition(Position);

Target += Position;
Camera->setTarget(Target);

Update = false;

}
}
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

try calling camera->updateAbsolutePosition() after setting it's new position
ceisnaugle

updateAbsolutePosition

Post by ceisnaugle »

"updateAbsolutePosition" is a protected member so I am unable to access it. My camera pointer was created using SceneMgr->addCameraSceneNode(..), so its just a pointer to an "ICameraSceneNode".

Not sure why using updateAbsolutePosition should make a difference when it works fine with anything below 1.0 on the movement rate and works fine in any other direction or rotation with values >= 1.0

Chris
Post Reply