Author Topic: Objective arrow indicator  (Read 3540 times)

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Objective arrow indicator
« on: January 22, 2012, 10:43:42 pm »
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: [Select]
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 );


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


Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Objective arrow indicator
« Reply #1 on: January 23, 2012, 08:52:09 am »
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.

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: Objective arrow indicator
« Reply #2 on: January 23, 2012, 02:29:13 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objective arrow indicator
« Reply #3 on: January 23, 2012, 03:07:36 pm »
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...

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: Objective arrow indicator
« Reply #4 on: January 23, 2012, 09:55:48 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objective arrow indicator
« Reply #5 on: January 24, 2012, 10:16:35 am »
Any help would be much appreciated as this is the last piece of code to make my game work.

....

It all works now. thanks for taking the time to look at my (bad) code.

I guess that means that we can expect a playable version soon... ;)

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: Objective arrow indicator
« Reply #6 on: January 29, 2012, 12:23:40 pm »
Nearly there, nearly there.

You'll be the first to see it.