Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by alvaro

  1. I want to point out that using atan2 followed by cos and sin is needlessly complicated, as it’s often the case when you use angles. You don’t need angles. Here’s how you normalize a vector: float inv_length = 1.0f / sqrt(x*x + y*y); x *= inv_length; y *= inv_length;
  2. alvaro

    Sphere-AABB Intersection Problem

    What problem?
  3. First link in a Google search for "c11":
  4. Why is this tagged "C++" but has "c11" in the title? Which is it? It's good to know what language we are talking about.
  5. alvaro

    AI for strategic decider

    Try to use proper grammar. I honestly don't understand what you are asking. You should also provide some context: Tell us what you are trying to do, what you have found in searching for a solution, what options you are considering based on what you have read, what you have tried, what relevant experience you have, etc.
  6. alvaro

    float rounding problem

    Another solution if you need "exact numbers" is to work with rationals. You could define a class that has two integer members, `numerator' and `denominator'. You then define all the usual operations with those numbers without ever losing precision. Make sure to eliminate common factors between numerator and denominator after each operation. One potential problem is that the numbers might get very large. For instance, 1/2 + 1/3 + 1/5 + 1/7 + 1/11 + 1/13 + 1/17 + 1/19 + 1/23 + 1/29 + 1/31 = 314016924901/200560490130 So at some point your integer type is going to overflow and you are going to get nonsensical results. The solution is to use an underlying integer type that uses a vector of "limbs" (think of them as "digits", except you are using base 2^64 instead of base 10). This part is tricky to implement right, although it's a good programming exercise. Fortunately people already have done all of this work for you, so you can install the GNU MP library and use the type mpq_class. #include <iostream> #include <gmpxx.h> int main() { mpq_class x = mpq_class(1,2) + mpq_class(1,3) + mpq_class(1,5) + mpq_class(1,7) + mpq_class(1, 11) + mpq_class(1, 13) + mpq_class(1, 17) + mpq_class(1, 19) + mpq_class(1, 23) + mpq_class(1, 29) + mpq_class(1, 31); std::cout << x << '\n'; // prints 314016924901/200560490130 }
  7. I mean that I don't know where this question was found. See Lactose's question. I don't know what a "test paper" is. I don't usually encounter questions worth "2 marks" (whatever that is) in the wild.
  8. I think the question is perfectly clear, although I don't know the context in which it is being posed. The OP was asked to demonstrate his understanding of the exploration versus exploitation dilemma, and he demonstrated that he only understands the exploitation side.
  9. No, I don't think you understand the issue at all. The result of the action is somewhat random, and the utility is assigned not to the actions, but to the individual outcomes. In other words, every time you take a particular action some utility is observed, but this is only a sample from a random variable, whose distribution is not known. You want to pick actions with high expected utility (exploitation), but you only have a noisy estimate of this expected utility, so over time you want to try every action enough times that you discover which action that is (exploration). Further reading here:
  10. Oh, sorry I missed that question at first. Calculus is necessary to understand the world, so I recommend taking it in general. I don't know how necessary it is specifically in procedural generation. Perhaps to understand Perlin noise it's a good idea to know some calculus. But you can probably just treat it as a black box, use it to make some pictures and never bother with the fine details. For AI, the only place where you absolutely need it is for computing the gradient of a loss function in machine learning ("backpropagation"). And again, these days there are many libraries that do the dirty work for you, so you can probably get away with very little understanding of the details.
  11. Here's how I'd figure out the relation between cos(2x) and cos(x) (which I actually don't remember). One of the very few formulas I do remember is: exp(i*x) = cos(x) + i*sin(x) Even for this formula, what I really remember is that exp(i*x) is a point in the unit circle at an angle x, and the rest I can write down from there. Computing the square of that, I get exp(i*2*x) = (cos(x) + i*sin(x))^2 But we also have exp(i*2x) = cos(2x) + i*sin(2x) If I look at the real part of those two expressions, I think I'll get the identity I want: cos(x)^2 - sin(x)^2 = cos(2x) I can get rid of the sin(x)^2 because I know that cos(x)^2+sin(x)^2=1. Again, this is not something I remember, it's just the fact that cos(x) and sin(x) are the coordinates of a point on the unit circle. cos(x)^2 - (1 - cos(x)^2) = cos(2x) 2*cos(x)^2 - 1 = cos(2x) cos(x)^2 = (cos(2x)+1)/2 There you have it. With a little bit of practice, this process doesn't take much time at all. If I have been doing trigonometry problems recently, I might remember the formula for a little while, but in the long term, I know I'll be able to derive it when I need it.
  12. alvaro


    That squares-in-circles-in-squares diagram might give you the qualitative feeling of things getting smaller as you move to the middle of the image, which is a feature of perspective. However, it's not correct in the details. The size of things changes exponentially in that diagram, but things only get hyperbolically smaller in correct perspective. Imagine a 3D space of points with coordinates (x,y,z), with your eye at the origin. The plane of the screen in front of you consists of all the points where z=1. If you have an arbitrary point in front of you (i.e., (x,y,z) with z>0), you can consider the ray that starts at your eye and passes through that point. That ray will intersect the screen plane at (x/z,y/z,1). So just draw the point at (x/z,y/z) on the screen. That's nearly all there is to perspective.
  13. If the explanations in those videos make sense to you, there is a good chance you can do calculus just fine. The key test is whether you can learn to solve problems. Math really is about solving problems. Knowing formulas and arithmetic facts is not very important. I do math for a living, and I remember very few formulas myself. But if I understand the concepts well, I can usually make a little diagram of the situation and derive whatever formulas I need. It sounds like in your math classes so far things have been framed as "here's a type of problem we may ask you about, here's a formula where you can plug in some numbers to solve that type of problem." That's not at all what real mathematics feels like. Good luck to you, whatever you end up doing.
  14. Disclaimer: I don't have any experience with people with math disabilities. With that out of the way, if it makes sense for your academic career to get that waiver, do it. Whatever you don't learn by not taking calculus you can always learn when you need it. Actually, most people will learn math better if they have a motivating problem they are trying to solve. I'm curious if you can follow the explanations in these videos:
  15. How's this? case "Weapon": Main.organ.swap(this.weapon, item); // This function can check if this.weapon is null if it needs to this.weapon = item; break; EDIT: Depending on the semantics of function calls in Java, you might be able to do the assignment inside that function as well. In C++ one could do that by passing the first argument as a non-const reference.
  16. This: case "Weapon": if(this.weapon == null) { this.weapon = item; // <-- Notice how this line is identical to... } else { Main.organ.addAmount(this.weapon, 1); Main.organ.addAmount(item, -1); this.weapon = item; // <-- This other line } break; can be turned into this: case "Weapon": if(this.weapon != null) { Main.organ.addAmount(this.weapon, 1); Main.organ.addAmount(item, -1); } this.weapon = item; break; I am not sure why the decrement doesn't happen if there was no weapon equipped... Anyway, the repetitiveness of the code is an obvious code smell, even after this minor cleanup. Perhaps Weapon, HeadArmor, ShieldArmor... can derive from Equipment, which provides a method to do the update? Anyway, I am not a Java programmer. I can think of some options in C++, but I'll let someone else suggest an idiomatic way to do this in Java. The other code smell is the "Main.organ", which looks a lot like global state. If at all possible, make sure your code doesn't use global state for anything. Also, why is it called "organ"?
  17. I am back at my computer, so I can flesh this out a bit. I have been advocating for years now the use of unit-length complex numbers to represent 2D rotations. If you represent a point (x,y) by the complex number (x+i*y), applying a rotation is simply complex multiplication. The C++ code to determine which direction you should rotate is then simply this: return sign(std::imag(desired / current));
  18. Angles make everything messy. You can subtract the current and the desired angles. The result (in degrees) will be between -360 and +360. The ranges between -360 and -180 and between 0 and +180 correspond to situations where you should increase the angle to get where you want to get. Otherwise, decrease it Or you can ditch angles altogether, but I am on my cell phone and that would require some lengthy explanation.
  19. alvaro

    Reverse transformation

    I didn't exactly follow what you are trying to do, but working with roll/pitch/yaw angles for any arithmetic of rotations (composition, inverse) is a nightmare. Use matrices or quaternions and those things will be trivial.
  20. alvaro

    i need directions

    You should probably start making some very simple 2D games (clones of Pong, Tetris, Snake, Space Invaders...). Since C++ doesn't natively give you access to graphics, sound or real-time input, you need to use a library. There are a few choices here, but I'm going to recommend SFML, mostly because it uses C++ very idiomatically. Good luck!
  21. Hi, A friend of mine is an animator in Japan and I would like to experiment making a small video game using his animations. His tool of choice is Live2D, which seems to be very popular over there. I looked around trying to find documentation of their formats, but didn't get very far. There's an API with nearly no documentation. They claim to have Unity integration, so perhaps that would be a way to do it (although I am not terribly keen to learn Unity just for this). Does anyone here have experience importing from this animation tool? Of course he could always provide me with a sequence of .PNG files, but I would like to see what alternatives we have. Thanks! Álvaro.
  22. First of all, use coordinates where (x1,y1) = (0,0): Just define (x,y):=(x2-x1,y2-y1) and you are now shooting from the origin. Even if the "time for arrow to fly" doesn't matter, figuring it out is the easiest way to solve the problem. Imagine that the hit happens at time t. At that time, you know that x^2 + (y+5*t^2)^2 = 400*t^2 Expanding that you get 25*t^2 + (10*y-400)*t^2 + x^2 + y^2 = 0 Plug in the values of x and y, and you get a quadratic equation where the variable is t^2. Solve it. In general there will be two solutions. Pick one of them. Take the square root to get the time t (the one you didn't care about). Now you know that the movement in the horizontal direction is linear, so x = 20 * cos(alpha) * t, and from there you can easily compute cos(alpha). Finally take the arccos and you have solved your problem. Try to do this step by step and let me know where you got stuck. Oh, and please don't edit your posts, or this conversation will be ruined for anyone that might encounter it in the future.
  23. alvaro

    questions about Utility AI

    Wait. I thought you were responsible for the name "utility-based salad".
  24. This is something you normally learn in school. Look up "constant acceleration" on the web. The formula you wrote describes the velocity under constant acceleration. The "1/2" and the "^2" come from integrating that formula to get the position under constant acceleration (the integral of x from 0 to t is t^2/2). Acceleration --(integrate)--> Velocity --(integrate)--> Position Acceleration <--(differentiate)-- Velocity <--(differentiate)-- Position If you know nothing about calculus, ignore everything in this post except the first line. Or go learn some calculus.
  25. Two ways to think about it: (1) Imagine the points of space that can be reached in time t, first with no gravity. It's simply a circle of radius v*t. Imagine that circle being animated over time. If you now introduce gravity, you can think of it as acting on the center of the circle, bringing it down as it grows. The formula (1/2)gt^2 is just the position under constant acceleration. (2) If you use a frame of reference in free fall, there is no gravity. Using that frame of reference corresponds to the change of variable y' = y + (1/2)gt^2, and in these (x,y') coordinates you are back to the situation without gravity.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!