Tag Info

Hot answers tagged

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

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


5

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


5

Start by adding a variable for the angle that the car is moving at. float angle = Math.Pi / 2; Then add a variable for the current speed. float speed = 0.0; Now create three constants: public static final float acceleration = 0.1; public static final float maxSpeed = 5.0; public static final float rotationRate = Math.Pi / 50; For starters, get your ...


4

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


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


4

If I understand correctly, you have three points A, B, C, and three points P, Q, R and you would like to know the affine transform (i.e. preserving distances) that transforms the first set into the second set. Finding the transform is straightforward; you just need to create two orthonormal bases from your sets of points, fill matrixes with the basis ...


4

To get a value inside [-pi,pi], you can add pi, do fmod, and subtract pi again. Here is one way that works. Unfortunately you still need to somehow test whether from - to is positive or negative before calling fmod: Scalar rotationBetween(Scalar from, Scalar to) { return (from > to) ? -pi + std::fmod(from - to + pi, pi * 2) : ...


4

All 3D rotation must occur about some axis. That's what 3D rotation is. However, not all such rotation occurs about the Z axis. Rotation can be about any axis: X, Y, Z or an arbitrary axis not aligned with any of the principle axes of the coordinate system. What it sounds like you're referring to is the convention of rotating 2D shapes in a 2D plane about ...


4

Create an empty gameobject, make it child of your gameobject. Move it to one of the corners you want to rotate about, Use RotateAround to rotate your gameobject. You could also do the same through code by calculating the dimensions of your gameobject. Edit: You could use these scripts to make your life easier: PivotManager, SetPivot.


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

Update: This was much harder to solve than I thought. However, I think I managed it to fix it, after trying 5 different approaches. So, the requirements really are that you have 3 source points and 3 corresponding destination points. And that you are sure that the distance between the points is conserved. And finally that the source points define a plane. ...


3

First of all: most computer trigonometric functions takes radians as input. Even if the code worked, I am 99% sure it will not rotate by 90 degrees. So if it is that case, try changing it to pi/2. Secondly, if you would rotate by not-multiply of 90 degrees - the code would still produce axis-aligned rectangle (bounding box), NOT rotated rectangle as you ...


3

Not sure if this is the most performant, but it can be visualized easily: //assuming you're starting with a relatively orthonormal matrix 1.) Take one of your matrix's 3 basis vectors and dot it against the 6 world orthogonal vectors and set it to the one whose result is closest to 1.0. 2.) Do the same for one of the 2 remaining basis vectors. 3.) Cross ...


3

One way to do it is to keep track of the Front and Up normalized vectors and transform the front vector whenever your character turns, and calculate the Right vector using cross product ( I am assuming Up vector won't rotate). Or you can keep track of the three vectors and rotate them. Once you rotate them you update the position by adding the offset in the ...


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

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


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

As hinted by user concept3d, it is difficult to help you without further details about your implementation approach. I'm going to give it a shot nevertheless, but that means that I have to make some assumptions that may or may not be true for your code. In any event, I hope that the following is general enough that you can adapt it if necessary. The first ...


2

There are different ways to represent angles and you didn't mention which you use. So let's assume that you represent the directions of angles measured in Radiants between 0π and 2π and any angles outside of that allowed range are automatically transformed back into it by adding/subtracting 2π until they fit again. When the difference between this.angle and ...


2

Move your sub-components from the centre of mass to the pivot point: Find the centre of mass of your object. Compute the vector between your centre of mass and the pivot point of your object. Use that vector to move your cubes so that the centre of mass of your object is at the same place of the pivot point of your object. Perform your rotation. (Also ...


2

When measuring performance, use frame times, rather than FPS. In your case: 1000 ms / 80 FPS => 12.5 msec/frame 1000 ms / 100 FPS => 10.0 msec/frame These are very even FPS numbers, which makes me suspect that they are tied to the display vsync. Have you tried disabling vsync (with a call like eglSwapInterval, or setting the Direct3D swap interval? ...


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

You're going to have tons of questions regarding 3D math so I recommend you get the book Essential Math for Game Programmers, the 2nd Ed. I bought a copy myself and was reading it last night before bed. http://essentialmath.com/book.htm For your specific question you can use a rotation matrix to represent your object's orientation. You can concatenate this ...


2

OpenGL 1.x's built-in matrix operations are notoriously slow, and may even cause pipeline flushes in some cases. To gain performance, translate your gl matrix operations to client-side code (there are several solutions, http://glm.g-truc.net/0.9.5/index.html and http://cmldev.net/ being popular ones). If you already have a lot of code, you can easily write ...


2

Looks like you got some very big rounding errors in there. I have no idea why but I have written some code for matrix rotations once. It's in Java though but should be very easy to translate to C++. Vector class: http://pastebin.com/Cy0DYk6p Matrix class: http://pastebin.com/WRECLRjz When I test it with this code Matrix m1 = new Matrix(new Vec(-1, -1, ...


2

You can apply the transformation matrix to a point and calculate the orientation and the scale from it. This of course only works if there are no other transformations than that. Vec2 scale; Angle rotation; Vec2 point(0, 1); point = matrix.apply(point); scale.Y = point.length(); rotation = AngleBetween(point, Vec2(0, 1)); Vec2 pointX(1, 0); pointX = ...


2

Let's see what is happening. float dx = (float) (5 * Math.cos(direction) + 40 * Math.sin(direction)); float dy = (float) (5 * -Math.sin(direction) + 40 * Math.cos(direction)); So facing right, dx = 40, so cos(direction) = 0 sin(direction) = 1. dy = -5 for the same reasons. 0,0 is top left. This means that direction = pi/2. This is unusual, normally ...


2

The libgdx-utils library has a Box2DSprite class that takes care of all the difficulties in synchronizing the appearance with the physics body. It may be helpful to either use this library or see how they implemented the functionality you are looking for: bitbucket.org/dermetfan/libgdx-utils/wiki/Home Example: bodyDef.position.set(4f, 8); ...


2

The direction of the force applied to a point colliding with your rotating object is the tangent to the sphere, perpendicular to the axis the sphere is rotating on. You should be able to calculate it with the following pseudo-code: vectorToContact = (pointOfContact - centerOfSphere); directionOfForce = normalize(cross(vectorToContact, axisOfRotation)) A ...



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