Alright picture this: You have a single point. Now this point traces outward on a rotating radius creating several other points in a circular pattern. You now have a circle with a point in the center of it. Now cut this circle in half and you have a semicircle (half of a circle) made up of some lines connecting from point to point.
Now imagine that you are doing this with traces, and you want to be able to change the axis that this semicircle is being created on with another function. Confusing right?
Well I need to be able to do this in a function. So far, I though that I could use [url=http://wiki.garrysmod.com/?title=Angle.RotateAroundAxis]Angle:RotateAroundAxis()[/url], but since I'm using traces that deal with vectors, it seems all but impossible unless I use some hacky method like creating a ghost entity to do the traces.
Here's what I have so far, mind you I started this yesterday and doesn't do anything yet.
Ignore the other functions inside, just pay attention to the angle and trace stuff.
[lua]function MakeNewPoint()
self.vOrigin = self:GetSwingOrigin() --This is the center point of the circle I referred to earlier.
self.vStart = self.vOrigin + Vector()
self.Furthest = self:GetSwingMaxDist()
self.MaxPoints = self:GetSwingMaxPoints()
local p, y, r
local pointlen = self:GetSwingDist()/self.MaxPoints
local newaxis = self:GetSwingAngle():RotateAroundAxis( self.vOrigin, pointlen ) --Could this help?
local offset = Vector( p, y, r ) --Alright, I was planning on the p/y/r to be the pitch/yaw/roll of this semicircle.
local newvec = self.LastPoint + offset
local trace = {}
trace.startpos = self.LastPoint
trace.endpos = newvec
trace.filter = self
local traceres = util.TraceLine( trace )
--This trace is added to a table of points, but the direction the points goes needs to be based on the offset, which is based on the pitch/yaw/roll of the local "newaxis" shown above.
self.LastPoint = traceres.HitPos
table.insert(self.Points, self.LastPoint)
return true
end[/lua]
Basically, I need to know if I can rotate the pitch/yaw/roll of a geometrical arc created by traces. Could Angle:RotateRoundAxis() help me with this? If not I need some ideas of how to do this.
If this is too confusing, just tell me and I'll try my best to clarify.
If I understand you right, you want to draw traces from a point in a circle( or half circle ) that follows an axis. Right? You can get direction vectors from an angle using the Up, Right and Forward methods. Then you can use those vectors to rotate the angle. Like so..
[lua]
function RotateAroundAngle( pos, ang, length, angle )
-- get forward direction of the angle and rotate around that
local forward = ang:Forward( );
ang:RotateAroundAxis( forward, angle );
-- get the right direction of the new angle
local right = ang:Right( );
-- and add the direction to our vector
pos = pos + right * length;
return pos;
end
[/lua]
I hope that works. I'm gonna try it out in a bit.
Shit Coder Is Shit I Could Solve This In Five Minutes
Sorry, you need to Log In to post a reply to this thread.