• Prop vectors and angles question
    1 replies, posted
In an attempt to understand prop vectors and angles (and how local and world relate), I've been making a little client side draw function that extends X, Y and Z axes from a PHX prop. [CODE] function ENT:drawAxes() render.SetMaterial(Material("cable/cable2")) -- X local beamStart = self:LocalToWorld(Vector(0, 0, 0)) local beamEnd = self:LocalToWorld(self:GetLocalAngles():Up() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(255, 0, 0, 255)) -- Y local beamStart = self:LocalToWorld(Vector(0, 0, 0)) local beamEnd = self:LocalToWorld(self:GetLocalAngles():Right() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(0, 255, 0, 255)) -- Z local beamStart = self:LocalToWorld(Vector(0, 0, 0)) local beamEnd = self:LocalToWorld(self:GetLocalAngles():Up() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(0, 0, 255, 255)) end [/CODE] What I'm seeing is that when I rotate the prop, rather than rotating in the direction of the prop rotation, the axes I drew are rotating around different ways. My understanding is: - I get the local vector representing the center of the prop. - I convert this local vector to a world vector, so I know where the center of the prop is in the world, and start my beams from there. - I get normalized forward (X), right (y) and up (z) local vectors representing the axes of the prop. - I multiply these by 10, so they end 10 units away from the prop center on the given axis. - I convert these end points to world vectors so I know where they are in relation to the world. - I draw the visual representation of the axes using the world coordinates I've just calculated. So, what have I gotten wrong? My vector/angle understanding, my code, or both? Thanks in advance. On a side note, I couldn't find anywhere how to syntax highlight my code on here.
Figured this one out myself when I took a fresh look, and realised I'd gotten myself confused. I've more or less gotten a grip of the whole world/local stuff now. [LUA] function ENT:drawAxes() local beamStart = self:GetPos() render.SetMaterial(Material("cable/cable2")) -- X local beamEnd = self:LocalToWorld(self:WorldToLocalAngles(self:GetAngles()):Forward() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(255, 0, 0, 255)) -- Y local beamEnd = self:LocalToWorld(self:WorldToLocalAngles(self:GetAngles()):Right() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(0, 255, 0, 255)) -- Z local beamEnd = self:LocalToWorld(self:WorldToLocalAngles(self:GetAngles()):Up() * 10) render.DrawBeam(beamStart, beamEnd, 2, 1, 1, Color(0, 0, 255, 255)) end [/LUA]
Sorry, you need to Log In to post a reply to this thread.