First of all, it's way less clutter. If you have a position, a velocity and an acceleration, that's already 6 variables you have to deal with, 9 in 3d.
Secondly, and this is the most important part, it grants you access to many ways to use or change them. For instance, getting the length of the vector, normalizing it, adding them together, dot product, ...
The answer is actually pretty easy if you do the math. You have a fixed distance of Y and a variable distance of X (See Picture 1). You need to find out the angle between Z and X and turn your turret that much more.
Step 1 - Get distance between the turret line (V) and the gun line (W) which is Y (this is constant but doesn't hurt to calculate). Get ...
Yes, To name a few:
The Pannini projection, for example, can capture wide fields of view in nice ways. (totally just my opinion)
I think implementation details would be beyond the scope of this specific question.
EDIT: Thanks for the comment, I did misspell Pannini. And to make this edit worthwhile here are a few more:
I always forget how to do this when I need it so I wrote a couple of extension methods.
public static Vector2 PerpendicularClockwise(this Vector2 vector2)
return new Vector2(vector2.Y, -vector2.X);
public static Vector2 PerpendicularCounterClockwise(this Vector2 vector2)
return new Vector2(-vector2.Y, vector2.X);
It depends on what you mean by "that could be used in a 3D system such as OpenGL". :)
Narrowly speaking, 3D graphics hardware and APIs like OpenGL only deal correctly with linear projections - projections that map straight lines in world space to straight lines on the image. They never distort something into a curved shape (unless it was curved to begin ...
Compare the function signatures of both RotatePoints versions.
const float *in_x,
const float *in_y,
float s = sinf(angle);
float c = cosf(...
How is Matrix Multiplication a Transformation?
A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers.
In games, we usually want to construct a matrix so that, when multiplied with a list of numbers representing a source position (say, the position of a vertex in a mesh) we get a list of ...
First we get a vector from B to A, as in the following picture:
Now we have a vector that tells us how to get exactly from B to A. In code it looks something along these lines:
var BtoA = A - B;
In the above image's case, the resulting vector is X:15 Y:-20. At this point we actually already know the direction, as it is included in the information of how ...
Readability > Writeability
I feel like it's just slow me down and barely has any benefit other
than organizing your code.
You are correct in that it (slightly) slows you down writing that code. However, you write it once in the beginning and from then on everytime you come back you are going to read it. So optimizing the reading speed will do much more ...
Vector3 vT = v2 + headingNorm * 3;
Be careful though, if v2 and v1 happen to be closer than 3 units away this will put you on the far side of v1. Maybe you want this to make the unit step back to make room for the attack. But then again be careful, because that means as you approach that attack point you will overshoot then correct and overshoot the ...
A 2D vector has two values (x and y), and it basically says how far you go from the point of origin in the x- and in the y-direction. For example, a vector of (3,4) goes 3 units in x direction and 4 units in the y direction, resulting in an angled line with a length of 5 (3² + 4² = 9+16 = 25, root of that is 5). So the vector basically gives you two pieces ...
Calculate a vector from B to A, normalize it (divide by the vector's length), then multiply by the circle size:
vx = A.x - B.x
vy = A.y - B.y
length = sqrt(vx*vx + vy*vy)
C.x = vx / length * size + A.x
C.y = vy / length * size + A.y
For the angle you can use the atan2 function, if your language has it.
Vector v3 = v2 + v1;
There is now only one place in your code where you have to write, test and debug vector addition, as opposed to tens, hundreds or thousands.
Obviously vector addition is an overly simplistic example, but there are more complex vector operations and the same applies to those too.
Linear transformations preserve:
Collinearity. If three points are collinear before the transformation, they remain collinear afterwards.
Parallelism. If two lines are parallel before the transformation, they remain parallel afterwards. This implies that a grid will remain a grid after the transformation.
The Origin. The origin point will be the origin ...
I thought this would be an interesting challenge to test some of the math I learned in school, so here's what I figured out.
This approach assumes each object can be considered a circle for collision purposes. Naturally a car isn't a perfect circle, but it could be used as an approximation. You could use more circles to fill the area of the car better if ...
To get a transformation matrix equivalent to the one you have, but reflected across a major axis you can compose it (multiply it by) a reflection matrix.
That is, if you have your input matrix M and you multiply by a matrix N that has the reflection.
To create the reflection matrix based on the major axis, you take the identity matrix and flip signs ...
Here is my suggestion. You just need two vectors.
in the first triangle, choose the normal vector, n1
in the second triangle, choose a vector e2 from a point on the shared edge to the point not on the shared edge.
Then compute their dot product: n1 . e2. If it’s positive, the angle is acute. If it’s negative, the angle is obtuse.
This answer still ignores the attempt to use matrix rotation, but I realized that there was a simple yet general solution.
First, assuming that the shape is encoded as coordinates of blocks in a grid, you have an arbitrary shape containing blocks with coordinates in the X and Y axes from 0 to n, where n+1 is the maximum size of a block (traditional Tetris ...
If your transformation matrix is a rotation matrix then you can simplify the problem by taking advantage of the fact that the inverse of a rotation matrix is the transpose of that matrix.
If your transformation matrix represents a rotation followed by a translation, then treat the components separately. The inverse is equivalent to subtracting the ...
A coder's guide to spline-based procedural geometry is a video from Unity event Unite 2015.
In the video, the presenter gives visual explanation of how splines can be created and modified. Then, he goes on to give code examples for the same. Very informative.
The video is for Unity3D, but the algorithms presented can be adapted to any platform.
In your situation you need a simple subtraction, with a normalization.
vectDistance = B - A
vectDirection = vectDistance / lenght(vectDistance)
This will give you the direction.
In LibGDX, you can use the sub method from the Vector2 class, along with the nor from the same class:
vectDirection = b.sub(a).nor();
To help figure out if you need to ...
The very complex and hard to understand calculation people do to get an object's size at a specific distance is: divide by Z. Even the big APIs, like DirectX and OpenGL are basically just rasterizing APIs with a depth buffer. The 3d aspect comes from this. So:
Given a width, a height and a distance from the camera Z, the new width and height of the object ...
you can concatinate 3 matrices
first a translation to put 1,1 at 0,0, then the rotation and then translate 0,0 back to 1,1
if you use affine transformation matrices this is easy
[1,0,-1][0,1,-1][0,0,1] * rotationMatrix * [1,0,1][0,1,1][0,0,1]
if you don't use affine transformations then just subtract 1,1 on each point then rotate around 0,0, then re-add ...
Why are all three lines of the formula seperated by commas?
P(x,y,t) is a vector valued function. Its values are thus 3D vectors. The commas just separate these components, probably akin to a Matlab style of coding.
D refers to a directional vector (i think)
D is a 2D vector in the (x,y) plane. It describes the direction (and magnitude, if not noramlized!)...
You have incorrectly implemented the formula as a function. The function is missing + 1 after the call to Math.sin(), which moves the wave to the range [0, 2].
Regarding your second problem, I don't see anything wrong. In fact the screenshot looks exactly like it should and seems to match the plotted curve. Try with k=10 and you should see the difference ...
I suspect the method actually used doesn't actually rely on parallel projection and it only seems so through the approximation of the article writer and subsequent translation. The problem with bringing a parallel projection into this is you'll attenuate perspective, which is not what you may want. At any rate the method I describe here achieves the same ...