Game Development Community

MAcos

by DIAG · in Torque Game Engine · 05/26/2004 (5:52 am) · 6 replies

Hello,
Just a quick question. Everytime i use a value greater than 1 in mACos, i get returned gibberish. Is there any way of resolving this?

#1
05/26/2004 (6:32 am)
No. Arc cosine inverts the cosine operation (ie. it finds the angle theta such that cos(theta) = amplitude). Think of the cosine graph. It goes from -1 to 1 in amplitude. So, there is no angle that gives a cosine of more than 1.

What are you trying to accomplish with this? Maybe we can help you figure out another way to do it.
#2
05/26/2004 (6:44 am)
Hey,
Thanks for your prompt reply. I am trying to get a modelled entity to go between two points. i was going to get this entity to move 0.5 game units every tick, in the required direction. so id get the angle between the two points using mAtan, then use this to find the appropriate x and y offset for that particular angle. but mAtan is returing values greater than 1. how can this be, if it cant be used by cos?
Cheers
#3
05/26/2004 (7:17 am)
Basic trigonomerty stuff here, cos and sin don't use values over 1, tan does though. Just try it on any scientifical calculator, inverse sin(sin-1)1.1 will return an error, whereas inverse tan(tan-1)1.1 will return 47.7. It is to do with sin and cos only dealing with angles less than 90 to put simply.

http://aleph0.clarku.edu/~djoyce/java/trig/

Here is a good site about trig I found useful.

Hope this helps a bit :)
#4
05/26/2004 (7:21 pm)
What you are trying to do is more naturally expressed by vectors. You have, if I understand you, point A and point B. Point A is the starting point. Point B is the ending point. You want to move along the line from A to B.

Here's some torque script that might help:
%A = "1 2 3"; // x y z coordinates
%B = "6 7 8";

%vec = VectorSub(%B, %A);
%vec = VectorNormalize(%vec);
%vec = VectorScale(%vec, .5);

%pos = %A;
on each tick:
%pos = VectorAdd(%pos, %vec);
#5
05/26/2004 (8:01 pm)
*Outside Note*: That is a start on fixing the Advanced Camera resource AdvancedCamera::runCameraCollisionCheck //TODO when the offset Camera Position collides with a terrain or interior: project the camera back towards the character along the vector from camera position to player position a small distance to get out of the terrain/interior. You determine a direction vector from the camera (%A) towards the character (%B), normalize that vector to get simply the direction, then apply a (small) scalar multiplier to see if you escape being "inside" the object you originally were "within"...then set your new camera position.

Sorry to hijack, hehe..but sometimes it's the small simple things that solve a problem! You just gave me the code I've been designing for a few hours, and every little bit helps!
#6
05/27/2004 (3:16 am)
Thanks eric! that works a treat!