Mathematics questions deal with the arithmetic, geometry, calculus, formulae and other calculations used in the development of a game.

learn more… | top users | synonyms (1)

-1
votes
1answer
71 views

Code explanation

Can someone please explain whats going on in this code written by Paul Irish I did not understand the draw(). function draw() { var time = new Date().getTime() * 0.002; var x = Math.sin( ...
0
votes
1answer
50 views

What is the optimal way to handle matrix internal data storage for interop with native graphics apis?

I'm writing a managed (c#) game engine and have stumbled on a bit of a crossroads in design/implementation regarding matrix types. Matrix types need to be optimized for marshaling to native graphics ...
0
votes
1answer
57 views

Rotating a vector around a vector in 3D space

I am trying to rotate a moon around a planet (the planet is also rotating around an axis) but I am having trouble doing so. I tried to make the model move through space like so: @Override public ...
0
votes
2answers
45 views

Bridge made out of blocks at an angle

I'm having a bit of trouble with the math behind my project. I want the player to be able to select 2 points (vectors). With these 2 points a floor should be created. When these points are parallel to ...
0
votes
0answers
20 views

Map to Screen Coordinates for isometric style map with tile height of 71 and width of 110

I am aware of the coordinates to convert map to screen coordinates and back with isometric tiles with a height and width ratio of 2:1. What I need is the same for tile width of 110 and height of 71, I ...
0
votes
2answers
142 views

How do I create a knockback-movement?

I am a web developer new to game development, and with limited math knowledge. I am writing a character movement controller in Unity. The game has an isometric Diablo-like camera. The character moves ...
2
votes
2answers
41 views

How to use “weighted average easing” correctly with variable framerate?

I often use a weighted average for smoothly animating numerical values to a target value, like so: frame(dt) { value = ((value*someFactor) + targetValue) / (someFactor+1) } As you can see dt ...
1
vote
1answer
32 views

Fit a bounding box in the scene modifying FOV

Suppose I have a radius for a spherical bounding box around a mesh. My goal is to render the scene such as when the camera moves, the bounding box whose centre the camera look at, occupies always ...
0
votes
0answers
59 views

Closest distance from 3D point to vector line

First let's have a look at my little drawing: I have an origin point p1 defined by x, y and z co-ordinates, and a vector v given by x, y and z magnitude. I also have an arbitrary point, p2, given ...
5
votes
4answers
464 views

How do I convert from the global coordinate space to a local space?

Given an entity named EntityA, I want to define a local coordinate space, where the position of EntityA is the origin, its heading vector is the X axis, and the normal of the heading vector is the Y ...
1
vote
2answers
93 views

Find point in 3D plane

I have four points in a 3D space, example: (0,0,1) (1,0,1) (1,0,2) (0,0,2) Then I have a 2D position on that square plane: x = 0.5 y = 0.5 I need to find out the 3D space point of that position in ...
1
vote
1answer
29 views

How to find the points of intersection of two OBBs

In my game I need to be able to find the points of intersection between two OBBs. I'm using Separate Axis Theorem to check if there's an intersection and get the penetration vector if there is one. ...
0
votes
1answer
23 views

Scaling entity by screen height (simulating depth on orthographic camera)

i want my entities to be at 100% scaling (for example 128x128 pixels) when they are at 40% of the screen height (for example 480 pixels at 100%), so when they are at 41%, they are at 99% scaling ...
3
votes
1answer
244 views

Explain this line segment intersection code

I've been reading this article on pathfinding over polygon meshes using line-of-sight, and in the article are several code snippets. One of them, the one I'm trying to understand, is a simple function ...
2
votes
2answers
193 views

How to make a projectile align correctly with the entity that shot it

I'm developing a 2D game. In the game, all entities can rotate 360 degrees. Each entity holds an angle value, and every frame it is drawn rotated around it's center by it's current angle value. For ...
2
votes
2answers
207 views

How can I simplify this code to compute the shortest rotation between two angles?

The following code will find the shortest rotation (in radians) (from pi to -pi) that I need to apply to from to leave me with to. Scalar rotationBetween(Scalar from, Scalar to) { Scalar fromMod ...
1
vote
1answer
30 views

XY Location scaling with varying density screens

I have a phone with resolution H=1280,W=720,Density=2 I have a tablet with resolution H=1216,W=800,Density=1.331 I drew a rectangle on my phone with corners Left,Top (-1.6,1.55), Right,Bottom ...
1
vote
1answer
67 views

How do you change movement to strafe

Right now my player can move forward and backward using case 'a':case 'A': speed.x = lx * 0.1; speed.z = lz * 0.1; break; case 'b':case 'B': speed.x = -(lx * 0.1); speed.z = ...
1
vote
2answers
66 views

How to get the normal that points *out* of a polygon

In 2D, each vector (x, y) has two normals: (-y, x) and (y, -x), pointing in opposite directions. Say I have a polygon and for each of it's edges I need to get the normal pointing outwards. In the ...
1
vote
0answers
44 views

Resolving penentration after collision using Separating Axis Thereom

I implemented collision detection in my game using SAT. The detection works, but I'm trying to use the algorithm to figure out the penetration vector of the two OBBs and push them apart (before doing ...
3
votes
1answer
82 views

How can I find the tangent and normal at an interpolated point on a Catmull-Rom/Hermite spline?

I have an implementation of a simple Catmull-Rom spline. It works, but I'm trying my hardest to be able to place vertices at extrusions along the curve. For this I need the normal (and tangent in the ...
20
votes
3answers
2k views

Are there 3D projections other than orthographic and perspective? [closed]

The question is pretty much in the title. Are there notable 3D projections other than orthographic and perspective that could be used in a 3D system such as OpenGL? In particular, are there any that ...
3
votes
1answer
54 views

Make an object follow the mouse pointer with LÖVE2D

I've been trying to make a picture follow the mouse pointer with LÖVE2D. I want that the object follow the mouse, and not just be the mouse coordinates, I did that. So I toked the distance between ...
1
vote
1answer
71 views

Predicted target location [duplicate]

I'm having an issue with calculating the predicted linear angle a projectile needs to move in to intersect a moving enemy ship for my 2D game. I've tried following the document here, but what I've ...
1
vote
1answer
29 views

Predicted target location

I'm having an issue with calculating the predicted linear angle a projectile needs to move in to intersect a moving enemy ship for my 2D game. I've tried following the document here, but what I've ...
0
votes
0answers
38 views

Equation / formula to determine an objects position on an ellipitcal path

I'm making a space game, as such I need objects to follow an elliptical path (orbit). I've worked out how to calculate all the important aspects of my orbits, the only remaining thing is how to have ...
2
votes
2answers
140 views

How can I simulate the sun's position for 3D lighting?

I'm using a directional light as a light source. It dosn't have a positon, only a direction, represented by a vec3. I'm trying to figure out how to make the light direction to simulate sun movement ...
0
votes
2answers
48 views

Convert vector interpolation to quaternion interpolation? (Catmull-Rom)

I have some existing code which does catmull-rom interpolation on two vectors (facing and up). I'm converting this to use quaternions instead (to replace the two vectors). Is there a general way to ...
0
votes
0answers
89 views

Sun & Moon Movement

I'm creating a 2D HTML5 Canvas Game and am stuck on how to go about animating my Sun & Moon. The current setup is basically setting the moon at -1024 on the X-axis and the sun at 0 and animating ...
0
votes
0answers
56 views

Using Bullet physics engine to find the moment of object contact before penetration

I would like to use Bullet Physics engine to simulate the objects in 3D world. One of the objects in the world will move using the position from 3D mouse control. I will call it "Mouse Object" and ...
0
votes
1answer
65 views

Implementing Camera Zoom in a 2D Engine

I'm currently trying to implement camera scaling/zoom in my 2D Engine. Normally I calculate the Sprite's drawing size and position similar to this pseudo code: render() { var x = sprite.x; ...
2
votes
2answers
143 views

How do I convert screen coordinates to between -1 and 1?

I'm writing a function that allows me to click on my tiles. The origin for my tiles is the center, however, the mouse's origin is the top left. I need a way to transform my mouse coordinates into my ...
34
votes
3answers
7k views

Why do we use the Pythagorean theorem in game physics?

I've recently learned that we use Pythagorean theorem a lot in our physics calculations and I'm afraid I don't really get the point. Here's an example from a book to make sure an object doesn't ...
3
votes
1answer
144 views

Most efficient way to implement delta time

Here's one way to implement delta time: /// init /// var duration = 5000, currentTime = Date.now(); // and create cube, scene, camera ect ////// function animate() { /// determine delta /// ...
4
votes
2answers
1k views

Why isn't this physics code scaling velocities separately?

I'm working my way through this book and I'm trying to work this code out: var squaredVelocity = this.velocity.x*this.velocity.x + this.velocity.z*this.velocity.z; if ...
3
votes
0answers
84 views

Learning game and effect related mathematical tricks [closed]

I'm trying to learn how to code some "effects" more succinctly. For example, I have sprite clouds in my game, and their transparency is determined with the following formula on their update-method, ...
2
votes
1answer
33 views

Can I use quaternions and do a partial multiplication?

I have some code that rotates an object around an axis. It does this by creating a quaternion for a rotation and then multiplying by the old orientation: nextRot = QuaternionRotationAxis( axis, ...
7
votes
3answers
373 views

How can I compare two quaternions for logical equality?

I'm trying to write some unit tests and realize I don't know how to compare quaternions. I need to know if two quaternions represent the same orientation (the object would be facing the same way). ...
21
votes
6answers
2k views

How can I Intercept object with a circular motion

I am creating a 2d space game and need to make the spaceship intercept a planet. I have working code for straight line intercepts but cannot figure out how to calculate the planets location in a ...
0
votes
2answers
67 views

How can I find the difference between rotations represented as angles in [0, 360]?

What is the easiest way to find the difference between two 2D rotations/directions? I want to test if one rotation is within 10° of another. I would just subtract, but there are some problems ...
3
votes
1answer
139 views

How to achieve cavalier projection using OpenGL fixed pipeline?

I want to make a quick demo program showing a cube, or a user loaded model, rotating in screen rendered with one of three projections: perspective, isometric and cavalier. Using the fixed pipeline, ...
1
vote
2answers
69 views

How do you account for zoom in a top down viewport?

I've been stumped on this for days so please forgive me if this question is in bad-form. I have a generic top-down RPG structure, and I want to create a zoomable Canvas viewport for it. I've read ...
0
votes
1answer
113 views

Integration error in high velocity

I've implemented a simple simulation of two planets (simple 2D disks really) in which the only force is gravity and there is also collision detection/response (collisions are completely elastic). I ...
3
votes
3answers
139 views

How do I disassemble a 3x3 transformation matrix into rotation and scaling matrices?

I have a transformation matrix that rotates and scales. Is there any easy way to disassemble it into the original rotation and scaling matrices? For instance: M = R * S; // I need f and h such that ...
1
vote
1answer
48 views

How to rotate vector A around another vector B?

Lets say I know what is directly above a turret. I also know where the turrets gun is currently pointing. I would like to know where will the turret's gun will point if I rotate it. I suppose I could ...
0
votes
1answer
44 views

How to tell right from left: Finding the vector pointing towards the right side of a character?

We have two vectors: Pointing from the floor to a 3d character's head. Pointing from the character towards where it's facing. How do I find the vector point from the character towards the right? ...
2
votes
1answer
92 views

How do I check why is no output on screen?

I'm using OpenGL 3.3+, and I'm trying to create an orthographic projection to draw on screen. I have the model data in a buffer: X Y 0, 0 50, 100 100, 0 And I create my Model-View-Projection ...
3
votes
1answer
77 views

What are the performance and size tradeoffs of Eigen::Transform versus Eigen::Matrix4f?

We finished migrating from DirectXMath to the Eigen math libraries for our 3D-Game Engine last week for portability reasons. After implementing transformations with matrices as we know them, we found ...
1
vote
1answer
103 views

Mixing interpolation with extrapolation in multiplayer game

I am creating a multiplayer drag racing game and have difficulties mixing extrapolation and interpolation. To save network bandwidth i am getting information from the opponent only on his button ...
2
votes
1answer
64 views

Camera roll has no effect

Consider my following (abstracted) C# w/ SharpDX code: class Game { Camera _camera = new Camera(); private void Window_KeyDown(object sender, KeyEventArgs e) { // Roll if ...