Tag Info

New answers tagged

1

First use Zehelvion answer to make the car turn correctly, then: Use the timestamp, you measure how much time it took for your last iteration and use that to modulate the speed at which you are changing things. void RunGame(float deltatime) { if (key.KeyCode == Keys.Up) { Player1.speed += accelaration * deltatime Player1.speed = ...


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


0

This solved my problem. #pragma strict var pos1 : Vector3; var pos2 : Vector3; var objectHeight = 2.0; // 2.0 for a cylinder, 1.0 for a cube function Update () { if (Input.GetMouseButtonDown(0)) { pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5); pos1 = Camera.main.ScreenToWorldPoint(pos1); pos2 = pos1; } if ...


0

In neutral position you have defined forward to be the positive Z vector (0, 0, 1). There are two vectors perpendicular to that vector (if we ignore sign), up (0, 1, 0) and left (1, 0, 0). The easiest thing would be to create all three vectors and to apply a matrix transformation to find the left, up, and forward vector in 'camera space'. Matrix transform ...


1

The sf::IntRect that you will use will be the same for both directions. What will need to be changed is the scale of the sf::Sprite variable. You will simply need to do something similar to this: // Assumes that the image side is 24x32 and it is the first frame of the sprite sf::IntRect test(0,0,24,32); playerSprite.setTextureRect(test); if( walkingleft ...


0

From LibGDX's docs: spriteBatch.draw(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. Set flipX as true to get your desired result


2

When facing this problem I found that I wanted the character to move forward at a velocity roughly proportional to how close they are to facing the target. When facing away from our target we "turn on the spot" (Red), when facing directly towards it we walk straight towards it (Green), when somewhere in between we will may walk slowly while turning (Blue ...


0

Your top code chunk is: t2 * (t1 * direction * inverse(t1)) * inverse(t2) Your bottom chunk is: t3 * direction * inverse(t3) Given that t3 = t2 * t1 It's (t2 * t1) * direction * inverse(t2 * t1) As far as my knowledge of Quaternion multiplication goes, I don't think t2 * (t1 * direction * inverse(t1)) * inverse(t2) and (t2 * t1) * direction * ...


0

the way to create your Quaternion rotations matrices (I assume from euler angles) look funny, I would expect you use unit vectors of each axis rather than axis XMMATRIX rotateQX = XMMatrixRotationQuaternion(MathHelper::XMConvertToQuaternion(XMFLOAT3(1, 0, 0), radianRotation.x)); XMMATRIX rotateQY = ...


0

On this line: XMStoreFloat4x4(&mWorld, scaling*rotateQX*rotateQY*rotateQZ*translate); does changing the order to: XMStoreFloat4x4(&mWorld, translate*rotateQX*rotateQY*rotateQZ*scaling); make a difference? If you meant to rotate about the origin then translate outwards then you need to be careful with your ordering, though I'm making assumptions ...


2

I'd expect the conversion to be more like: static XMVECTOR XMConvertToQuaternion(XMFLOAT3 axis, float radian) { return XMVectorSet(sin(radian/2)*axis.x, sin(radian/2)*axis.y, sin(radian/2)*axis.z, cos(radian/2)); } in particular there is no need to push the coordinates through a cos and the w should be the last coordinate, there is a micro optimization ...


1

Do I use XMMatrixRotationQuaternion(XMVECTOR quaternion) and multiply the resultant Matrix with my scaling matrix and translation matrix to get my transformation matrix? I believe so. At least that's what I do with D3D9. (D3DXMatrixRotationQuaternion) You might already know but multiplication order should be : scalingMatrix * rotationMatrix * ...



Top 50 recent answers are included