In my game I can move a unit from it's current position: Vector1 to it's target position Vector2 no problem.
I want to change the target-vector using angle+distance, like this:
1. Look at a unit's position and its target position.
2. Get the angle between the vectors.
3. Rotate that angle further by 45 degrees
4. Place the target-vector in a distance of 100 from the unit's current position using the new angle.
How can I do this using Ogre-specific functionality?
[Solved] Place Vector3 by using angle and distance
-
- Gnoblar
- Posts: 3
- Joined: Fri Nov 15, 2013 8:43 pm
[Solved] Place Vector3 by using angle and distance
Last edited by galaxyjam on Sun Nov 17, 2013 4:59 pm, edited 6 times in total.
- lingfors
- Hobgoblin
- Posts: 525
- Joined: Mon Apr 02, 2007 12:18 am
- Location: Sweden
- x 79
Re: Basic question about: vector, angle, distance
Too little information...
1. Look at a unit's position and its target position.
World position? Entities' local position? Entities' parent's position?
2. Get the angle between the vectors.
What angle? Shortest? Along a certain axis?
3. Rotate that angle further by 45 degrees
Along which axis? In what direction?
4. Place the target-vector in a distance of 100 from the unit's current position using the new angle.
100 units of what?
1. Look at a unit's position and its target position.
World position? Entities' local position? Entities' parent's position?
2. Get the angle between the vectors.
What angle? Shortest? Along a certain axis?
3. Rotate that angle further by 45 degrees
Along which axis? In what direction?
4. Place the target-vector in a distance of 100 from the unit's current position using the new angle.
100 units of what?
-
- Gnoblar
- Posts: 3
- Joined: Fri Nov 15, 2013 8:43 pm
Re: Basic question about: vector, angle, distance
Further information:
We can think of this world as a 2D world top-down. I don't use y, only x and z.
1. Say I have two vectors that look like this:
2. What I mean is, the angle from vector1 directly toward vector2, like a line from vector1's position straight toward vector2's position.
3. Rotate on vector1's y, either direction + or -
4. When I say 100 I think of it in relation to the two vectors I created. Ogre::Real 100 as in a distance from vector to vector.
We can think of this world as a 2D world top-down. I don't use y, only x and z.
1. Say I have two vectors that look like this:
Code: Select all
Ogre::Vector3 vector1(0,0,0);
Ogre::Vector3 vector2(100,0,0);
3. Rotate on vector1's y, either direction + or -
4. When I say 100 I think of it in relation to the two vectors I created. Ogre::Real 100 as in a distance from vector to vector.
-
- Gnoblar
- Posts: 3
- Joined: Fri Nov 15, 2013 8:43 pm
Re: [still need help] Place Vector3 by using angle and dista
Didn't realize this was a simple math problem when I posted this.
To do this you just do:
To do this you just do:
Code: Select all
Ogre::Real current_angle = vector1.angleBetween(vector2).valueDegrees();
Ogre::Vector3 new_position(0,0,0);
Ogre::Real new_angle = current_angle+11.5;
Ogre::Real distance = 50.0;
new_angle = new_angle*(Ogre::Math::PI/45);
new_position.x = (Ogre::Math::Cos(new_angle) * distance) + vector1.x;
new_position.z = (Ogre::Math::Sin(new_angle) * distance) + vector1.z;