View unanswered posts | View active topics It is currently Wed Apr 24, 2024 5:54 am



Reply to topic  [ 5 posts ] 
 Understanding CastStrengthRay 
Author Message
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post Understanding CastStrengthRay
As I understand it, the general idea of CastStrengthRay is to look around for any terrain pieces that are stronger than a specified value and to then return true or not.

According to the Wiki, CastStrengthRay is used as such:

Arguments:
- The starting position.
- The vector to trace along.
- The strength value of screen any found to be equal or more than will terminate the ray.
- A reference to the vector screen will be filled out with the absolute location of the found terrain pixel of less than or equal to above strength.
- For every pixel checked along the line, how many to skip between them for optimization reasons. 0 = every pixel is checked.
- A material ID to ignore, IN ADDITION to Air.
- Whether the ray should wrap around the scene if it crosses a seam.

Return value:
- Whether a material of equal or more strength was found along the ray. If not, the fourth parameter have been set to last position of the ray.

So it's really the fourth point that I'm confused about.
What would a reference be, and what is a vector screen?

I also found an example although I still don't quite understand why the fourth value is Vector (0,0) (or what will happen if I change it)

Code:
      local terrainRaycast = SceneMan:CastStrengthRay(self.Pos,Vector(self.Vel.X,self.Vel.Y),10,Vector(0,0),0,0,SceneMan.SceneWrapsX)


Any help would be appreciated!


Sat Mar 10, 2012 1:25 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Understanding CastStrengthRay
Basically, a reference means you're giving it hitPos itself instead of just a copy of hitPos. That way, the function can modify hitPos for you and then you can use that new data.
Code:
local hitPos = Vector();
local terrainRaycast = SceneMan:CastStrengthRay(self.Pos,Vector(self.Vel.X,self.Vel.Y),10,hitPos,0,0,SceneMan.SceneWrapsX);
After that, hitPos will be filled out with the position of where the ray terminated.
By setting that argument to Vector(0,0), you're giving it a throwaway value of sorts - you can't access it afterward. In other words, you don't care about where the ray ends, so it'll just discard the data.


Sat Mar 10, 2012 1:33 am
Profile WWW
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post Re: Understanding CastStrengthRay
So basically, if I want to know the exact point of where the ray hits, I add the hitPos part, but if I just want to know whether the ray hits or not, I just use Vector(0,0) right?

Assuming the above is true, CastStrengthRay will return a true/false value and a vector?


Sat Mar 10, 2012 2:56 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Understanding CastStrengthRay
Functions can only return one value - in this case, it's a Boolean (true/false) value. That's why you have to pass in the vector as a reference. To your first question, though, yes, just use Vector(0,0) (or just Vector(), since that's the same thing) if you don't care where it hits.


Sat Mar 10, 2012 3:43 am
Profile WWW
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post Re: Understanding CastStrengthRay
Alright thanks!


Sat Mar 10, 2012 4:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.074s | 15 Queries | GZIP : Off ]