Tag Info

New answers tagged

1

I think these two lines are not needed: Subtract(a,&entities[target].pos);// Make it relative to the obstacle model ... Subtract(b,&entities[target].pos);// Make it relative to the obstacle model I don't see why are you adding them. I think that if you remove them it should work as intended. EDIT: when you calculate the normal to the triangle ...


2

In your context, I think constant acceleration refers to acceleration's like Earth's gravity. This is lengthy because you are not specific about how you are using the model. Are you trying to simulate gravity, space travel, bullet riccochet, etc?? I'm kind of a math-nerd and would be happy to reply with more specific detail if you are more specific about ...


1

You can look into the Perspective n Point problem. I think that's what this issue is officially called.


-1

You just need to rotate direction vector A by angle theta, where theta is angle corresponding to your distance on circumference. Because you know full circle is 2 * pi radians and you can calculate the circle's perimeter. Theta is then distance / perimeter * 2pi radians, simplified dist / len(A). In code: double theta = distance / A.Length(); vec2 dirA = A ...


2

Turn the quaternion into a 3x3 matrix, transpose it (shortcut for the inverse of a purely rotational matrix), apply this matrix to your world space vector and you now have your model space velocity vector (entity's virtual axes: X=right, Y=Up, Z=forward or backward).


0

Well, getting 2d orientation from 3d points can be done by multiplying it with the world, view, and projection matrices. You could reverse these calculations. The thing is, you donĀ“t know depth. What you get is a line inside the viewing frustum , between the near and far clipping plane of the camera, that tells you where you see this point. But there is no ...


0

A quick guess, your raycast collides with the ball. Usually you shouldn't call a raycast without specifying what objects it is allowed to hit. Also notice that your calculated point of collision, and thus also the calculated normal, does not take the size of the ball into account. If the ball is small this might not be a big issue, but it could lead to the ...


2

float rotation = 90f; while(true) { position = CircleRadius * new Vector2(Math.Cos(MathHelper.ToRadians(rotation)), Math.Sin(MathHelper.ToRadians(rotation))) + center; rotation += 1f; }


1

public class Player { float rotation; Vector2 position; Vector2 center; float length; public Player() { position = new Vector2(Core.WIDTH / 2 - 10, Core.HEIGHT - 50 - 10); center = new Vector2(Core.WIDTH / 2, Core.HEIGHT / 2); rotation = 0; } public void turnRight() { rotation += 0.001; length = Math.sqrt(((position.x - center.x) * (position.x - ...


0

You could use the distance formula: Formula: sqrt((p2.x - p1.x)^2 + (p2.y - p1.y)^2 + (p2.z - p1.z)^2) Code: Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2) + Math.pow(p2.z - p1.z, 2))


0

The method I use is called barycentric interpolation. I would write a guide how to do it, but I don't think I could possibly sum it up better than this tutorial.


1

abs(x1-x2) + abs(y1-y2), as proposed by this answer will not always be correct. If you are willing to perform two more multiplication, you can perform an exact ordering without the cost of a squareroot. Consider the distances from (0,0) to the points (3, 4) and (5, 1). The distances are 5 and ~5.09, but the abs algorithm shows (5, 1) as being closer. ...


0

abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2) is much more efficient than using square root. If you don't need the actual distance, and just need to compare distances, this is the way to go. There will be a margin of error here, so it will give you a rough sort. Thanks to David for pointing this out


14

Compute the vector representing the displacement between the two points p0 and p1: v = p1 - p0 and then compute the length of that vector: distance = sqrt(dot(v, v)) A vector in this case is an element of the real 3D coordinate space, so it has three components (X, Y and Z). A point also has the same three coordinates, and we can subtract two points ...


1

It's assumed that point A is at the origin. Let d be the unit vector in the direction point A is currently looking at, and p be the unit vector in the direction of B - A. Notice that d and p necessarily define a plane in 3D-space. If you can imagine this, then it becomes clear that a single rotation of d by an amount equal to the angle between these two ...


0

If you have a method of getting the quaternion of the rotation matrix then just get the lookat matrix and use that method. otherwise you can get the rotation R1 from (0,0,-1) to the look vector, This results in a lookat transformation with an arbitrary up. then find that arbitrary up with R1*(0,1,0) and then find the rotation between that and the resulting ...


0

If you're looking for a single heat value you can calculate the distance between your sample point and all sources & sinks in a straight line. If there is a wall in a straight line, calculate from your sample to the ends of the wall and then to the source/sink. it gets a bit more complicated with walls made of multiple segments due to being potentially ...


0

What you need is the vector of the shortest distance between the Wall and the balls center. More generally, you seek the distance between a point and a line. Paul Bourke has given a general solution to this well known geometry Problem on his website: This note describes the technique and gives the solution to finding the shortest distance from a point ...


0

After a full day of testing and google searching I finally came upon the fix so I'm sharing it here : uniform vec2 Resolution;//This is the render target size, i.e. what you feed into glViewport vec2 screen; screen.x = ( gl_FragCoord.x - Resolution.x / 2.0 ) / ( Resolution.x / 2.0 ); screen.y = ( (Resolution.y - gl_FragCoord.y) - ...


0

Your normals are supposed to be the face normals of a polygon. If your vertices are an oriented array in counter clockwise order, then you can easily compute the normal of a face by a 90 degree rotation. So if we have an edge on a polygon made of the vertices a and b, we know that the edge is oriented from a to b going around the polygon in CCW order. To ...


1

Have a look at this. It works through some very clear diagrams. http://www.mathopenref.com/coordpolygonarea2.html They are just calculating area and you are enumerating points. However you can adapt these ideas. Look carefully at 'A More Complex Case' and how the horizontal lines divide the polygon into a set of trapezoids (if you recognize a triangle as ...


1

You could possibly treat it as a graph traversal problem. If you treat adjacent points as 'children' of each other and add each child of your boundary points to a list of open nodes (ie. unvisited nodes), then your enumerator could explore this list. In case you're unfamiliar with search algorithms, this would probably look something like: For each point; ...


1

Every polygon can be represented as lines[L] with interception points[P].For each line you calculate weather it is above or below a point Pn(n is the index of array P) which is not part of the line Lm.When you measure all the lines you save the result in one dimensional bool array V[number_lines].When you have a random point A.Then you make for loop for ...


9

You will need to process all the points at least once so if this check is done only once there isn't much you can do to speed up the test other than brute-forcing it using parallelism. If the test is going to be run multiple times there are ways to pre-calculate tables to help, such as a grid of cells marked as [definitely inside (green in image), outside ...


7

What you are seeking is a solution to the "point-in-polygon" problem. It is described in Wikipedia here:           You can find C code following the links to Computational Geometry in C, or at many other locations found by searching for "point-in-polygon" code.


1

To calculate perspective projection divide by w. vec4 result = vec4(x, y, z, 1) * perspective_view_model_matrix; result /= w; You are then left with the (x,y) in screen space (-1 to 1). Multiply this by 1/2 screen width,height and you get pixel coordinates. You then need to take the corresponding vertex UVs, multiply by the texture size and you get ...



Top 50 recent answers are included