Author Topic: Pitch, Yaw, Roll Formulas?  (Read 1186 times)

0 Members and 1 Guest are viewing this topic.

Offline bja888

  • Flagrunner
  • ****
  • Posts: 745
  • Working
    • Bja888.com
Pitch, Yaw, Roll Formulas?
« on: December 18, 2007, 08:09:13 am »


I want to change a tool in Garry's Mod to do something a little more useful.

The image above is like a table. The top row is the control, this is what happens if you stat the tool at (0, 0, 0).
The bottom is what happens if it does not start at (0, 0, 0). Which is where I am having the problem. The right side of the image is what happens when I use the tool to add a 45 yaw to an object that is not at (0, 0, 0). The left side is what I would like the tool to do.

Does anyone know what the formula is to make it do this?
Right now the code looks like this.

Code: [Select]

SetAngle(GetAngle() + Modify)


Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: Pitch, Yaw, Roll Formulas?
« Reply #1 on: December 18, 2007, 08:14:37 am »
I'm not entirely sure what you mean, but if you want to rotate something with respect to the center of that object you always have to translate to the center of that object first. Rotation is always with respect to a point in space. You rotate 'around' a point, which in your case is the center of the object.

So in your case it's always:
Translation of your coordinate frame to the center of the object -> Rotation -> Translation back.

I'm not familiar with the commands you have in source, but I hope that this will shed some light on your problem nontheless.
« Last Edit: December 18, 2007, 08:18:58 am by sai`ke »
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline bja888

  • Flagrunner
  • ****
  • Posts: 745
  • Working
    • Bja888.com
Re: Pitch, Yaw, Roll Formulas?
« Reply #2 on: December 18, 2007, 08:21:43 am »
So you mean something like this???

Code: [Select]

SetAngle( (0,0,0) + Modify + GetAngle() );


Edit:

This is the tool I am trying to edit...
http://www.garrysmod.org/downloads/?a=view&id=5620
« Last Edit: December 18, 2007, 08:30:36 am by bja888 »

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: Pitch, Yaw, Roll Formulas?
« Reply #3 on: December 18, 2007, 11:48:47 am »
No, I doubt that would work since I don't see any translation in the process.

Assuming you have SetAngle and assuming that it sets the angle of the object then you likely have something like setPos too, which I assume sets the object to a certain position. In that case it would be something like:

Store position into a variable using getPos.
setPos( 0,0,0 )
setAngle
and then setPos back to it's original position which you have stored in that temporary variable before you change it with setPos. But as I said I'm not familiar with the language you are using so I can't give you much more than pseudocode.

What does SetAngle do exactly?
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline Kszchroink

  • Soldier
  • **
  • Posts: 155
  • black people
Re: Pitch, Yaw, Roll Formulas?
« Reply #4 on: December 18, 2007, 12:02:37 pm »
rotating from (45,x,y) to what you want it to do would require a combination of x and y, not just x
YOU! SHOOK ME ALLLL NIIIGHT LONG - Kurt Cobain
WHO TOOK MY AVATAR I'LL FIND MY AVATAR - Kurt Cobain

Offline bja888

  • Flagrunner
  • ****
  • Posts: 745
  • Working
    • Bja888.com
Re: Pitch, Yaw, Roll Formulas?
« Reply #5 on: December 18, 2007, 07:15:11 pm »
rotating from (45,x,y) to what you want it to do would require a combination of x and y, not just x

Clearly, thats why I asked for a formula.

Offline Kszchroink

  • Soldier
  • **
  • Posts: 155
  • black people
Re: Pitch, Yaw, Roll Formulas?
« Reply #6 on: December 19, 2007, 08:09:54 am »
so what's the actual rotation of the bottom-left piece? (the one that says (+45,-45,0)(it's not that))
YOU! SHOOK ME ALLLL NIIIGHT LONG - Kurt Cobain
WHO TOOK MY AVATAR I'LL FIND MY AVATAR - Kurt Cobain

Offline bja888

  • Flagrunner
  • ****
  • Posts: 745
  • Working
    • Bja888.com
Re: Pitch, Yaw, Roll Formulas?
« Reply #7 on: December 20, 2007, 07:06:37 am »
so what's the actual rotation of the bottom-left piece? (the one that says (+45,-45,0)(it's not that))

Yes you are correct, I rotated it manually and don't know just yet. I'll see if there is a way I can get the game to output it.

Date Posted: December 19, 2007, 04:12:23 pm


(+28, -60, +320)
Thats the best I could get. I would say its accurate up to 5 degrees.

So....
Code: [Select]

function((+45, 0, 0), (0, -45, 0)) = (+28, -60, +320)

function(a, b)
{

 Formula goes here

}



Date Posted: December 20, 2007, 06:30:29 am
I also did the most obvious numbers...


(+22.5, -67.5, +315)


(+22.5, +67.5, +45)