Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

  • Days Won


Everything posted by alvaro

  1. Yes, it's possible to find a closed-form formula for hitting a constant-velocity target with projectiles that fall due to gravity. I described the general way to approach this type of problem here. In this particular case, it's easier to use a frame of reference that falls with gravity. Then the projectiles seem to travel at constant velocity and it's the target that is accelerating upwards. Write the parametric equation that tells you where the target is at time t, and find a time t such that the distance from the origin to the target at time t is t * projectile_speed. The resulting equation is a polynomial of degree 4 in t, which can be solved in closed-form. But a numeric solver would work just fine.
  2. I No, you are probably right. But you mentioned you were getting the problem that it could align to the opposite of the desired direction, so I tried to think about it from scratch. I though we were talking about a homing missile, not a turret.
  3. The way I would do it is: Compute the quaternion that would produce the "most natural rotation" that would align your missile with the target. Look at its real coordinate to see if the rotation is larger than the limit. The real part should be at least cos(limit_angle/2). If needed, modify the quaternion so its real part is exactly cos(limit_angle/2), scaling the imaginary parts to keep the quaternion having unit length. Apply the quaternion to rotate the missile. You can find code to compute the "most natural rotation" in this thread. Depending on the genre, a more realistic Physics simulation of the missile's dynamics and a control mechanism (like a PID loop) to guide the missile could give you better results.
  4. alvaro

    Does each vector have its own basis vector?

    An affine space doesn't have an origin, correct. "Origin" is a property of the frame of reference you are using to define coordinates. affine frame of reference selection == origin selection + basis selection
  5. alvaro

    Does each vector have its own basis vector?

    Some definitions and theorems: A vector space is a set of elements we'll call vectors that can be added, subtracted and scaled. A vector space has a special vector 0, which can be added to any vector without changing it. A linear combination of some vectors is a [finite] weighted sum of those vectors. A set of vectors is said to be linearly independent if the only way to get 0 as a linear combination of them is to make all the coefficients 0. The span of a set of vectors B is the set of vectors that can be obtained as a linear combination of vectors in B. A set of vectors is called a generating set if its span is the whole vector space. A set of vectors that is both linearly independent and a generating set is said to be a basis. The number of vectors in a basis is the same for all choices of basis, and it's called the dimension of the vector space. If you have a vector space and a basis for it, you can express any vector as a linear combination of the basis vectors in a unique way. The coefficients of the linear combination are called coordinates. This allows you to do computations. In light of this, you can see that the questions in the original post don't make sense. I don't understand the first question in your second post either. I would say that "3D model space is a subspace of 3D world space" is not accurate. Model space is a 3-dimensional affine space (which I didn't define because this is getting long enough) where the vertices of the model are specified. These vertices can be mapped into the world space (another affine space) using an affine transformation. Once you have specified an origin and a basis for each affine space, an affine transformation can be described as certain 4x4 matrix.
  6. alvaro

    Get rotation angle from normalized 2D vector

    No, lack of understanding and ability to methodically analyze the situation are your problems. You'd be much better off in the long run if you took some time to understand the details. Anyway, I am done trying to help in this thread.
  7. alvaro

    Get rotation angle from normalized 2D vector

    Oh, I'm sorry. Of course, you don't have time to debug your own problem, so you expect us to help you for free. I see how that works...
  8. alvaro

    Get rotation angle from normalized 2D vector

    Try what? I don't know what values to use for x, y, player.x or player.y . Extract specific values passed to atan2 where you obtained something outside of [-pi,+pi] from it. Any additional code required will just obscure the issue, because the problem could be anywhere else.
  9. alvaro

    Get rotation angle from normalized 2D vector

    I just joined in. I gave you examples when the output is very close to -pi and very close to pi. Do you have examples when the output is *not* in the range from -pi to pi? Just a few lines of code, like I posted, would be enough.
  10. alvaro

    Get rotation angle from normalized 2D vector

    Are you saying that the range of values returned by atan2 is not -pi to pi? I don't need to make a function that rotates anything to figure that one out. I can just run this: #include <iostream> #include <cmath> int main() { std::cout << std::atan2(-1e-10, -1.0) << '\n'; std::cout << std::atan2(+1e-10, -1.0) << '\n'; } Or I can look at the documentation: http://www.cplusplus.com/reference/cmath/atan2/
  11. alvaro

    Card game AI help

    The rules of a game are often given by describing: the setup, what you do in your turn, when the game ends and how you determine who won. It's not even clear to me from the description if this is a game the OP is creating or an existing game. Once we know what we are talking about, we might be able to give you decent advice.
  12. I actually didn't read much further than that. If you want my help, you shouldn't torture me with a wall of text and stories about your difficulties staying connected to your friends. Get to the point.
  13. alvaro

    Remove VR split screen

    Can you ask the developer you are working with?
  14. The update to the velocity (using Euler integration) is typically something like this: angular_velocity = old_angular_velocity + angular_acceleration * dt You can introduce friction by this simple tweak: angular_velocity = (1 - something_smallish) * old_angular_velocity + angular_acceleration * dt That's would be my first attempt. See if that behaves the way you want.
  15. Fulcrum.013, two observations: (1) This thread is about rotation kinematics, which is not "Physically inaccurate" in any reasonable sense. It's just not full-blown mechanics, but that doesn't make it wrong. (2) Try to spell correctly. I am OK with people being a little bit careless or even ignorant of correct spelling, but it was honestly hard for me to understand what you wrote.
  16. alvaro

    Why are enums broken

    I agree with Oberon_Command on this one. If some feature can be implemented in the standard library without touching the language, the committee has usually preferred that. Something being in the standard library is not a good reason to not use it.
  17. alvaro

    Why are enums broken

    I like your edit from "Wrong" to "True".
  18. alvaro

    Why are enums broken

    The enum values before C++11 were in whatever namespace you defined the enum, not necessarily in the global namespace.
  19. alvaro

    Why are enums broken

    I find myself wanting to do arithmetic operations and bitwise operations on enums all the time. Here's an example from my chess engine: enum Piece { Pawn, WhitePawn = Pawn, BlackPawn, Knight, WhiteKnight = Knight, BlackKnight, Bishop, WhiteBishop = Bishop, BlackBishop, Rook, WhiteRook = Rook, BlackRook, Queen, WhiteQueen = Queen, BlackQueen, King, WhiteKing = King, BlackKing, Empty, NPieces = Empty }; I use this type as index in an array declared something like `uint64_t bb[NPieces]'. This is a bitboard representation of the position, where bb[WhitePawn] is the 64-bit integer whose bits indicate the presence or absence of a white pawn at each location. Then I can refer to the pawns of the side to move as `bb[Pawn + side_to_move]', where `side_to_move' is 0 for white and 1 for black (I have an enum for that too). The result of that sum is an int [I believe] and if I wanted to store it in a variable of type Piece I would have to cast it. Another operation that I may want to do is loop over the piece types, which also requires arithmetic. for (Piece piece = WhitePawn; piece != NPieces; piece = Piece(piece + 1)) It would be nice if I didn't have to fight the compiler to accept `++piece' as my increment. In order to check if a piece is a pawn of either color, I can do `((piece & ~1) == Pawn)'. I don't have much of a problem working within the language: I either define some operators to return Piece or I sometimes use `int' in places where `Piece' would be more expressive, so the compiler doesn't complain. But I can see how some people might feel that enums are too restrictive.
  20. You should probably provide a mechanism to create a quaternion from a vector by making the real part 0. For instance, when you use the quaternion to apply a rotation, you normally do something like q' = q * v * conj(q) That `v' means the vector used as a quaternion in the manner I described.
  21. Notice the equations could be re-written like this: (1) q' = (1 + 0.5 * w * dt) * q (2) q' = exp(0.5 * w * dt) * q Since exp(z) = 1 + z + z^2/2 + z^3/6 + ..., you can think of the first equation as using a linear approximation to the exponential function.
  22. No, no. `w' is just the angular velocity, with a 0 as real part. No trigonometric functions involved.
  23. I believe the first equation is a linearization of the second one. Notice how the first one doesn't involve any trigonometric functions, but the second one does. Remember to re-normalize the orientation after you use the first formula.
  24. I don't understand what you are saying. That equation is a way to update the orientation using angular velocity... I am not sure what "q_rot" does, so I can't comment on your second equation.
  25. If you only need the position, apply the transformation to the origin.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!