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

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

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

This is a late response, but I figured this question illustrates a common problem that many people are likely to run into and that deserves an answer. Quaternion rotation uses half the angle you want to rotate by. Since you (in this example case) are rotating by 90 degrees, the quaternion needs to calculate the sine and cosine of 45 degrees, both of which ...


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


3

This problem is called Forward Kinematics. To solve this problem in general, I recommend creating what is called a Kinematic Chain, or Kinematic Tree. To do this, you will need knowledge of a 2D rotation matrix, or transformation matrix. A 2D 3x3 transformation matrix is defined as: H = [xx, xy, tx; yx, yy, ty; 0, 0, 1]; In this case, [xx, ...


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

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

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

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

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

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

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

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

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


2

You are very much correct in your thinking that you shouldn't be using trigonometric functions where you don't absolutely need them. Particularly in cases where your calculation is using both a trigonometric method and its inverse (noting, as you do, that Matrix.CreateRotation* uses sin and cos internally). However, you need more than a single vector to ...


2

The following code conveys the intent of RandyGaul's answer translated into Xna(ease). Matrix RotationNeededToAlignArbitraryVectorWithZAxis(Vector3 arbitraryVector) { arbitraryVector.Normalize(); Vector3 axis = Vector3.Cross(arbitraryVector, Vector3.UnitZ); float partialAngle = (float)Math.Asin(axis.Length()); float finalAngle = ...


2

The method camera.rotate() (and all other transformation methods on camera) act on the current state of the camera. So if it's rotated 30 degrees, it will add more 30 degrees to the rotation. If you want to keep at 30 degrees (but still applying the transform every step), you have to make it look back at whatever it was looking before. Assuming you're using ...


2

This is a classical control problem. You want to create a feedback loop that takes the divergence from optimal position and applies the appropriate torque to nudge it back into position. btQuaternion targetOrientation = // whatever you need btQuaternion currentOrientation = myObject->getOrientation(); Getting the delta orientation is quite simple, ...



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