Tag Info

Hot answers tagged

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


7

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


6

The problem with rotations, is that, most people think of it in terms of Euler angles, since they are easy to understand. Yet most people forget the point that Euler angles are three sequential angles. Meaning that rotation around the first axis, will make next rotation be relative to the first original rotation, hence you cannot independently rotate a ...


5

You could always deploy a type of Linear Interpolation. This allows you to slowly move to the target rotation over time and make it look decent. If I'm misunderstanding and you simply want the angle between the two vectors, you might want to first normalize them (as you have done) and then simply take the dot product and angle. You can find a StackOverflow ...


5

Each orientation in 3D space can be represented by 2 distinct unit quaternions, q and -q (component-wise negated q). For instance the orientation represented by the 3x3 identity matrix I can be represented by 2 quaternions: q: { 0, 0, 0}, 1 -q: {-0, -0, -0}, -1 Both represent the same orientation in 3D space, their dot product is exactly -1, each of ...


4

Roy T. suggested to fix this changing the texture filtering settings, On LibGDX this can be found on Texture.setFilter or changing the Texture Params if you are using the AssetLoader. Set the filter params to TextureFilter.Linear and the problem should be fixed. For more on the matter, take a look at ...


4

1: Simple physics There will be a subtle difference in drag on either side*, because the side rotating into the wind will have greater dynamic pressure than the one that rotates with the wind. For an arbitrary shape, this will be somewhat difficult to calculate (although possible) for correct physics. You should not try, and approximate it instead. This ...


3

Here is a no-trig calculation, derived from straight-forward Grade 11 Trig and Physics. It assumes that the origin is the lowest point of the pendulum bob's suspension, that L is the length of the pendulum, and that the normal graphics convention of y increasing down, and x increasing to the right is adopted: Update: I messed up yAcceleration initially; ...


3

Your formula is correct. I would suggest normalising the quaternion at the end, though, or any stage involving interpolation will likely be messed up. What I believe is happening is that your up vector is (0, something, 0) and your normal vector is (0, -1, 0). In this very specific corner case (when the input vectors are opposite to each other) there is no ...


3

You can extract the translation by removing the top three elements of the fourth column, (1,4), (2,4) and (3,4); You can determine the scale by finding the determinant of the top-left 3x3 elements. The determinant of a plain rotation matrix is 1, so any value above or below that is the scale factor. Note that this is only true for uniform scale; per-axis ...


3

Assuming direction is the desired rotation angle to turn toward, just subtract direction - rotation and wrap the result into the [-pi, pi] range. Then its sign should indicate the correct direction to turn. There's no need to munge it through any trigonometric functions.


3

It sounds like you're just getting the order of your matrix operations wrong. Assuming you have a circular collision volume you just want to make sure you rotate your sprite on it's centre axis. To do that you have to first have your sprite centred in the screen either by translating it to the centre or drawing it about the centre. Then you rotate it ...


3

It’s important to note that changing the co-ordinate system with rotate and translate do not affect anything that’s currently drawn into the canvas. It only affects subsequent drawing actions. var TO_RADIANS = Math.PI/180; function drawRotatedImage(image, x, y, angle) { // save the current co-ordinate system // before we screw with it ...


3

The simplest way to handle rotating 2D collisions is to use circles instead of rectangles. For most practical purposes, circles are a good approximation, simple to implement, and nobody will be able to tell the difference anyway. Two objects are colliding if the distance between the centres (using Pythagorean theorem) is less than the sum of the radiuses.


3

Simple Solution If you want the body to instantly rotate just call Body::setTransform and pass the current position and the desired angle, don't bother applying torques or anything. The function call could be something like this: body.setTransform(body.getPosition(),myDesiredAngle); Physics Solution If you want the player body to interact with bodies ...


2

Since you're dealing with arrays, there doesn't have to be any actual rotations. You're just moving data around inside the arrays. For example imagine the top loop of such an array. It combines 4 of those 2D arrays into a strip. Like so: The coordinates represent the 3D position of the cube being represented. There are of course duplicates for the corners ...


2

To rotate the look of a material (this will apply to all instances of that material): Open the material in the Material Editor. Find the Texture Sample node you want to rotate. Create a Rotator node and leave the default values in. Connect the Rotator to the UVs of the Texture Sample. Create a Constant node. Connect the output of the Constant to the Time ...


2

I think you are misinterpretting the result of setting the origin to (0.5f, 1). I did the same thing, and I got the expected results. Here's a modified version of the code I ran at this answer: Color[] colors = new Color[] { Color.White }; texture = new Texture2D(GraphicsDevice, 1, 1); texture.SetData<Color>(colors); spriteBatch.Draw(texture, new ...


2

As Martin Sojka notes, rotations are simpler if you convert to a different coordinate system, perform the rotation, then convert back. I use a different coordinate system than Martin does, labeled x,y,z. There's no wobble in this system, and it's useful for lots of hex algorithms. In this system you can rotate the hex around 0,0,0 by “rotating” the ...


2

if you see the draw, I think is easier to understand. You should have a ship position that is the same for the blast, and you have two sprites with different sizes. You should realize the rotation is related to the origin, so you have to pair the rotation origins. The yellow circles are the origins for each sprite: a) Ship: You have to sure that the ...


2

To illustrate, look at this image generated by Wolfram Alpha: You have your 3 local coordinate axes and you want to coincide any of them with a given forth vector (for instance (1/2, 1/2, 1/2) as in the image). To do that, you need to rotate your object. A rotation is best described as a combination of an angle and axis to rotate around. So how do we find ...


2

Doing that is possible, though I imagine insanely difficult, and since there is a better way, unnecessary. I'm also assuming that your using OpenGL 2.1, since glRotate was deprecated in OpenGL 3.x. So, Using OpenGL 2.1, instead of reversing the matrix from your physics API, I suggest you just plug that matrix straight into OpenGL. This can be done with ...


2

Instead of drawing the rotated image out to another image where you then draw that image out to Graphics to be displayed... why don't you draw directly to that Graphics object? This way it saves ALOT more time and doesn't waste memory. Graphics2D g2d = ... AffineTransform backup = g2d.getTransform(); AffineTransform trans = new AffineTransform(); ...


2

As Byte56 noted in a comment, you should just be able to read the object's current orientation (i.e., its rotation matrix) off of the gyroscope, and the problem is much easier to solve that way. Regardless of how you have the object's orientation, the key is to find the 'transformed' version of whichever axis (presumably Y or Z) corresponds to your upwards ...


2

You can do this by creating the vertices for a sphere using one of the algorithms from this question, then you can orbit around it using the strategy described here. If you should use an engine or not isn't really something we can answer here. It depends on how long you want to spend creating the required functionality yourself. Typically, it's recommended ...


2

This gives me a nice slow rotation. But I am clueless how to tell Unity to stop at +30 degrees, reverse to -30 degrees, rotate again to +30, stop and repeat, etc, etc. I suggest you to use coroutines for that. There are several ways of course of doing that. The code could look more or less the following: IEnumerator LoopRotation(float angle) { ...


2

No, usually you don't undo transform by applying inverse. Because precision errors love to accumulate. Instead, either precalculate desired transform and set it directly, or reset current transform to identity and start over. This answer is api-agnostic. If there is way to manipulate current transform, then should be also way for resetting it. (I am not ...


2

Each corner should be rotated around the center of the box. Typically this would be done by translating the box back to the origin, rotating, then translating back to the starting position. Imagine the points that make up the corners rotating around a circle: For rotating each point, see this answer.


2

I'd project the rotationDirection into the horizontal plane before you normalize it, something like... var rotationDirection = transform.position - rayHitPoint; rotationDirection.y = 0; rotationDirection.Normalize (); rotationTarget = Quaternion.LookRotation (rotationDirection); Note that the order of the subtraction used ...


2

It is actually supposed to be simple. There is an invisible anchor bullet moving like a normal game bullet would in a straight line (implementation not included). You have the angle alpha in which the anchor bullet is moving and its position px & py. You also have the amplitude (how far does the sine wave expands) and it's frequency (how fast does it go ...



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