Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Vector3D & Quaternion 1.75.3, odd results.

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Vector3D & Quaternion 1.75.3, odd results.

Post by Frame »

using vector3D and Quaternions for my turrets for the Polaris class destroyer has revealed some odd behavior

Code: Select all

quaternion.rotateZ(angle)
can be rotateY or rotateX instead, but it
seems to rotate the quaternion about some to me undefinable axis doing this on screen
via debug console seems to makes a rotation of 90 degree turn, = 5156.620156177409 rad do 12 turns before it is in the same position again.. ofcourse this should only be 4 turns..

however, my turret tracking code, rotated the turrets odd away from me

so instead i tried to use quaternion.rotate(vector,angle)... however just entering
a vector like this

Code: Select all

quaternion.rotate(0,1,0,5156.62~)
will produce an error since

Code: Select all


let aVector = new Vector3D()
//then later....
aVector = (0,1,0)

willl seem to destroy the vector and make it a plain number , in this case zero.

while setting the vector at initialization time will work fine and therefore buoy repair is in the clear..

is all this expected behavior ? or one or two a genuine bug/s.

with a "good" vector Q.rotate(vector,angle) works fine.. and producing very different results than Q.rotateY/X/Z(angle)

Cheers Frame...
Bounty Scanner
Number 935
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Frame »

surely i'm mistaking, in the above is probably fine as it seems i'm rotating my turrets the wrong way.. i should use

Code: Select all

turret.orientation = turret.orientation.rotate(turret.position.direction(),angle)
I did fall upon this by scrutinizing the buoy repair code , as i went , i fugured, if the position is not a heading then what is, and Direction was a very likely candidate
Bounty Scanner
Number 935
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Frame »

oh again my mistake...

it should be

Code: Select all

kl = new Vector3D
kl = ([0,0,0])
then setting the vector is fine.. I was just a bit focused on the wiki in the quaternion sections that incorrectly say

Code: Select all

q.rotate(0,1,0,Angle)
should be

Code: Select all

q.rotate([0,1,0],Angle)
correcting that now..

Cheers Frame
Bounty Scanner
Number 935
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8512
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by DaddyHoggy »

I'm posting this just to stop you talking to yourself!

Well worked out, btw!
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Thargoid »

I actually came across this one myself last week. I think the rotateX etc are about the universal X/Y/Z axes (ie the ones of the system itself) which in practical terms is next to useless.

If you use rotate around a known ship axis (e.g. this.ship.vectorForward) then it seems to work fine, as you've discovered.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Eric Walch »

Frame wrote:
I was just a bit focused on the wiki in the quaternion sections that incorrectly say

Code: Select all

q.rotate(0,1,0,Angle)
should be

Code: Select all

q.rotate([0,1,0],Angle)
correcting that now..

Cheers Frame
Thank for correcting. At the time that part was written, it was correct, but it was now wrong after a change, a long time ago. This must just have slipped through.

Ans as you noticed, the rotations around the Z-axis mean the system z-axis, and not the ships z-axis. I think they are pretty useless for manipulating ships and are only added to make the tools complete. There were more vector/quaternion commands I thought were useless and that I am using now. So, on writing it is difficult to see what is useful and than better add ten methods to much than one short. :P
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Frame »

Eric Walch wrote:
Frame wrote:
I was just a bit focused on the wiki in the quaternion sections that incorrectly say

Code: Select all

q.rotate(0,1,0,Angle)
should be

Code: Select all

q.rotate([0,1,0],Angle)
correcting that now..

Cheers Frame
Thank for correcting. At the time that part was written, it was correct, but it was now wrong after a change, a long time ago. This must just have slipped through.

Ans as you noticed, the rotations around the Z-axis mean the system z-axis, and not the ships z-axis. I think they are pretty useless for manipulating ships and are only added to make the tools complete. There were more vector/quaternion commands I thought were useless and that I am using now. So, on writing it is difficult to see what is useful and than better add ten methods to much than one short. :P
well rotateY/X/Z are not entirely useless if you use them on subEntities as these use a local coordinate system defined by the axis of the model. This is only useful for visuals, if you want to use it for anything interactive such as turrets, its annoying since i then have to operate on 2 virtual orientations as well for articulated turrets..

And for some reason my turret code has become unstable, still trying to find out why.. it happened when i was adding the 2nd virtual axis for the horizontal moving barrels.

Cheers Frame...
Bounty Scanner
Number 935
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Eric Walch »

Frame wrote:
well rotateY/X/Z are not entirely useless if you use them on subEntities as these use a local coordinate system defined by the axis of the model. This is only useful for visuals, if you want to use it for anything interactive such as turrets, its annoying since i then have to operate on 2 virtual orientations as well for articulated turrets....
I was thinking that rotations around the system axis were useless for ships that are in random orientation. but I am wrong. I just noticed that Oolite internally is using it heavily for ships:

Code: Select all

- (void) applyRoll:(GLfloat) roll1 andClimb:(GLfloat) climb1
{
	Quaternion q1 = kIdentityQuaternion;

	if (!roll1 && !climb1 && !hasRotated)  return;

	if (roll1)  quaternion_rotate_about_z(&q1, -roll1);
	if (climb1)  quaternion_rotate_about_x(&q1, -climb1);

	orientation = quaternion_multiply(q1, orientation);
	[self orientationChanged];
}
In JS words for a roll:

Code: Select all

var Q = new Quaternion(1,0,0,0)
Q = Q.rotateZ(roll)
ship.orientation = ship.orientation.multiply(Q)
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Frame »

nice!!, also i found my error and corrected it, and now got a visual tracking base turret with a corresponding vertical barrel tracking hostile ships. Barrel seems to go a bit off target though, it may need a tighter tolerance in dot product, that is now +- 80.

adding its weapons now..


*ordinary plasma gun turrets "shiver". I presume these are aiming in some of the same way that mine does, that will also shiver if i give them a higher degree of motion pr allowed frame than is possible to aim within a set tolerance.

Cheers Frame..
Bounty Scanner
Number 935
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Vector3D & Quaternion 1.75.3, odd results.

Post by Eric Walch »

Frame wrote:
*ordinary plasma gun turrets "shiver". I presume these are aiming in some of the same way that mine does, that will also shiver if i give them a higher degree of motion pr allowed frame than is possible to aim within a set tolerance.
One can reduce the "shiver" by making them turn slower by lowering the thrust setting.

For the random hits station it helped strongly to stabilise them on my computer. But, I can imagine that the effect also depends on the FPS value.
Post Reply