View unanswered posts | View active topics It is currently Sat Apr 27, 2024 5:11 am



Reply to topic  [ 2 posts ] 
 Vector vs. const Vector 
Author Message
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Vector vs. const Vector
I'm right now testing a Lua script that involves using a CastMORay(). The function calls for these arguments:

CastMORay(SceneManager,const Vector,const Vector,number,number,boolean,number).

My script has all the arguments, expect for the second "const Vector". The console screams at me that I only have inputted a Vector.

Apparently, self.Pos is a "const Vector", but something like Vector(2,1) is just considered a Vector. So what is the difference between a const Vector and a Vector? How do I define one?

For those wondering, this script is meant to do a ray cast that is tangent to the projectile's (self) current trajectory every Update(). Keep in mind not all of my code is show (there isn't much else after it though). This is for detecting whether or not the projectile is about to collide with another movable object (the if statement for the distance between the projectile and the found object is not shown).

Code:
local horrizon = nil;
       if self.Vel.X > 0 then
          horrizon = 1;
       elseif self.Vel.X < 0 then
          horrizon = -1;
       else
          horrizon = 0;
       end

       local horVector = Vector(horrizon,0);
       local velVec = Vector(self.Vel.X,self.Vel.Y);
       local normal = velVec:Normalize();
       local mag = math.sqrt(math.pow(self.Vel.X,2) + math.pow(self.Vel.Y,2));
       local angle = math.acos( normal:Dot(horVector) / 1 );  --arccos( a*b/(|a||b|)).  a and b always equal 1.

       --angle is always returned positive, so we need to make sure whether or not the projectile is heading down or not.
       if self.Vel.Y < 0 then
           angle = angle * -1;
       end

       --debug
       print("Horrizon Vector: (".. horrizon ..",0)");
       print("Normal Vector: (".. normal.X ..",".. normal.Y ..")");
       print("Magnitude: ".. mag);
       print("Angle: ".. angle);

       local targetID = SceneMan:CastMORay(self.Pos,normal,0,0,false,0);  --normal will be tangent to the projectile's movement


Sat Jun 06, 2009 2:50 am
Profile
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post Re: Vector vs. const Vector
You can make something a const Vector by using ToConstVector(myVector)


Sun Jun 07, 2009 7:44 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.187s | 15 Queries | GZIP : Off ]