Tag Info

Hot answers tagged

31

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


18

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


15

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


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


12

What you are asking for is called Arcball rotation. Quaternions are the easy solution only if you understand how they work. You can achieve the same without quaternions however. Pre-requisites Do you know how to rotate objects in general? Let's say you have an object at the origin. Do you know how you rotate it (hint: multiply by some rotation matrix)? If ...


11

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


11

You could just store the rotations in an array like you'd store your blocks, four for each block type, then just iterate over them. That way you don't have to deal with the mess you've described.


10

Well, you'll have to use a little bit of physics, but you don't need to simulate any physics. There are formulas for pendulum motion you can easily use to set the rotation of your pendulum. For small swings, the motion can be approximated with simple harmonic motion. The angular displacement at a specific time can be approximated with: This is most ...


9

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


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


9

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


8

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


8

The basic idea is to use a cross product to generate the extra orthogonal axes of your rotation matrix, based upon the axes that you already have. Matrix3x3 MakeMatrix( Vector3 X, Vector3 Y ) { // make sure that we actually have two unique vectors. assert( X != Y ); Matrix3x3 M; M.X = normalise( X ); M.Z = normalise( ...


8

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


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


8

Conceptually, you can do that by animating the rotation of the cube (or as in Bloxorz, a cuboid) 90 degrees around one of its edges. You don't need move() at all! Side-on view of one rotation: Here's a seriously good JMonkeyEngine tutorial showing you how to rotate Boxes around pivot Nodes. It explains everything step-by-step. These are the important ...


7

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


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

The LookAt function does this for you. You may be using it improperly, or something is wrong with your steering if you're having problems with this. You can try it this way too: //find the vector pointing from our position to the target dir = (Target.position - transform.position).normalized; //create the rotation to look at the target rotation = ...


7

Conceptually you've got it, just think of the rectangle as a helper for you to deal with position and collision detection of your image. To implement it you could use: mySprite.image = pygame.transform.rotate(Surface, angle) This will give you a rotated Surface (image), then you can use: mySprite.rect = mySprite.image.get_rect() To give you your new ...


7

The simple solution is not to store the orientation of the object as angles around axes (X-, Y-, Z-axis), as for instance in euler angles. Store the orientation of the object as a matrix or a quaternion. This can cause gimbal lock, using euler angles: class Object { float m_angleAxisX; float m_angleAxisY; float m_angleAxisZ; }; No gimbal ...


7

As long as you're doing only uniform scaling, this is easy; you can simply extract each row (or column; it doesn't matter), of the 3x3 matrix. The scale factor will be the length of the row vector. If you normalize each row vector and construct a new matrix from the normalized rows, that will be the rotation part. (If you have a 4x4 matrix, you just do ...


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

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


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



Only top voted, non community-wiki answers of a minimum length are eligible