1. Post #1
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    I want to align a prop to a ragdoll bone. My current method doesn't work however.

    Piece of the draw method of the custom entity:
    local position, angles = ply:GetBonePosition(bone)
    local pitch = relative_angle.p
    local yaw = relative_angle.y
    local roll = relative_angle.r
    		
    angles:RotateAroundAxis(angles:Forward(), pitch)  
    angles:RotateAroundAxis(angles:Right(), yaw)  
    angles:RotateAroundAxis(angles:Up(), roll)  
    		
    self:SetAngles(angles)  
    
    Works without a problem. My problem is retrieving the correct relative angle to use in the above code.

    Currently I do this by posing the prop on the ragdoll, selecting both the desired ragdoll bone and prop (using a custom tool I made) and then retrieving and comparing their angles.

    But how do I get the correct relative angle from this? I tried [prop angle] - [bone angle], but that returns incorrect values (the prop is rotated incorrect using the custom entity).

  2. Post #2
    kevkev's Avatar
    April 2007
    1,093 Posts
    I think what you want is ent:LocalToWorld(vector) and ent:WorldToLocal(vector) ?
    Reply With Quote Edit / Delete Reply Netherlands Show Events Dumb Dumb x 1 (list)

  3. Post #3
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    I think what you want is ent:LocalToWorld(vector) and ent:WorldToLocal(vector) ?
    I'm talking about angles, not vectors. And this has nothing to do with the relativity to the world, but a relative rotation to a ragdoll bone.

    Let me put is like this.

    For the prop to be drawn in the right place, I need:
    Code:
    bone angle -> do stuff with relative angle -> result: prop angle
    If I pose a ragdoll and a prop, and retrieve their angles, I have:
    Code:
    bone angle -> prop angle -> calculate stuff -> result: relative angle
    My problem is, I don't get the correct relative angle, probably because I'm doing something wrong with the calculations.

  4. Post #4
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    Angles are a real bitch. I did some work with them a while back trying to do something similiar to what you are doing. I was trying to fake a bonemerge so weapon models would be correctly positioned. It involved getting the bone position of the player's right hand bone and getting the relative offsets of the weapon's right hand bone, then rotating and positioning the weapon model in such a way that the reference bone and player's right hand bone were in the same positions/angles in the world.

    I can probably help you with this, but not right now since I'm at school. I'll need access to a decent paint editor first to make some diagrams to help explain my process...

  5. Post #5
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Angles are a real bitch. I did some work with them a while back trying to do something similiar to what you are doing. I was trying to fake a bonemerge so weapon models would be correctly positioned. It involved getting the bone position of the player's right hand bone and getting the relative offsets of the weapon's right hand bone, then rotating and positioning the weapon model in such a way that the reference bone and player's right hand bone were in the same positions/angles in the world.

    I can probably help you with this, but not right now since I'm at school. I'll need access to a decent paint editor first to make some diagrams to help explain my process...
    I'm glad someone wants to be of assistance. I've been unsuccessful in finding the right way to calculate the relative angle so far. Tried all sorts of things. It looks as if different functions handle the angles differently (negative pitch for example).

  6. Post #6
    Gold Member
    ralle105's Avatar
    October 2005
    4,648 Posts
    You're rotating around the wrong axises.

    It should be:
    [list][*]Pitch - Right[*]Yaw - Up[*]Roll - Forward[/list]
    Hope it works now^^

  7. Post #7
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    You're rotating around the wrong axises.

    It should be:
    [list][*]Pitch - Right[*]Yaw - Up[*]Roll - Forward[/list]
    Hope it works now^^
    Nope, it doesn't. Angles are still fucked.

    I should try to reverse RotateAroundAxis math. Should be failproof...

    Edited:

    Argh, too much linear algebra. Think I'll just wait for J89.

  8. Post #8
    Gold Member
    ralle105's Avatar
    October 2005
    4,648 Posts
    Then try play around with AlignAngles

  9. Post #9
    Gold Member
    Crazy Quebec's Avatar
    May 2008
    2,449 Posts
    Can't you just do something like this?

    	local ent = ents.Create("entity_class")
    	ent:SetModel("path/to/model.mdl")
    	ent:SetParent(self.Owner)	
    	ent:SetPos( self.Owner:GetPos() )	
    	ent:Spawn()
    	ent:Fire("setparentattachmentmaintainoffset", "anim_attachment_RH", 0.01)
    	ent:SetAngles( ent:GetAngles() + Angle(0,5,0) )

    This places the model in your hand and it moves together with the hand, you can use +Angle() to rotate it on all axis. Or did I get something wrong?

  10. Post #10
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    I don't know if they're still bugged or not but objects parented to the player moved incorrectly a while back. From what I can tell the parented objects thought the player was a box rotating about it's origin and didn't take into consideration the player's bones. So you got this weird behavior that made the parented object look like it was floating around the player moving independently.

  11. Post #11
    Gold Member
    Crazy Quebec's Avatar
    May 2008
    2,449 Posts
    I don't know if they're still bugged or not but objects parented to the player moved incorrectly a while back. From what I can tell the parented objects thought the player was a box rotating about it's origin and didn't take into consideration the player's bones. So you got this weird behavior that made the parented object look like it was floating around the player moving independently.
    It still does, which is why I'm attaching it to the right hand so that it behaves properly. This works perfectly well.

  12. Post #12
    dill pickle pringle EXTREME

    May 2005
    479 Posts
    Just use the bone matrix.

    local matrix = pl:GetBoneMatrix( bone );
    matrix:Rotate( relative_angle );
    
    local angles = matrix:GetAngle();
    Reply With Quote Edit / Delete Reply United States Show Events Friendly Friendly x 1 (list)

  13. Post #13
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Then try play around with AlignAngles
    Don't think that function will be of much help.

    The drawing code is fine, it's used in all the hat scripts I've seen. The problem is calculating the right relative angle for that script to use, by grabbing the absolute bone angle and absolute prop angle (and their absolute positions, but that part of the script works fine) and doing something that will get me that angle.

    It still does, which is why I'm attaching it to the right hand so that it behaves properly. This works perfectly well.
    My code is all based on being able to align props to different bones, not only the parts that have attachments.

    Just use the bone matrix.

    local matrix = pl:GetBoneMatrix( bone );
    matrix:Rotate( relative_angle );
    
    local angles = matrix:GetAngle();
    And for relative angle I could just use [absolute prop angle] - [absolute bone angle] = relative angle?

    Edited:

    Just tried it Jinto, no dice. Angles are still way off.

    Edited:

    I really think the whole '[absolute prop angle] - [absolute bone angle] = relative angle' is incorrect.
    The calculation is:

    angle_a rotate over angle_b = angle_c

    Now I have angle_a and angle_c, how do I get angle_b?

  14. Post #14
    dill pickle pringle EXTREME

    May 2005
    479 Posts
    That's how you're calculating relative angle? My solution works in the local coordinate space of the bone. Thus your angle value needs to be in local coordinate space as well. It should be a fixed value if you want it to follow the bone. So don't don't worry about calculating an angle between the prop and bone. Just figure out some fixed value in local coordinate space and pass that to rotate.

    Example: Angle( 0, 0, -90 )

    The resulting angle after applying that to the matrix would always be the same, regardless of bone angle.

    On a side note, can you show more of your code? The code you're using to calculate the angle, etc.

  15. Post #15
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Final explanation of what I'm doing:

    First I pose a ragdoll in sandbox. I spawn a prop and place it somewhere alongside its body.


    (click to view)

    Using my own bone info tool, I select a ragdoll bone and the prop.

    It grabs the ragdoll bone angles and position using Entity.GetBonePosition( )

    It grabs the props rotation using GetAngles( )

    It then calculates the relative position and the relative angle (<- where I think the problem is) and prints this to console as a lua table. Example:

    Code:
    { model = "models//gibs/hgibs.mdl", bone = "ValveBiped.Bip01_Head1", pos = Vector(0.66467, -0.94526, 2.07958), ang = Angle(80.25862, -194.19928, 118.75885) },
    Now in my gamemode I use this table to spawn a sent that puts the 'ang' value in NetworkedAngle "angles".

    My current clientside code of this sent:

    function ENT:Draw()  
    	if (LocalPlayer() == self:GetOwner()) then return end
    
    	local ply = self:GetOwner():GetRagdollEntity() or self:GetOwner()
    	local bone = ply:LookupBone(self:GetNWString("bone"))  
    	if bone then  
    		local position, angles = ply:GetBonePosition(bone)
    		
    		local offset = self:GetNWVector("position")
    		
    		local x = angles:Up() * offset.x   
    		local y = angles:Right() * offset.y  
    		local z = angles:Forward() * offset.z 
    
    		
    		local matrix = ply:GetBoneMatrix( bone )
    		matrix:Rotate( self:GetNWAngle("angles") )
    
    		local angles = matrix:GetAngle()
    		
    		//local pitch = self:GetNWAngle("angles").p
    		//local yaw = self:GetNWAngle("angles").y
    		//local roll = self:GetNWAngle("angles").r
    		
    		//angles:RotateAroundAxis(angles:Forward(), pitch)  
    		//angles:RotateAroundAxis(angles:Right(), yaw)  
    		//angles:RotateAroundAxis(angles:Up(), roll) 
    		
    		self:SetPos(position + x + y + z)  
    		self:SetAngles(angles)  
    
    		self:DrawModel()
    	end 
    	
    end  
    

    Ingame, it draws like this:


    (click to view) (ignore the other two props sticking out of him)


    THAT is my problem.

  16. Post #16
    TomyLobo's Avatar
    April 2009
    270 Posts
    if it was entities, not physobjs, you could use that:
    Entity.LocalToWorldAngles

    or you could employ trickery and do the following:
    1. prop:SetAngles(phys:GetAngles())
    2. prop:SetAngles(prop:LocalToWorldAngles(local_angle ))
    (prop being your prop, phys being the head/arm/whatever PhysObj)

    btw: try PAC :)

  17. Post #17
    dill pickle pringle EXTREME

    May 2005
    479 Posts
    Ideally you'd want to apply the inverse of the bone matrix to the angle and position of the prop. That would give you the angle and position in the local coordinate space of the bone.

    LocalToWorld does just that, but since we can't just do it with a matrix ourselves you have two options. What the guy below said, or try the PhysObj:LocalToWorld.

    if it was entities, not physobjs, you could use that:
    Entity.LocalToWorldAngles

    or you could employ trickery and do the following:
    1. prop:SetAngles(phys:GetAngles())
    2. prop:SetAngles(prop:LocalToWorldAngles(local_angle ))
    (prop being your prop, phys being the head/arm/whatever PhysObj)

    btw: try PAC :)
    Physics objects have a local to world method as well.
    Reply With Quote Edit / Delete Reply United States Show Events Friendly Friendly x 2 (list)

  18. Post #18
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Ideally you'd want to apply the inverse of the bone matrix to the angle and position of the prop. That would give you the angle and position in the local coordinate space of the bone.

    LocalToWorld does just that, but since we can't just do it with a matrix ourselves you have two options. What the guy below said, or try the PhysObj:LocalToWorld.



    Physics objects have a local to world method as well.
    I don't quite grasp your explanation yet, or actually, where it needs to be applied. What do I need to change in the code I posted above? Is it for the part where I retrieve the angle, or the part where the sent draws it?

  19. Post #19
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    I think I understand what he's saying. To get the offset angle you grab the angles of the entity you're positioning, then choose a physics object that is attached to the bone you want to attach to, do PhysObj:WorldToLocalAngles() and convert the angle you got earlier to local angles. Likewise, get the first entity's position and then convert those to local angles with PhysObj:WorldToLocal().

    Now that you have both the local position and angles relative to the physics object, you can move an entity to that relative position at any time by doing ent:SetPos(PhysObj:LocalToWorld(localPos)) and ent:SetAngles(PhysObj:LocalToWorldAngles(localAngl es)).

    Ah, but wait, do PhysObjs have a LocalToWorldAngles/WorldToLocalAngles? I'm aware they have a LocalToWorld/WorldToLocal, but...

  20. Post #20
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Ah, but wait, do PhysObjs have a LocalToWorldAngles/WorldToLocalAngles? I'm aware they have a LocalToWorld/WorldToLocal, but...
    Nope, they don't. But isn't there a way I can just use the GetBonePosition values I retrieved from the bone, because those are (I think) the same as its PhysicsObject. I'm pretty confused because of all the local and world angles being mixed up...

  21. Post #21
    TomyLobo's Avatar
    April 2009
    270 Posts
    Physics objects have a local to world method as well.
    But not for angles, only for vectors.

    Edited:

    Ah, but wait, do PhysObjs have a LocalToWorldAngles/WorldToLocalAngles? I'm aware they have a LocalToWorld/WorldToLocal, but...
    they don't, hence you need to use SetAngles twice.
    Once to give your entity the same orientation as the bone.
    The 2nd time to set an angle local to that coordinate system.

  22. Post #22
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Argh, I totally lost it. Let's just drop the theory discussion, and show me how to improve the code:

    bone_info tool:

    -- Get both entities we selected
    -- I assume the ragdoll was selected first, and the prop next, so Ent1 = ragdoll, Ent2 = prop
    local Ent1,  Ent2  = self:GetEnt(1),  self:GetEnt(2)
    local Bone1, Bone2 = Ent1:TranslatePhysBoneToBone(self:GetBone(1)), Ent2:TranslatePhysBoneToBone(self:GetBone(2))
    
    -- Retrieve bone positions and angles
    local BonePos1 , BoneAng1 = Ent1:GetBonePosition( Bone1 )
    local BonePos2 , BoneAng2 = Ent2:GetBonePosition( Bone2 )
    
    -- DefBones is a table of strings with the HL2 bone names like "ValveBiped blablablab"
    local defbone1, defbone2
    for k, v in pairs(DefBones) do
    	
    	if (Bone1 == Ent1:LookupBone( v )) then
    		defbone1 = v
    	end
    	if (Bone2 == Ent2:LookupBone( v )) then
    		defbone2 = v
    	end
    end
    
    -- Props often have -1 as bone index, and to be sure, I just get their normal position and angles.
    if (Bone2 == -1) then
    	BonePos2 = Ent2:GetPos()
    	BoneAng2 = Ent2:GetAngles()
    end
    
    
    local relpos = BonePos2-BonePos1
    local relang = BoneAng2-BoneAng1 -- <- RELATIVE ANGLE!?
    

    Next is the SENT draw function.
    NWVector("position") = relpos (from above code)
    NWAngle("angles") = relang
    NWString("bone") = defbone1 (name the of ragdoll bone)

    function ENT:Draw()  
    	if (LocalPlayer() == self:GetOwner()) then return end
    
    	local ply = self:GetOwner():GetRagdollEntity() or self:GetOwner()
    	local bone = ply:LookupBone(self:GetNWString("bone"))  
    	if bone then  
    		local position, angles = ply:GetBonePosition(bone)
    		
    		local offset = self:GetNWVector("position")
    		
    		local x = angles:Up() * offset.x   
    		local y = angles:Right() * offset.y  
    		local z = angles:Forward() * offset.z 
    
    		local pitch = self:GetNWAngle("angles").p
    		local yaw = self:GetNWAngle("angles").y
    		local roll = self:GetNWAngle("angles").r
    		
    		angles:RotateAroundAxis(angles:Forward(), pitch)  
    		angles:RotateAroundAxis(angles:Right(), yaw)  
    		angles:RotateAroundAxis(angles:Up(), roll) 
    		
    		self:SetPos(position + x + y + z)  
    		self:SetAngles(angles)  
    
    		self:DrawModel()
    	end 
    	
    end 
    

    Please just show what you'd do with it, and I'll show the results.

  23. Post #23
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Please help me out guys!

    btw: try PAC :)
    In PAC you directly edit and preview the relative position and angles. I'm trying to retrieve these without user input (except for the posing).

    Edited:

    Also, just figured my relative position math shouldn't be as simple as BonePos2-BonePos1. It needs to be rotated around something-with-the-bone-angle too, but I'm still doing it wrong.
    Reply With Quote Edit / Delete Reply Netherlands Show Events Dumb Dumb x 2Optimistic Optimistic x 1 (list)

  24. Post #24
    Gold Member
    Deco Da Man's Avatar
    July 2007
    1,017 Posts
    You need to calculate the actual angle between the bone and the prop at the posing stage.

    PropPos and BonePos are relative to the world origin (entity:GetPos()).
    PropAng and BoneAng are relative to the their origins (entity:GetAngle()).
    Make the necessary adjustments if this is not the case for you.

    The position of the prop relative to the bone's origin:
    PropBoneRelativePos = ((PropPos-BonePos):Angle()-BoneAng):Forward()*PropPos:Distance(BonePos)

    The [angle of the prop relative to the prop's origin] relative to the [angle of the bone relative to the bone's origin]:
    PropBoneRelativeAng = PropAng-BoneAng

    The position of the prop relative to the world origin:
    PropWorldDrawPos = BoneRealtimePos+PropBoneRelativePos:Rotate(BoneRea ltimeAng)

    The angle of the prop relative to the prop's origin:
    PropWorldDrawAng = BoneRealtimeAng+PropBoneRelativeAng

    I'm pretty sure this it right. Have fun!

  25. Post #25
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    You need to calculate the actual angle between the bone and the prop at the posing stage.

    PropPos and BonePos are relative to the world origin (entity:GetPos()).
    PropAng and BoneAng are relative to the their origins (entity:GetAngle()).
    Make the necessary adjustments if this is not the case for you.

    The position of the prop relative to the bone's origin:
    PropBoneRelativePos = ((PropPos-BonePos):Angle()-BoneAng):Forward()*PropPos:Distance(BonePos)

    The [angle of the prop relative to the prop's origin] relative to the [angle of the bone relative to the bone's origin]:
    PropBoneRelativeAng = PropAng-BoneAng

    The position of the prop relative to the world origin:
    PropWorldDrawPos = BoneRealtimePos+PropBoneRelativePos:Rotate(BoneRea ltimeAng)

    The angle of the prop relative to the prop's origin:
    PropWorldDrawAng = BoneRealtimeAng+PropBoneRelativeAng

    I'm pretty sure this it right. Have fun!
    Trying it out now.

    Edited:

    Well, the angles are working! Some debug:

    Code:
    -- BONE INFO DUMP --
    Entity 1: 
    * class: prop_ragdoll
    * model: models/player/zombie_soldier.mdl
    * bone ID: 6
    * bone identified as: ValveBiped.Bip01_Head1
    * bone pos: 858.7556 -176.0274 95.4101
    * bone ang: -65.932 -54.694 -61.362
     --- 
    Entity 2: 
    * class: prop_physics
    * model: models//gibs/hgibs.mdl
    * bone ID: -1
    * bone pos: 857.8264 -175.6315 96.9188
    * bone ang: 5.230 130.374 -5.403
     --- 
    Relative info (from entity 1 to entity 2) 
    * bone pos rel: -1.5239 -0.9381 -0.3069
    * bone ang rel: 71.162 185.068 55.959
    --- DATA INFO ---
    { model = "models//gibs/hgibs.mdl", bone = "ValveBiped.Bip01_Head1", pos = Vector(-1.5239268, -0.9380709, -0.3069178), ang = Angle(71.1622619, 185.0682373, 55.9589118) }
    Draw position: 857.4528 -175.4319 94.2944
    Draw angles: 5.230 130.374 -5.403
    As you can see, the draw angles are now equal to the angles of entity 2 (the prop). But the draw position isn't! Something's still wrong with the relative bone position math, I'm sure I implemented your method correctly.

  26. Post #26
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Pretty much confirmed that the relative position calculation is not working Deco (modified my bone tool to spawn a new entity to show directly how the prop is placed, updates every Think).

    This problem is really starting to work on my nerves. Three days without real progress. :/

  27. Post #27
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    Later today I will work with you on a solution to this problem. I think I have something that should be of some use to you.

    That is of course unless you find a better way, mine isn't perfect but it should work for what you need I think. I was going to post earlier but I figured that Jinto would be able to answer your question better than I could.

  28. Post #28
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Later today I will work with you on a solution to this problem. I think I have something that should be of some use to you.

    That is of course unless you find a better way, mine isn't perfect but it should work for what you need I think. I was going to post earlier but I figured that Jinto would be able to answer your question better than I could.
    I could solve the whole problem by simply changing the way the tool works, and make it work similar to PAC: fiddle with the relative position/angle till it looks good.

    Not really what I want, and it takes away the whole challenge

  29. Post #29
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    Alright, as promised I will try to help.

    First I'll start by giving some insight into the working of 3D applications.

    Whenever a model is created, we say that it is created in "local space". This means that the coordinates and angles of everything in the model (vertices, bones, etc) is relative to a single point that I'll call the local origin.



    When the game loads a model, it is no different. The model is stored in local space. This is sort of a problem. Since all of the vertices in the model are centered around <0,0,0>, how do we display a model at an arbitrary position? How do we rotate it? What about resizing it?

    Objects in a 3D universe are displayed in the game world by transforming their coordinates from local space to world space.

    In order to do this, we need the following:
    [list][*] A coordinate in local space[*] A scaling vector <xscale,yscale,zscale> - This can be <1,1,1> for no change in size[*] A rotation angle <pitch,yaw,roll> - The coordinates will be rotated around the Z-axis (yaw), Y-axis (pitch), and X-Axis (roll) by these many degrees.[*] A position vector <x,y,z> - The model's center of local space (<0,0,0>) will end up at this location.[/list]
    The order that these transformations typically follow is like so:
    Identity (no transformations have been performed yet):

    Rotate around local origin:

    Scale outwards (or inwards if a scaling factor is < 1) from local origin:

    Translate (move) away from local origin:


    This is how we convert from Local Space to World Space.






    It follows that we may also want to reverse this process, and go from World Space to Local Space.
    To do this, we must have the following variables:
    [list][*] A coordinate in world space[*] The object's scaling vector <xscale,yscale,zscale>[*] The object's rotation angle <pitch,yaw,roll>[*] The object's position <x,y,z>[/list]

    Identity (no transformations have been performed yet):

    Backwards Translation (move backwards):

    Backwards Scale:

    Backwards Rotation:



    Normally we would use matrices which would compact all of these seperate operations into one single operation, but we do not have proper access to this kind of functionality in Garry's Mod. Therefore we'll have to do this the hard way.


    The first step is to identify two angle/position pairs. One will be relative to another.
    In this case, you probably would want the entity position/angles will be relative to a bone on the player model.

    There's no real voodoo to this part. First I'd say open up a ragdoll in Source SDK's model viewer. I've chosen barney. Go to the "Bones" tab, check the "Highlight Bone" box and find the bone you want in the dropdown box above that checkbox. You should see a cross identifying that bone:


    The point where the red, green, and blue lines emanate from is the current position of the bone. The red, green, and blue lines show the forward, left, and up vectors of the bone's current angle, respectively.

    Once you've found a bone on a model you like, make note of it. In this case, the bone I have chosen is ValveBiped.Bip01_Head1.

    I will continue this post later today. I think I messed up the order of operations - I think scaling comes first, then rotation, then translation. I'll correct this.
    Reply With Quote Edit / Delete Reply Show Events Useful Useful x 3 (list)

  30. Post #30
    Mr Affinity's Avatar
    September 2007
    526 Posts
    The way I remembered it was alphabetical order, RST Rotation Scaling Translation.
    Reply With Quote Edit / Delete Reply United States Show Events Informative Informative x 1 (list)

  31. Post #31
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    I understand the local and world position stuff, I've made it through my first year of university linear algebra (although I can't recall much of it). It's just that values I retrieve do not seem to be the kind of values I think they are. You kind of seem to confirm that in this part:
    The point where the red, green, and blue lines emanate from is the current position of the bone. The red, green, and blue lines show the forward, left, and up vectors of the bone's current angle, respectively.
    GMod has functions to grab the right vector of another vector. I do believe that my problem has something to do with this.

    The way I remembered it was alphabetical order, RST Rotation Scaling Translation.
    The order in which you do rotating or scaling doesn't matter, as long as you're doing translation last.

  32. Post #32
    TomyLobo's Avatar
    April 2009
    270 Posts
    I understand the local and world position stuff, I've made it through my first year of university linear algebra (although I can't recall much of it). It's just that values I retrieve do not seem to be the kind of values I think they are. You kind of seem to confirm that in this part:

    GMod has functions to grab the right vector of another vector. I do believe that my problem has something to do with this.
    No? Such a thing is mathematically impossible anyway.

    There is, however V:Angle(), which assumes a roll of 0 and gives you an angle, of which you can get the A:Right() axis.
    So V:Angle():Right() would probably give you what you want.

  33. Post #33
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    No? Such a thing is mathematically impossible anyway.

    There is, however V:Angle(), which assumes a roll of 0 and gives you an angle, of which you can get the A:Right() axis.
    So V:Angle():Right() would probably give you what you want.

    Right vector of an angle, my bad.

  34. Post #34
    dill pickle pringle EXTREME

    May 2005
    479 Posts
    Just found out about a global function that's just what you need.

    local localPos, localAng = WorldToLocal( propPos, propAngle, bonePos, boneAngle );
    Reply With Quote Edit / Delete Reply United States Show Events Friendly Friendly x 2Useful Useful x 1 (list)

  35. Post #35
    TomyLobo's Avatar
    April 2009
    270 Posts
    neat, thanks jinto

    Edited:

    Jinto, I started an article for this function, could you check/add any information there?
    http://wiki.garrysmod.com/?title=G.WorldToLocal

  36. Post #36
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    Just found out about a global function that's just what you need.

    local localPos, localAng = WorldToLocal( propPos, propAngle, bonePos, boneAngle );
    Ok. And now how do get propPos and propAngle back if I have the bonePos, boneAngle, localPos and localAng? You seem to have it all thought out so I rather just ask instead of spending another hour on fruitless attempts.

  37. Post #37
    Mr_Roberto's Avatar
    October 2008
    133 Posts
    Ok. And now how do get propPos and propAngle back if I have the bonePos, boneAngle, localPos and localAng? You seem to have it all thought out so I rather just ask instead of spending another hour on fruitless attempts.
    *crosses fingers* hoping this function exists:

    local propPos, propAngle = LocalToWorld( localPos, localAng, bonePos, boneAngle )
    
    Reply With Quote Edit / Delete Reply United States Show Events Agree Agree x 1Friendly Friendly x 1 (list)

  38. Post #38
    dill pickle pringle EXTREME

    May 2005
    479 Posts
    *crosses fingers* hoping this function exists:

    local propPos, propAngle = LocalToWorld( localPos, localAng, bonePos, boneAngle )
    
    Yes, it exists.

  39. Post #39
    Gold Member
    Clavus's Avatar
    September 2009
    6,283 Posts
    *crosses fingers* hoping this function exists:

    local propPos, propAngle = LocalToWorld( localPos, localAng, bonePos, boneAngle )
    
    Thanks.

    Everything now works how I want it to. Thanks everyone :)

  40. Post #40
    Gold Member
    theJ89's Avatar
    February 2005
    421 Posts
    /facepalm
    and here I was about to explain that whole transformation process.

    But basically the code implemented in LocalToWorld and WorldToLocal were what I was going to end up walking you through anyway, so it all works out. I wasn't even aware of those functions until now.

    Oh well, I hope at least that I helped someone's understanding of the transformation process at least!
    Reply With Quote Edit / Delete Reply Show Events Friendly Friendly x 2 (list)