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)

0
votes
0answers
66 views

Tool or an approach for (semi) automatic generation of impossible figures? [on hold]

I'm interested in this subject for educational purposes. I myself was unable to get neither existing software nor an understandable document on how to implement one. The only most complete things I ...
1
vote
1answer
24 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
52 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 ...
4
votes
4answers
428 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
90 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 ...
0
votes
1answer
24 views

How to find the points of intersection of two rectangular OBBs

In my game I need to be able to find the points of intersection between two rectangular OBBs. I'm using Separate Axis Theorem to check if there's an intersection and get the penetration vector if ...
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 ...
0
votes
0answers
72 views

planning a spaceship path (possibly bezier curves)

Given a spaceship with a current position and velocity, I'm trying to plan a path to a given destination point, so that I can show a line plotting the course taken by the ship. It's in space so drag ...
3
votes
1answer
230 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
186 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
201 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
25 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
65 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
37 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 ...
1
vote
0answers
40 views

Understanding vector projection [migrated]

I'm learning about vector projection. I understand how to perform it, but I still can't understand what it actually means and what it gives me. Here is a common definition: Vector projection of a ...
3
votes
1answer
69 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
46 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
70 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
26 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
36 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
126 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
43 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
85 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
46 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
55 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
142 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
139 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
83 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
361 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
63 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
132 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
63 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
108 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
121 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
44 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
42 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
85 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
69 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
98 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
63 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 ...
0
votes
0answers
60 views

rotating sprite with quaternion in scenegraph

I have been trying to set up a scenegraph in XNA, which I then use to draw sprites in the correct places. It uses matrix transformations to accomplish this. So far, I got position and scale working ...
0
votes
0answers
31 views

How to calculate positions and randoms in scene. SpriteKit [duplicate]

So here is a code : static inline CGFloat randomInRange(CGFloat low, CGFloat high) { CGFloat value = arc4random_uniform(UINT32_MAX) / (CGFloat)UINT32_MAX; return value * (high - low) +low; } ...
0
votes
3answers
62 views

How to find the total bounds rectangle around a list of rectagles

Rectangle object: a simple data structure of 4 floats (w,h,x,y). I have an array of 2 or more rectangles and want to create a rectangle that surrounds all of them: The result rectangle, calculated ...
1
vote
2answers
100 views

Find closest point from an origin, in a mesh

I want to do something similar to a raycast. With a raycast, you can set an origin and a destiny, and check where the ray collides with something but only with a line. What I want to do, is given an ...