Gui Arrow Guide.
by Peterjohn Griffiths · in Torque Game Engine · 10/13/2006 (11:41 pm) · 8 replies
I am still a bit of a noob and I am wanting to create an arrow to guide the player to the next check point.
I have done some research on this and have found the guiMeterCtrl created by Frank Bignone
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2676
I had to do some digging to get the control working in Torque 1.4 and posted the corrections at the bottom.
So now I have my guiMeterCtrl with no background and a arrow pointer set to 0. I have set this up so that it works in degrees with 0 as straight ahead, using the following code in client\ui\playGui.gui
Now this is where I'm stuck.
I need to update this control's angle with the angle the checkpoint is, from the car's relative position in the mission.
Anyone got any idea how I would go about this.
Any pointers on what to read up on? methods / functions / resources.
I can't seem to find anything relevant and I am at a bit of a dead end with this bit.
Many thanks in advance.
I have done some research on this and have found the guiMeterCtrl created by Frank Bignone
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2676
I had to do some digging to get the control working in Torque 1.4 and posted the corrections at the bottom.
So now I have my guiMeterCtrl with no background and a arrow pointer set to 0. I have set this up so that it works in degrees with 0 as straight ahead, using the following code in client\ui\playGui.gui
new GuiMeterCtrl(arrowPointer) {
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "12 512";
Extent = "83 81";
MinExtent = "8 8";
Visible = "1";
wrap = "0";
spinBitmap = "~/data/shapes/fuel/spin.png";
color = "1 1 1 1";
angle = "0";
spinAngle = "0 100";
spinOffset = "2 3";
helpTag = "0";
lockMouse = "0";
};Now this is where I'm stuck.
I need to update this control's angle with the angle the checkpoint is, from the car's relative position in the mission.
Anyone got any idea how I would go about this.
Any pointers on what to read up on? methods / functions / resources.
I can't seem to find anything relevant and I am at a bit of a dead end with this bit.
Many thanks in advance.
#2
By forward vector do you mean the transform of the car?.
I have tried but couldn't get it to work correctly.
Maybe its becouse you don't mean the transform of the car?.
How do I get the forward vector of the car?.
10/22/2006 (8:28 pm)
Bit over my head that.. :+}By forward vector do you mean the transform of the car?.
I have tried but couldn't get it to work correctly.
Maybe its becouse you don't mean the transform of the car?.
How do I get the forward vector of the car?.
#3
%car.getForwardVector();
That would return the forward vector and would then work fine.
I have spent two days trying to get this to work and it would seem I was barking up the wrong tree with transform. The fromFwd is what got me thinking its was the transform that was needed. I guess you learn something new every day (Or two in my case :+} ).
10/22/2006 (8:34 pm)
Ok, I see it now. Dough!.%car.getForwardVector();
That would return the forward vector and would then work fine.
I have spent two days trying to get this to work and it would seem I was barking up the wrong tree with transform. The fromFwd is what got me thinking its was the transform that was needed. I guess you learn something new every day (Or two in my case :+} ).
#4
Many thanks again.
:+}
10/22/2006 (8:36 pm)
Almost forgot to say thankyou Frank Bignone, for writing the "FuelOMeter, SpeedOMeter like control" resource, updating the guimeterctrl and for helping with this problem.Many thanks again.
:+}
#5
10/25/2006 (2:22 am)
You're welcome.
#6
What I need is when facing towards an object, it returns 0 degrees.
When turned to one side it returns 90 degrees.
When turned to the other side it returns -90 degrees.
I need this for every degree from -180 (Facing away) through to 0 (Facing towards) through to 180 (Facing away again).
Anyone got any idea where this is going wrong?.
10/27/2006 (5:36 pm)
I have this sort of working with the following.function getAngle(%itemPos, %playerFwd, %playerPos){
%itemFwd = VectorSub(%playerPos, %itemPos);
%myAngle = mRadToDeg(mAcos(VectorDot(VectorNormalize(%itemFwd), VectorNormalize(%playerFwd))));
}Only problem is that when the car is pointing towards the object it returns 180 degrees and not 0. Also there is no -180 degrees.What I need is when facing towards an object, it returns 0 degrees.
When turned to one side it returns 90 degrees.
When turned to the other side it returns -90 degrees.
I need this for every degree from -180 (Facing away) through to 0 (Facing towards) through to 180 (Facing away again).
Anyone got any idea where this is going wrong?.
#7
I don't pretend to understand all the math and have done this by reading other posts and resources and with help form other people like Frank Bignone and my brother in law who has an eng background.
Here is the code to return the angle to an object. Again note that the angle returned is not totaly accurate. :+O
Example of how to use this function
The angle returned in %angleToObject is the angle from the car's forward vector in + or - 0 to 180 degrees.
Degrees above 0 are to the left and degrees below 0 are to the Right.
If anyone can improve on this please post below.
Below are the problems the function has that seem to effect the accuracy of the angle returned.
The angle returned by the following line of code it the oposite of the 180 angle and I don't understand why.
I have spent a long time trying to get this to work and this works well enough for now, but it would be great to get it to work with more accuracy.
10/28/2006 (2:18 pm)
I have managed to get this working a lot better but its not totaly accurate.I don't pretend to understand all the math and have done this by reading other posts and resources and with help form other people like Frank Bignone and my brother in law who has an eng background.
Here is the code to return the angle to an object. Again note that the angle returned is not totaly accurate. :+O
function getAngleFromVectors(%itemPos, %playerFwd, %playerPos){
//Work out the forward vector between the two position vectors.
%itemFwd = VectorSub(%playerPos, %itemPos);
//Work out the angle the object is from the player fwd vector. This will always be an angle >= 0.
%myAngle = mRadToDeg(mAcos(VectorDot(VectorNormalize(%itemFwd), VectorNormalize(%playerFwd))));
//%myAngle is the oposite 180 of the angle we require. If %myAngle is 10 Degrees then its actualy 170 degrees. 20=160, 30=150, 40=140 etc.
%myAngle = 180 - %myAngle;
//Make the angle sloppy by 10 degree's, 5 either side of 0 to counter act the needle jumping when passing the object up close.
%myAngle = %myAngle - 5;
if (%myAngle < 0 ){
%myAngle = 0;
}
//Work out the side the object is on from the players forward vector. + left or - Right.
%crossProduct = VectorCross(VectorNormalize(%itemFwd), VectorNormalize(%playerFwd));
%rotation = GetWord(%crossProduct, 2);
if (%rotation < 0 ) {
//Angle needs to be a negative angle of the same amount as its on the right.
%myAngle = %myAngle - (%myAngle * 2);
}
//Return the angle.
return %myAngle;
}Example of how to use this function
%angleToObject = getAngleFromVectors(obj.position, localclientconnection.car.getForwardVector(), localclientconnection.car.position);
The angle returned in %angleToObject is the angle from the car's forward vector in + or - 0 to 180 degrees.
Degrees above 0 are to the left and degrees below 0 are to the Right.
If anyone can improve on this please post below.
Below are the problems the function has that seem to effect the accuracy of the angle returned.
The angle returned by the following line of code it the oposite of the 180 angle and I don't understand why.
%myAngle = mRadToDeg(mAcos(VectorDot(VectorNormalize(%itemFwd), VectorNormalize(%playerFwd))));Because I couldn't fix the above problem, I worked with it and used the following code to reverse the andle.
%myAngle = 180 - %myAngle;
I have spent a long time trying to get this to work and this works well enough for now, but it would be great to get it to work with more accuracy.
#8
www.uklanparty.net/modules.php?name=Forums&file=viewtopic&t=545
10/28/2006 (3:10 pm)
There are some screenshots on our forum if anyone is interested.www.uklanparty.net/modules.php?name=Forums&file=viewtopic&t=545
Torque 3D Owner Frank Bignone
Darkhand Studio
A quick way: You can (on server side), take the position of the player and position of the next checkpoint. Then you can compute the angle between the forward vector of your player and the vector form by the two previous position (used dot vector product with normalized vector and you will get the cos of the angle). It should work ok.