Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 Help Me ! » mirror/rotate quaternion? » 2014-07-19 16:58:07

DeadBeef
Replies: 0

Hi everyone!

im working on a game. and i've stumbled upon kind of a strange bug. i have an object in space, and a camera that's supposed to be following it. positioning and all goes well. but the rotation is pointing the exact wrong way, so i need a way to turn it around 180 degrees on either its (local) x or y axis, but not on its z axis(which would turn the camera upside down). i really dont know this kind of math well, so i apologize in advance for being a bit unclear, if there are any questions i'll happily answer them

#2 Re: Help Me ! » Translate local vector to world vector » 2014-06-25 02:05:06

the start orientation is always as you see the ship when you log in, pointing upwards.

edit: if you take another look at the project (just register a new user if you cant remember your password. like i said, there will be hundreds of wipes) i removed the ship moving and instead placed an axisHelper. note i have set the radius, or length of the vector to a hardcoded value, i did this to make the problem more visible, it shouldnt affect the formula.

#3 Re: Help Me ! » Translate local vector to world vector » 2014-06-23 05:24:11

well this is exactly where i run into trouble. i cant explain what i dont understand. anyways, here's what's happening in the code:
i set a euler (x, y and z rotation of the ship, relative to the world, in radians) by converting quaternions.
now i need to use those angles plus a velocity to calculate the end point of the velocity vector.

i've made some minor modifications to the code, the axis you're seeing should always be in front of the ship.

if this still doesnt clear it up, i give up, cant explain it, thanks for trying tho.

#4 Re: Help Me ! » Translate local vector to world vector » 2014-06-22 02:36:48

thank you for the compliment.

well, its very much in development, the intention is to make it mmo and give the player missions to gain levels and money to modify his or her ship to become better at blowing up other ships. create alliances to work together, etc. so its not as much a simulator as it is a game, it just fits into the category space sim.

the engines are just visuals, they dont do anything but look pretty, i'm using a physics engine (cannon.js), when rotating i give the ship an angular velocity, and indeed, once an object is in motion it stays in motion unless acted upon by another force, the physics engine does this as well, i gave it friction to allow for more control (i still have to make the visuals for slowing down the ship, both velocity and angular velocity. i'm quite satisfied about the rotation and the control over it. the problem is the velocity vector of the ship, seeing as im using two angles where i should be using three, the direction is off. for simplicity's sake, lets say the ship should always be moving forward.

let me try it this way because i just cant seem to explain the problem properly, and i apologize. it feels like trying to explain something in a foreign language.
to calculate the x, and y coordinates on a circle you have only one angle:
X = radius * cos(angle)
Y = radius * sin(angle)

to calculate the point on a sphere you need at least 2 angles:
X = radius* cos(beta) * cos(alpha);
Y = radius* cos(beta) * sin(alpha);
Z = radius* sin(beta);

now i need a way to do the same, but with all 3 angles (representing the rotation of the ship). i have a feeling the answer is staring me right in the face, but i don't understand sine cosine and tangent well enough to figure it out, though im learning fast.

#5 Re: Help Me ! » Translate local vector to world vector » 2014-06-21 08:57:53

ah, ok. i cant thank you both enough for helping me!

#7 Re: Help Me ! » Translate local vector to world vector » 2014-06-21 07:47:52

ah, i think i'm starting to understand it now... then... i would need all four angles. alpha, beta, delta and gamma, the euler angles i have now make no sense then...

#9 Re: Help Me ! » Translate local vector to world vector » 2014-06-21 07:14:07

I apologize for the confusion. I'll try to clarify, but im not a mathwiz. if anything needs clearing up, please ask.

this isnt about relative vectors anymore, as anonimnystefy pointed out, the velocity relative to the ship will always be zero. so i have to find a different solution.

the ship has a rotation in quaternions. i can create a new euler and set its values to the current rotation of the ship, X, Y and Z rotation.
i need the velocity vector (relative to the world) to always point forward (relative to the ship)

so in a sense, its calculating a point on a sphere, using 3 angles, i do know how its done using 2 angles, like i described before, but there is a third angle.

perhaps if i show you the problem in action, the problem will be described better than i ever could, so here goes: http://77.174.19.60/dev/ this is the project i'm working on. (just enter a random username and pass and click register, db will get hundreds of wipes, also use a pass like 'adsfjday' because i havent gotten to encryptions yet)
now, rotation and all works perfect.
however when you havent rotated yet, the ship moves forward, like it should (by pressing the arrow keys you can control the rotation better than with the mouse) up/down also works surprisingly well, assuming you still havent rotated.
the left and right cause problems. this is because i dont calculate in the Z rotation of the ship. (it might be a bit hard to see, but the camera is chasing the ship, it should be looking at the back of the ship when you're moving for a few seconds)

the formula to calculate the vector i'm currently using is:

x = radius* cos(beta) * cos(alpha);
y = radius* cos(beta) * sin(alpha);
z = radius* sin(beta);

where the radius is the speed of the ship, alpha is the Y angle of the ship, and beta is the X angle of the ship. i need a way to calculate in the Z axis.

i hope this clarifies the problem a bit. your help and patience so far is greatly appreciated!

#10 Re: Help Me ! » Translate local vector to world vector » 2014-06-21 02:56:33

Now that you mention it, indeed. i hadn't thought of that... hmm... do you happen to know a way to calculate the velocity vector based on the objects rotation?

i tried it using 2 angles, alpha and beta, it's the only way i know how to calculate x, y, and z of a point on a sphere:
x = radius* cos(beta) * cos(alpha);
y = radius* cos(beta) * sin(alpha);
z = radius* sin(beta);

Radius in this case being the ship's velocity, and alpha and beta are the angles i adjust to rotate the vector.

however, this doesn't take into account the last rotation of the ship, the roll so to speak. and its exactly this what's been driving me nuts the past couple of days.

#12 Help Me ! » Translate local vector to world vector » 2014-06-21 00:35:20

DeadBeef
Replies: 27

Greetings geniuses and geniuses in training!

I've been working on creating a space sim, just for laughs, see how far I'd get. and i think i have reached my limit. I was hoping someone here might be able to help me out.

I have a vector relative to the player's ship representing the velocity, the local vector. now, the physics engine I'm using can only work with vectors relative to the world, so I'm gonna have to translate
the local vector to a world vector. I was hoping someone here might be able to point me in the right vector (see what i did there? ^^)

Kind regards, DeadBeef.

Board footer

Powered by FluxBB