Eric_Brown

Member
  • Content count

    46
  • Joined

  • Last visited

Community Reputation

127 Neutral

About Eric_Brown

  • Rank
    Member
  1. Determine current angle of rotation around vector

    Captain, Yes, o is the position of the camera relative to the center of the sphere. When I say sphere space, I mean that the center of the sphere is the origin of this space, and the offset vector o is given relative to this origin. I would like to try and verify that I know what it is you are trying to do: From what I can tell, you are storing p and c, and using them to calculate o. You want to represent the location of the camera on the sphere by using a set of angles. You then use these angles to rotate o. Then you want to recalculate p using the rotated o. Is this correct?
  2. Determine current angle of rotation around vector

    Hey Cap'n I would avoid using sphereical coordinates to represent the position of the camera on the surface of a sphere. Rather, store the center of the sphere, and the current sphere offset vector. If the magnitude of the offset vector is fixed, then the position of the camera is always on the sphere p is the vector representing the world space position of the camera, c is the vector representing the world space center of the sphere, and o is the vector representing the sphere space position of the camera. This representation is especially simple if you want to have a smooth blend from the current sphere space position of the camera o to a new desired location od. The blend is done in two steps. The first step is: Where b is between 0 and 1 and determines the blend rate. If b is 0 then there is no blend. If b is 1 there is an instantaneous blend. The second step is: Which constrains the blended position to lie on the surface of the sphere. This blend is non-linear, but it is smooth. Also, changing the destination point before the blend is complete does not cause problems. Store this blended value as the new offset vector, and recalculate the world space position of the camera. Then find the lookat vector and so forth. Eric Brown
  3. Quote:Original post by Zipster Quote:Original post by alvaro Hmmm... That doesn't seem to add anything to the formula, except complexity. If you plug in a negative x in the usual formula, you'll get the correct result. It could be that in Euler's time there was a stylistic reason to prefer a formula that incorporates exp(ix) and exp(-ix). Even if you get the same result in the end, perhaps it's to clarify that the sign of 'x' only influences the terms involved with calculating 'sin' and not 'cos'. Or to hint at the effect of complex conjugation.
  4. uncombining transformation matrix

    What I've found is that matrix decomposition is useful when you need to output a particular transform to a human, such as in a debugging tool, or a game design tool. For this reason alone, having a good decomposition procedure is handy. Other than interfacing with humans, keep the transform in a more compact form, such as a 4x4 matrix, or as {scale vec, rotation quat, translate vec} which simplifies a lot of blending operations. If you aren't going to be doing a lot of blending, you should really just use matrices.
  5. Differentiation & Integration

    marcus, I think I felt a similar confusion when I first started delving into the world of computational physics simulation. My confusion came from the fact that the process was called "integration", but the method of integration seemed more like taking a derivative. For instance, you give an example of a differentiation: Quote: Differentiation - (I understand)It gives rate of change, eg: ball is moving then to get new position at time 't' ( ds/dt = dv) we do like .. present_position = old_position + dv * dt; but the expression "present_position = old_position + dv * dt" would actually be termed integration. When you approximate calculus with finite differences, the operations of differentiantion and integration are encoded in the standard algebraic operations of addition, subtraction, multiplication and division. With this encoding, you can kind of think of a derivative as being associated with division, and an integral as being associated with multiplication. For example, the approximation of a derivative can be expressed like this Which incorporates a division. Integrating the previous equation amounts to multiplying both sides by Δt You can rearrange this expression to get the equation that you were referencing. So, in the end, even though they are basically the same relationship, if the equation is in this form it is a derivative. If the equation is in this form it is an integral. Once I came to grips with this, I overcame my confusion about terminology.
  6. Accurate ray-to-plane intersection with floats

    Taz, I'm not sure if I can answer your question, but I can provide a couple of little gems I keep around when dealing with precision problems regarding planes. The first is: Floating point subtraction is notoriously bad, and can magnify the error introduced by previous floating point operations. Addition isn't so bad, but adding a negative number is the same as subtraction, and since you may not know the sign of your float you might as well treat addition and subtraction the same. Many times you obtain the plane normal from a set of three points that lie on the plane. This is usually done by subtracting the verteces to get edge vectors, then taking the cross product of the edge vectors. This results in a lot of terms that are VERY BAD. Most of the precision problems I've had with planes is due to the way I was calculating the plane normal. I've worked out a method for calculating a normal from three points, which seeks to minimize the badness. Vector findPlaneNormal(const Vector& a, const Vector& b, const Vector& c) { Vector n; n.x = a.y*(b.z - c.z) + b.y*(c.z - a.z) + c.y*(a.z - b.z); n.y = a.z*(b.x - c.x) + b.z*(c.x - a.x) + c.z*(a.x - b.x); n.z = a.x*(b.y - c.y) + b.x*(c.y - a.y) + c.x*(a.y - b.y); n.Normalize(); return n; } This method seems to perform better than the standard "cross product of edge vector" approach. I'm not sure how much better it is, but it has solved a lot of my precision problems when dealing with planes.
  7. Bemba, did you get this working?
  8. deterministic physics replay

    One thing I've done before is construct a replay animation. It seems like it would take too much memory, but I've actually done this before using a little compression trick. For the animation you will need to be able to evaluate the position and orientation of several objects at every moment in time during the replay. Thus you will need to record these positions and orientations. You may also need to store the animation frame a particular character is on, or other stuff like that. You don't need to store a value for every frame, you just need to be able to determine a value at every frame. Only store data on particular frames, and linearly interpolate, or use cubic splines to get the frames in-between. That's a simple idea, but how do you decide which frames are keyframes, and which frames are not during the initial run of the simulation? Here is a simple trick. Always store the current state as a keyframe. After storing the current state as a keyframe, take a look at the last 3 keyframes. If you remove the second to last keyframe, how does the interpolated value compare to the real value? If it is below a pre-defined threshold, then you get rid of the second to last keyframe. It is possible to store your keyframes sequentially in an array, since when you are writing the array, you are only ever manipulating the last and second to last entries. This makes reading the keyframes much quicker. I can envision ways in which this scheme might fail, however, when I did it, I was able to get an excellent replay, with no visible error. My compression ratio was around %10, but in some cases it was much lower. I think I was replaying about 10-15 objects, some of them animated, some of them updated by physics. The keyframe structure stored the replay frame time, the position, the rotation quat, and the animation frame.
  9. One way to incorporate pre-canned motion into your dynamic simulation is to find the value of a that will move the character to the position where you know it should be. This is not what I recommend, however, since the character motion usually needs to be pretty deterministic. I've found that it is easier to just snap or blend the position of the character to the pre-canned location, then adjust the velocity to take into account the shift in position that you just introduced. When it is time to turn the pre-canned motion off, the dynamics will smoothly take over. The main disconnect between pre-canned animation and dynamic physics is that a pre-canned animation usually only updates the position. The dynamic physics needs the position AND the velocity to be updated.
  10. Here is a solution that might work for you. I haven't tried this, but it seems to work on paper. Sorry, it's kind of long :( If you were dealing with positions, instead of rotations, you may try a damped spring approach, where each frame you calculate the spring force between your current location and your desired location. You would also calculate some damping that is opposed to your velocity so that you don't wildly oscillate. Here is the rotational version of a damped spring force using quaternions. You need to store a "position" (q) and "velocity" (v) quaternion to represent your rotational state. You are going to calculate a rotational acceleration (a) that is analogous to a damped spring. I'll discuss later how to calculate a, but once we have it, we will step the state forward like this: If your time step is small you should replace the expensive Slerps with NLerps. If your time step is equal to 1 then you can remove the slerps altogether and the equations simplify to There are two components to a. One applies a spring force to push you toward your desired rotation. The other dampens the motion so that you don't start wildly oscillating. The linear spring force is proportional to the difference between your current and desired positions. For rotations, this difference is the rotation that rotates your current "look at" vector into your desired "look at" vector. We will call this rotation Δq. Here is a function based on the half angle method that will quickly calculate this quaternion, without employing any trig or inverse trig functions. Quat getRotationQuat(const Vector& from, const Vector& to) { Quat result; Vector H = VecAdd(from, to); H = VecNormalize(H); result.w = VecDot(from, H); result.x = from.y*H.z - from.z*H.y; result.y = from.z*H.x - from.x*H.z; result.z = from.x*H.y - from.y*H.x; return result; } Once you have calculated Δq, you need to "scale" it by a constant that represents the springs stiffness. The analogue of scaling in quaternion land is slerping between 1 and the given quaternion by the scale parameter. The acceleration due to the spring is given by The acceleration due to damping is proportional and opposed to the current velocity. Again, you just need to "scale" the velocity quat using a slerp between 1 and the velocity. Since quaternion multiplication does not commute, it is not clear if the final acceleration quat should be composed with the spring acceleration first, or with the damping acceleration first. My guess is that you should just pick one, and then tweak the k and μ parameters until it behaves correctly. At any rate, the total acceleration can be given by the product of these two acceleration components As before, if your k and μ paramters are small enough, you may want to consider replacing the expensive slerps with normalized lerps. You may just want to do this anyway - I would! If you decide to try this, let me know how well it works. I've often contemplated if it was possible to do rotational "dynamics" in this way.
  11. Matrix interpolation method for Skeleton?

    There are a few things that quaternions just do better than matrices - and interpolation is one of them. To the point, if inserting quaternions requires you to consider rewriting a lot of your animation code, you may want to consider the rewrite. As an alternative you may want to specify the keyframes using quaternions, and then once you have the interpolated result, immediately convert from a quaternion to a matrix. What is the initial form of the keyframe data? It surely isn't a matrix, is it? Most animation packages export animation curves as euler angles, or quaternions.
  12. If all you are trying to get is a non-uniform blend from the start location to the finish location, try using a non-uniform blending parameter for your slerp. In effect, apply the acceleration to the blending parameter that you send into the slerp function. You can think of f(t) as a kind of blend velocity. If you want to start slow, and end fast, you can use a quadratic function If you want to start fast and end slow, you can use this function
  13. 6 DOF Distance formula

    Quote:Original post by alvaro On top of what Eric said: (1) Since q and -q represent the same orientation, you should take the absolute value of the dot product before you take the arccos. (2) You don't need to compute the expensive arccos at all if all you need to know is which of them is closest. The smallest angle will be the one with the highest cosine, so simply find the one that maximizes that. Agreed!
  14. How to get an oblique projection matrix?

    Quote:Original post by chiyuwang I want to project a 3D point x onto a plane (defined by a b c d) along a 3D direction v. It sounds to me like you might be trying to find the intersection of a ray with a plane. If this is the case, you don't want to search for stuff on projection matrices. Projection matrices are applicable to your problem, but it seems like the hard way to approach it. Instead, consider that you are sliding your point x in the direction of v. Eventually, you will hit the plane, and this is the point you are trying to find. Use the parameter t to represent the sliding point like this Now, you want to find the value of t so that the sliding point lies on the plane. The condition that the sliding coordinates are lying on the plane is given by inserting the definition of the sliding coordinates with respect to the parameter t gives Solving for t gives NOTE: if the denominator of t is zero, then the sliding point will never come into contact with the plane. Now, insert this value of t back into the equation of the sliding point to get the actual projected point.
  15. 6 DOF Distance formula

    Oh, I see. If all of the points are at the same position, then you only need to worry about the angular peice. Find the rotation matrix, or quaternion that represents the set of angles. I prefer quaternions. You construct the quaternion like this Here ψ is the yaw angle, θ is the pitch angle, and φ is the roll angle. Of course, these angles are given within their canonical ranges. If you have 2 quaternions that represent 2 different rotations, then you can always construct a single quaternion that will take you from one rotation to the other If you want to find the angle that this delta quaternion represents, you use the scalar part of Δq in the following formula. Note, that you don't have to perform a full blown quaternion multiply if you want to find the scalar part of Δ q. The scalar part of this product is just the 4D dot product of the two quaternions q1 and q2. It seems to me that what you are looking for is the set of coordinates that minimizes the angle α. I don't recommend using matrices to solve this problem, because it is more expensive all around. But if you were using matrices instead, you would find the delta matrix Then you would use the formula posted by Emergent [Edited by - Eric_Brown on April 1, 2010 11:38:44 AM]