You are not logged in.

- Topics: Active | Unanswered

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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.

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

So, the ship is movong in the direction of the vector with the velocity equal to the intesity of the vector?

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

you are correct sir!

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

But, then that cannot be relative to the ship. The ship's velocity relative to the ship is 0.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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.

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Hi DeadBeef

I'm not sure what you are asking. What I understood is that you are trying to get the x, y and z component of the velocity vector. Is that correct?

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,651

hi DeadBeef

Welcome to the forum.

It's going to take me a few posts to focus in on exactly what you are asking. Here's a sphere:

I've got the x axis coming 'forward'; the y axis going to the right; and the z axis going straight up.

O is the origin; B a point on the surface of the sphere; and A the projection downwards of that point onto the x-y plane.

beta is the angle BOA; alpha is the angle AOX.

OB is the radius.

So the z coordinate of B is BA = R.sin(beta)

OA is R.cos(beta)

And hence

the y coordinate of B is R.cos(beta).sin(alpha)

and the x coordinate of B is R.cos(beta).cos(alpha)

So far so good.

Now your ship is moving on the surface of the sphere with a certain vector relative to the world (sphere).

But you don't know what that is but you do know the vector relative to .....??? And that's where I come unstuck, because I don't know what its relative to.

If we can sort that out, then, maybe, the rest is plain sailing.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Hi Bob

Are you sure it is moving on the surface of the sphere?

I am also stuck with the point of view. The only reference frame that makes sense is the world, but it doesn't seem to be so...

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,651

Are you sure it is moving on the surface of the sphere?

In a word, no. But here's the evidence: (1) to a good approximation the world is a sphere; (2) those coordinates make sense on a sphere.

What worries me is maybe DeadBeef wants to allow for the rotation of the world on its axis. I'm not going to enjoy that transformation.

I think you missed my plain sailing pun.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Those coordinates make sense because that's the way the vector can be decomposed in 3D.

I don't think it's around a world axis. It seems to be a rotation of the ship, but neither affect any coordinates, so I'm not sure what that's about.

Yes, I did miss the pun. I quite like it, unlike most people.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,651

Hhmmm. Over to the OP I think. Oh yes; nearly forgot: (3) the word 'radius' is used.

There are many opportunities for puns in English as there are so many words that sound alike but have different meanings or are spelt the same but have different meanings. Here they are mostly followed by a long groan, but I felt one was justified because of:

DeadBeef wrote:

I was hoping someone here might be able to point me in the right vector

And being a sea-faring nation, there are many nautical opportunities. Anyway, I'm signing off for a while; hopefully we'll get some clarification soon.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Well, he clarifies that "radius" refers to the velocity vector.

Also, I think you missed the word play in the last sentence of my last post.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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!

*Last edited by DeadBeef (2014-06-21 07:17:06)*

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Okay, I think I see the problem here. But, if I'm not mistaken, and I might be, you would need two more angles for the rotation of the rocket.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

two? are there more than X y and Z?

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

No, no. You will need angles gamma and delta for the rotation of the ship.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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...

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Actually, I just looked at the info on wikipedia a bit. You are right, you don't need 4 angles. Three is enough.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

please, enlighten me ^^

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Well, I think I need enlightenment myself. Your best bet is to wait for Bob, but I will try doing it in the mean time.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,651

hi DeadBeef

I'm no gamer and my programming is 'out the ark', so you'll have to excuse me if I ask obvious questions.

I've looked at your development. Nice graphics. Especially like the spinning Earth. I played with the arrow keys and observed that the space ship can be made to pitch and yaw. In space there's effectively no friction so once you start a motion it carries on until you introduce the opposite motion. I couldn't get control well enough to be certain about this.

So what is the mission? To 'home in' on the Earth and maybe land ? With the car racing games I've seen, the car graphic is fixed and the background moves, giving the illusion that you're the driver hurtling round the track. If you did the same, then all those nice graphics for the underside of the ship are wasted. On the other hand, if you don't 'move the Earth', you won't be able to home in on it.

I see four rocket engines and once started, they kept on firing for me. But in the Apollo missions they did short 'burns' and let the craft take up a new position. If I call the engines (clockwise from top left) 1, 2, 3, and 4; then I'm imagining that 1+4 will make the craft yaw to the right, and 2+3 will cancel this. 1+2 to pitch down and 3+4 to cancel that. So 1+2+3+4 would make the craft go forwards. How will it slow down/stop ?

If that's the mission I would give the player control of the four engines and translate 'burns' into movements of the background (left-right, up-down, closer). I don't see why you need quaternion rotation at all.

As you can see, I'm still not understanding the question yet. To come back to your original question, you can convert a vector into a new one that is relative to a moving point just by addition.

eg. If a train is travelling at 60 relative to the track, and a passenger walks forward along the length of the train at 3 relative to the train, then the motion of the passenger relative to the track is 63.

In general, if a point, P, moves with vector u relative to a point A; and A moves at vector v relative to point B; then P moves at u+v relative to B

At the moment, I see space fixed (including the Earth) and the ship moves relative to this. I'm assuming you want the ship to be the fixed, and space to move, so that we see the journey from the perspective of the pilot.

Over to you.

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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.

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,651

hi DeadBeef

I'm still having problems understanding exactly what is needed.

What are the three angles? How are they measured? Can you supply a diagram ?

Is the ship moving forward properly apart from direction?

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**DeadBeef****Member**- Registered: 2014-06-21
- Posts: 12

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.

Offline