Q: 3D Overlay with SceneNode

Problems building or running the engine, queries about how to use features etc.
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Q: 3D Overlay with SceneNode

Post by Van »

I am attempting to create a Hud. I have two Hud overlays: one 2D hud overlay (ZOrder=500) and one 3D hud overlay (ZOrder=499). In the 3D hud, I only have ONE item at the moment - an "arrow" that will point in the direction of a target selected by the player. The arrow will use the "SceneNode::setAutoTracking" option.

The problem
When I attach (Overlay::add3D) the "arrow" SceneNode to the 3D Hud Overlay and set the AutoTracking to a valid node, the arrow spins about violently. However, if I do not attach the node to the overlay the arrow works properly.

Code: Select all

	// Hud 3D
	mOverlayHud3D = (Overlay*)OverlayManager::getSingleton().getByName("Hud/3D");

	EntityArrowTargetVector = mSceneMgr->createEntity("ArrowTargetVector", "vectorarrow.mesh");
	NodeArrowTargetVector = mSceneMgr->createSceneNode(EntityArrowTargetVector->getName());
	NodeArrowTargetVector->attachObject(EntityArrowTargetVector);
	NodeArrowTargetVector->getMaterial()->setDepthCheckEnabled( false );
	mOverlayHud3D->add3D(NodeArrowTargetVector);
	NodeArrowTargetVector->setPosition(0,-12,-125);
	NodeArrowTargetVector->setVisible(false);
	NodeArrowTargetVector->setAutoTracking(true,MySpaceShip->CurrentTarget->Node);
	NodeArrowTargetVector->setVisible(true);

If I comment out the mOverlayHud3D->add3D(NodeArrowTargetVector); it seems to work fine.

Any suggestions?
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

Calculate yourself the direction of the arrow using the target's position and yours, and then apply the rotation to the arrow. I'm not sure if using auto-target with 3D overlays is secure :?
Image
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

Thanks Kencho for your reply.

Unfortunately, I get the same results. :(
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

More information.

I my SceneNode is starting at position 8000,0,0.

When I start to move, the arrow is "tumbling" (like a gimbal lock). However, If I turn 90 degrees, the arrow works correctly.

BTW, FYI, I get am using the Newton Physics Engine (1.31) and am getting the direction/velocity of travel with NewtonBodyGetVelocity()

Here is the code:

Ogre::Vector3 MySpaceShip->Velocity

Code: Select all


	NewtonBodyGetVelocity(NewtonRigidBody, &MySpaceShip->Velocity.x);


	// Drift arrow
	if (MySpaceShip->Velocity != Ogre::Vector3::ZERO)
	{
		NodeArrowDriftVector->setDirection(MySpaceShip->Velocity);
		NodeArrowDriftVector->setVisible(true);
	} else {
		NodeArrowDriftVector->setVisible(false);
	}
Anyone have any Ideas?
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

Van wrote:

Code: Select all

NewtonBodyGetVelocity(NewtonRigidBody, &MySpaceShip->Velocity.x);
Not sure if this is the problem, but what is the '.x' doing there? Velocity is a vector, right? Shouldn't it be:

Code: Select all

NewtonBodyGetVelocity(NewtonRigidBody, &MySpaceShip->Velocity);
If you were not initializing y and z of the vector, maybe that explains the strange movement.
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

DWORD wrote:
Van wrote:

Code: Select all

NewtonBodyGetVelocity(NewtonRigidBody, &MySpaceShip->Velocity.x);
Not sure if this is the problem, but what is the '.x' doing there? Velocity is a vector, right? Shouldn't it be:

Code: Select all

NewtonBodyGetVelocity(NewtonRigidBody, &MySpaceShip->Velocity);
If you were not initializing y and z of the vector, maybe that explains the strange movement.
From the Netwon SDK documenation

Code: Select all

Get the global linear velocity of the body. 

void NewtonBodyGetVelocity(const NewtonBody* bodyPtr, float* velocity) 

Parameters
const NewtonBody *bodyPtr  - is the pointer to the body.  
const float *velocity  - pointer to an array of at least three floats to hold the velocity vector.  
Just so you know the syntax. Its is correct. You just pass the first element of the array and Newton will populate all three elements. The numbers I am getting back appear correct during debug.

[rant]
I have tried using AutoTracking and doing the math myself. I have tried attaching it to the Overlay (3D) and NOT attaching it to the overlay and I get the same results all the time. Is probably starring me in the face and I just can't see it.
[/rant]


This is SO frustrating. :(
I thought this would be simple. I want my arrow to act like the camera and constantly "lookat" and "autotrack" the players target (another SceneNode) so the player knows the relative location of the target. Whats MORE frustrating is that in certain Positins/Orientations the arrow works find however, in other combinations it tumbles.
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

Van wrote:Just so you know the syntax. Its is correct. You just pass the first element of the array and Newton will populate all three elements. The numbers I am getting back appear correct during debug.
Sorry, just me not knowing Newton (and not thinking).
Van wrote:I have tried attaching it to the Overlay (3D) and NOT attaching it to the overlay and I get the same results all the time.
Are you certain? In your first post, you said it worked if you didn't attach the arrow to the overlay. :? Are you using the position of the arrow's scene node for the calculations? I don't know if it's safe to get the position when it's just attached to an Overlay (and not the root scene node). Also wouldn't it be best to use the actual players position instead of (0,-12,-125)? Just guessing about what you are doing here, maybe you could post a minimal example somewhere?
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

Here is some sample information:

Current Code, this gets called every frame update

Code: Select all

	// Drift arrow
	if (MySpaceShip->Velocity != Ogre::Vector3::ZERO)
	{
		NodeArrowDriftVector->setDirection(
			MySpaceShip->Velocity,
			Ogre::Node::TS_WORLD,
			Ogre::Vector3::NEGATIVE_UNIT_Z);
		NodeArrowDriftVector->setVisible(true);
	} else {
		NodeArrowDriftVector->setVisible(false);
	}
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

DWORD,

You are on to someting. Apparently, from what I can tell from testing,when having a SceneNode AutoTrack another SceneNode the tracker SceneNode must be a child of the RootSceneNode and must not be attached to anything else (like another SceneNode or Overlay, etc).

Maybe there is a "derived" position error in the OgreMain library that causes this? Or, this implementation was never suppose to be used as I am using it?

Anyway, what I am doing now is creating the tracker SceneNode from the RootSceneNode and placing it in position in front of my ship to make it look like its part of the hud. However, now my problem is that when I rotate the ship, the ArrowNode doesn't rotate with me to stay directly in front of my hud. How do I do this? I can keep it at the correct distance with:

Code: Select all

	NodeArrowTargetVector->setPosition(MySpaceShip->NodeShipControl->getPosition() + Vector3(0,0,10));
...but I am unsure how to lock the arrows Orientation to stay in front of the hud.