Hot answers tagged rotation
26
You're trying to calculate the Torque. Torque depends on the applied force F, the point of application, and the center of mass of the object.
1) Center of Mass. Define the center of mass of the object.
2) Point of Application: Define the point at which the force acts on.
3) Moment Arm: The distance between the two points defined above.
Point ...
17
The standard Tetris rotation logic is called Super Rotation System. SRS is suited to high-level Tetris play, allowing for many variations on wall kicks and t-spins.
All tetrominoes exist inside a bounding square and rotate about the center of this square unless obstructed. Tetrominoes of width 3 (J, L, S, T, Z) are placed in the top two rows of the ...
16
It might be because of how the GamePad's deadzone works. It defaults to GamePadDeadZone.IndependentAxes, which means each axis is checked against the dead zone individually. This tends to cause the input to snap to each axis of the analog thumbstick. Instead, try using GamePadDeadZone.Circular:
newGamePadState = GamePad.GetState(playerIndex, ...
14
In short
You only need to change T in your SQT form.
Replace the translation vector v with v' = v-invscale(p-invrotate(p)) where v is the initial translation vector, p is the point around which you want the rotation to occur, and invrotate and invscale are the inverses of your rotation and scale.
Quick demonstration
Let p be the point around which you ...
13
The angle you need to rotate by is the the angle your velocity vector makes with the positive x-axis.
This angle can be calculated using the inverse tan of the slope of the vector. In XNA, we use the Math.Atan2 function.
Give the function the y coordinate and the x coordinate of the velocity vector (in that order). Atan2 will return an angle between +PI/2 ...
10
All of the canonical rotational formulas used to derive your rotation matrices are for rotation about the origin. If you would like instead to apply that rotation around a specific point, you must first offset the origin -- or, equivalently, move the object so the point you want to rotate about is at the origin.
Consider the 2D case first, because it is ...
9
The secret is atan2:
Vector2 exitPosition = whatever;
Vector2 currentPosition = whatever;
Vector2 direction = exitPosition - currentPosition;
float angle = (float)Math.Atan2(direction.Y, direction.X);
atan2 (MSDN) gives you the angle of a vector, with the positive X axis being at an angle of zero, and moving in the positive direction towards the positive ...
9
You'll want to get a vector based on your current velocity and heading. Then use that vector to increment your position.
//first get the direction the entity is pointed
direction.x = (float) Math.cos(Math.toRadians(rotation));
direction.y = (float) Math.sin(Math.toRadians(rotation));
if (direction.length() > 0) {
direction = direction.normalise();
}
...
9
Given only a point and a direction there is no defined 'right' or 'left'.
Imagine being a falling raindrop, which direction is right or left for you in that case?
In order to calculate (or even define) a right or left you need two directions, typically forward and up.
You seem to already have a forward direction, so you need to define a up direction.
...
8
atan2 is a mathematical function; it is stateless. There is nothing in it to “know” that you want an angle which is close to the angle from the previous frame, as opposed to an angle which is simply sufficient to identify the direction.
You must write your own logic to handle this case. There are several possible behaviors you could implement; here's the ...
7
The straightforward approach is to
find the extents of the unrotated bounding box
apply the same rotation matrix to those extents as you did to the sprite (but on the CPU, so you may need to employ your own matrix math here)
recompute the AABB of the rotated extents (which should be cheap since there are only four).
It's possible to perform the operation ...
7
If you have three sprites (or if they have very specific relative positions, which almost never happens) there is a special point called the circumcentre which is at an equal distance of each sprite. However, this doesn't scale to more than 3 sprites and doesn't work if they are aligned.
The best solution would probably be to compute the barycentre of all ...
7
Here is a way to rotate a Matrix (model) around a specific point :
Vector3 pointToRotateAround = modelWorldTransform.Translation +
modelWorldTransform.Down * modelHalfHeight; // modelHalfHeight is meant to represent distance from fbx origin to feet plane
modelWorldTransform.Translation -= pointToRotateAbout;
...
7
What you want to do is something called LERP. Stands for Linear Interpolation, and you can do with the follow:
If you know how many seconds have passed, and what is the total, you might do the follow:
u = total / passedTime
u is your "progress" variable, on a LERP.
So, as your start value is 0 and the final value is 360, we do the following:
current = ...
7
Well in the simplest sense you have something like this.
y |\
| \
m | \ s
o | \ p
v |(a) \ e
(y)e |angle\ e
m | \ d
e | \
n | \
t | \
|__________\
x movement
(x)
The speed is however fast the enemy is, and you can determine how much they ...
7
There are 360 degrees (2π radians) in a circle. Divide that by the number of objects, and that tells you the correct angle between the objects, for even spacing.
If you want to keep the objects the same distance apart no matter how many objects are in the circle, we need to calculate the distance out from the center at which points are that distance apart. ...
6
glm::quat myquaternion(glm::vec3(angle.x, angle.y, angle.z));
Where angle is a glm::vec3 containing pitch, yaw, roll respectively.
PS. If in doubt, just go to the headers and look. The definition can be found in glm/gtc/quaternion.hpp:
explicit tquat(tvec3<T> const & eulerAngles) {
tvec3<T> c = glm::cos(eulerAngle * ...
6
I'm not familiar with GLM, but in the absence of a function to directly convert from eular angles into quaternions, you can use the "rotation around an axis" functions (such as "angleAxis") to it yourself.
Here's how (pseudocode):
Quaternion QuatAroundX = Quaternion( Vector3(1.0,0.0,0.0), EulerAngle.x );
Quaternion QuatAroundY = Quaternion( ...
6
You are combining matrices for the effect.World backwards.
It should be:
effect.World = transforms[mesh.ParentBone.Index] * _orientation;
Most likely, there is some model root or local ModelMesh scaling coming from the 'transforms' (via the 3d modeling app usually). When you place the orientation first, it takes the system out of world space alignment. ...
6
You do realize that a directX camera is just a couple of matrix transformations? You have a ModelView, Projection, then Viewport matrix transformation to each vertex in that order to change the 3d coordinates to 2d coordinates.
More details about transformation along the standard pipeline (I believe DirectX and OpenGL both work the same way).
Then you ...
6
I'd suggest letting the framework do all of the work for you. Start by calculating a rotation matrix for your start and end orientations, and convert them both to quaternions. You only do this once at the start of the movement and store the values.
Matrix start = /* calculate current rotation matrix */;
Matrix end = /* calculate desired rotation matrix */;
...
6
The large gear has circumference 2πR1 and the small one has circumference 2πR2, so when the small gear has made a full circle, it has turned R1/R2 times around itself, minus one time because it turned inside the large gear (it would be plus one if the gear was outside).
So when the centre of the inner gear is rotated by angle t, the gear itself needs to be ...
5
This is due to the angle wrapping. For example, lerping from 1 degree to 359 degrees is not what is wanted, instead the equivalent lerp from 1 degree to -1 degree should be used. If the angles are in the same range, then adding or subtracting 2*pi to the target will work, e.g.
if (targetRotation > rotation+Pi)
targetRotation -= 2*Pi;
else if ...
5
The core problem in your code is probably that you pass in 0, 0 as the pivot point to rotate about in your rotate call.
For a more robust way of expressing your transformation, in linear algebra the way to rotate about an arbitrary point is to translate the world in such a way that the point is at the origin, rotate, and then translate back.
That is, ...
5
General formula for rotating around origin is
xNew = x * cos(a) - y * sin(a)
yNew = x * sin(a) + y * cos(a)
For 90 degrees it becomes
xNew = -y
yNew = x
So, firstly get brick center coordinates relatively to pivot point:
x = xBrickCenter - xPivot
y = yBrickCenter - yPivot
Then rotate them around pivot point:
x1 = -y = yPivot - yBrickCenter
y1 = x = ...
5
Frankly, I would continue to use quaternions if you are already using them and comfortable with them. It doesn't seem to me like it's worthwhile to build out a whole system -- if even it's a small one -- to handle fixed sets of rotations when you can simply do that on top of a system that handles arbitrary ones.
Furthermore, you can address the floating ...
5
You can always convert from vector to angle or vice-versa. You might want to run some tests and profile the running code to see which direction of conversion is faster, if that makes a difference.
Someone else here said you can't add or subtract a fixed angle from a vector. You actually can, of course, using matrix multiplication:
Addition of angle θ
x' = ...
5
You need to offset the gun's position based on the rotation of the player. Here's the first formula that comes to mind:
x = x + offset*cos(rotation)
y = y + offset*sin(rotation)
So in your specific case use this as the gun's position:
new Vector2( playerPosition.X + 15 * (float) Math.Cos(player.rotation), playerPosition.Y + 15 * (float) ...
5
I think your use of RigidBody physics for controlling the ship is an interesting idea (and might even be a very "correct" way of approaching this), however it's probably much easier to implement the logic yourself. In your last comment, you asked about the basic concepts:
Inertia / Momentum
Space ships have inertia, and since space is (for our purposes) ...
5
Yes!
Let's have a look at how SpriteBatch works:
SpriteBatch draws sprites onto a 2D plane. So if you had wanted to rotate your sprites so that they come "off" this 2D plane, then you'd probably have to find another solution. But, looking at your video, it looks like you want to rotate the entire 2D plane.
SpriteBatch's normal mode of operation uses a ...
Only top voted, non community-wiki answers of a minimum length are eligible