jPCT-AE - a 3d engine for Android > Support

Objective arrow indicator

(1/2) > >>

dutch_delight:
Hi all,

I've been looking to implement a target indicator. An arrow at the top of the screen that always points at my next selected objective.

I've been using the code in this topic:
http://www.jpct.net/forum2/index.php/topic,1385.msg9704.html#msg9704

But that doesnt work as i want it to. the arrow seems to point at a point in the world when i move forwards and backwards
but when I rotate the helicopter, the arrow doesnt move and so the rotation goes all wrong.

It's probably to do with my setup:

playerLift (movement dummy)
playerTilt (rotation dummy - child of playerLift)
Player (helicopter model - child of playerTilt)
PlayerRadarDummy (dummy that positions the radarmap and compass - child of player)
PlayerObjectiveArrow (arrow mesh - child of playerRadarDummy)

WorldObjects is an Object3D array that holds my collection of objectives.




--- Code: ---SimpleVector lookAtPoint = playerLift.getTransformedCenter().calcSub(WorldObjects.get(0).getTransformedCenter());
lookAtPoint.add( WorldObjects.get(0).getZAxis() );
SimpleVector direction = new SimpleVector(lookAtPoint.calcSub( object.getTranslation() ) );
Matrix rotationMatrix = new Matrix( direction.getRotationMatrix() );
PlayerObjectiveArrow.setRotationMatrix( rotationMatrix );
--- End code ---


Any help would be much appreciated as this is the last piece of code to make my game work.

K24A3:
What you need is a function that rotates an Object3D to point to a SimpleVector, the function is posted in this forum (search for 'lookat'). Once you have that, you would then do something like this:

- translate/move the arrow so it's visible to the user onscreen.
- use the LookAt function parsing the arrow's Object3D and your lookAtPoint to rotate the arrow towards the destination vector, ignoring the helicopters rotation.

Perhaps Egon can add it to jPCT's Object3D class? It would be a very useful addition imo.

dutch_delight:
Yeah that's what I've got.

the playerRadarDummy is always offset from the camera so that it displays my minimap, radar and objective arrow
the arrow is always at the top of the screen and gets its rotation from the lookat function.

but I guess the lookat function is not taking into account either my rotation
dummy or translation dummy.

thanks though

EgonOlsen:
I don't get what this code is supposed to do...you are calculating the vector between WorldObjects.get(0) and the player with the first line. Are you sure that this is what you want to do? Don't you want to calculate the vector between the player and WorldObjects.get(0) instead? You then add the z-axis of WorldObjects.get(0) in world space to that vector...why? Then you subtract the translation of object...what is object?...as said, i don't get it...

dutch_delight:
ah sorry. I've been trying everything to make this work so the code was in a bit of a mess.

I've done as you said which does make it work as it should. Only problem was that it didnt rotate when the camera rotated. So I've fixed that by attaching the arrow to another dummy which i rotate in the oposite of the camera.
It all works now. thanks for taking the time to look at my (bad) code.

Navigation

[0] Message Index

[#] Next page

Go to full version