Tag Info

New answers tagged

0

I'm pretty sure many games do calculate the bitangent by crossing the normal and tangent. In the games I've worked on, that's what we did. We also stored a 1-bit "flip" value to indicate whether the tangent basis should be right-handed or left-handed. As you say, this saves memory, plus the bandwidth used to fetch the memory; and if you reconstruct the ...


0

The correct formula is r(x*cos(theta) + y*sin(theta)) to get a vector from an angle with line at angle theta of length r, so your calculations look right. BUT one thing you need to account for is if the angle is over 180. then you would have to subtract 360 from the angle. E.g. escapeAngle += 90; if(esacapeAngle > 180) escapeAngle -= 360; then do ...


-1

Quaternion.Euler(x, y, z) * Vector3.forward; Or what exactly do you mean?


-4

Math.ceil gives the right feel to snap the blocks to right grids


0

This is one area that I also found quite lacking. Instead of using DecalBatch, I did something much, much simpler: I added a .z value to all sprites, and just draw them in order. Technically, I created my own wrapper/subclass of Sprite with a z property which I can get and set. When drawing, I have a sorted list of sprites, and just draw them from lowest- ...


0

This depends on your camera. So if the camera is directly facing the object, you can do this. The surface normal is lets say (x,y,z). z meaning the depth. Then just make z = 0, as if you are projecting it in to plane. Then angle is simply atan2(y,x). This is for the simplest case though. IF the camera is not aligned with the object then you have to figure ...


2

You could treat the turret as stationary and subtract the velocity of the turret to the target's velocity before the start of the code, provided it works for a motionless turret. To subtract velocity vectors, if the target is moving 4 pixels left and 8 pixels up in a given time, but the turret is moving 4 pixels right and 3 pixels up in the same time, the ...


1

I believe it is pretty common to use a bone just to represent the weapon, and pull the rotation from that. Alternative you would keep an extra vertex so you can determine the direction. Depending on what they are holding you might be able to use a fixed rotation from the hand's bone rotation.


1

I think that tutorial actually contains all you need. It mentions that the order of rotations is Z, then X, then Y. I don't know Unity's quaternions, but you are either doing Z then Y then X, or the reverse. Try swapping x_rotation and y_rotation when you calculate your final rotation.


4

What you are looking for can be found in this very good explanation: http://www.songho.ca/opengl/gl_transform.html But since I found it sort of confusing without hand holding I will try to explain it here. At this point you need to consider 5 coordinate systems and how they relate to each other. These are the window coordinates, the normalized device ...


11

You simply need to project vector AP onto vector AB, then add the resulting vector to point A. Here is one way to compute it: A + dot(AP,AB) / dot(AB,AB) * AB This formula will work in 2D and in 3D. In fact it works in all dimensions.


1

I love the other answers given. Very technical! If you want, I have a very simple method to accomplish this. We'll assume angles for these examples. The concept can be extrapolated to other value types, such as colors. double MAX_ANGLE = 360.0; double startAngle = 300.0; double endAngle = 15.0; double distanceForward = 0.0; // Clockwise double ...


5

Vector projection means finding the components of vector a that are in the same direction of vector b. Check my answer here for how to do it. Not only vector projection is important in game dev but vector decomposition in general, where you have a vector and you need to decompose it into 3(or 2) separate vectors in the u,v,w directions. For example in ...


0

Please note that I'm only giving a rough starting point for an algorithm here. I can't say for sure if it will work, and you'll have to do a bit of legwork to implement this. First, a few quick things: What do you define as "lots of iterations"? The TinyKeep demo you linked does it in around 40-50. Also, given that you are working with something 2D grid ...


3

Transforming the ray position and direction by the inverse model transformation is correct. However, many ray-intersection routines assume that the ray direction is a unit vector. If the model transformation involves scaling, the ray direction won't be a unit vector afterward, and should likely be renormalized. However, the distance along the ray returned ...


5

How about letting box2d do the work for you? It wasn't too difficult for me to setup everything in RUBE: There are two major parts: the wheel and the needle. Wheel First there is a base. In this case the base is a static body with a square fixture. The wheel is attached to the base via a revolute joint. This joint allows the wheel to spin freely ...


4

The trick is to remember that angles (at least in Euclidean space) are periodic by 2*pi. If the difference between the current angle and the target angle is too large (i.e. the cursor has crossed the boundary), just adjust the current angle by adding or subtracting 2*pi accordingly. In this case, you can try the following: (I've never programmed in ...


6

It’s not always the best method, and it can be more computationally expensive (though this ultimately depends on how you store your data), but I will make the argument that lerping 2D values works reasonably well in the majority of cases. Instead of lerping a desired angle, you can lerp the desired normalised direction vector. One advantage of this method ...


1

Despite its name, Vector3.Transform() does not transform a vector but a point. The unwanted side effect is that the translation part gets added to your vector. If you want to actually transform a vector, you need to use Vector3.TransformNormal(), which will omit the translation part: Vector3.Dot(Vector3.Normalize(Vector3.TransformNormal(side, matrix)), ...


0

Sorry, the formula was correct. I built my side and hypotenuse vectors at time 0 incorrectly. My mistake was that I used normalized vectors at time 0 in the transformation, while you need to use the original ones. You can indeed find the cosine at time 1 with this formula: Vector3.Dot(Vector3.Normalize(Vector3.Transform(side, matrix)), ...


0

As a side-note, your use of EndIf makes me think you're trying to do this in PHP - which makes no sense whatsoever, but whatever. It would help if you could clarify what language you're working with. But concerning the mathematics alone... The two events you need to catch are when the edge of the space contacts the needle and when the edge breaks contact ...


2

Turns out my sprites weren't being drawn at the correct position, so their rotation was happening incorrectly. Let the lesson be Always Draw At Your Sprite's Origin Because Bad Things Will Happen If You Don't Know What You're Doing.


3

Fundamentally I think this is a problem with the grid-based ray casting being a pretty inaccurate and granular approximation of the 'real' thing you're trying to simulate. No matter what you'll do you'll run into problems. Instead of thinking about it in terms of the specifics of the iteration and implementation, think of it as if your world was actually ...


3

An axis-aligned bounding box is a simplified representation of some object's volume and position. In this case, I think an axis aligned integer bounding box would be a bounding box that can only have integral dimensions, and an integral position. If this definition is accurate, then a bounding box like this could be found if you found the highest vertex, ...



Top 50 recent answers are included