Jump to content
  • Advertisement

deej21

Member
  • Content Count

    25
  • Joined

  • Last visited

Community Reputation

152 Neutral

About deej21

  • Rank
    Member
  1. deej21

    Multiplayer cooperative RTS

    I played it in Starcraft and it was quite fun. My friend and I would play against two computers, so it would be 1v2 and it was challenging. What made it most fun, though, was that each player started with a builder unit from the race they chose. So if he chose terran and I chose zerg, our base would be terran, but we would also have a zerg drone. So a bit later, I would head out and build a zerg base. Ahh, if only wow wasn't so successful... we need a sequel.
  2. deej21

    object references

    Hello, I have a question about object references, and I am on vacation without a compiler to check it, but still programming (notepad ftw.) I'm using C#. There are four classes, Base, Sub1 : Base, Sub2 : Base and a main class that has a Hashtable with keys of strings and values of Base. The Sub1 class will sometimes call "MainClass.foo(this);" where foo has a parameter of Base. Now, the main class has a reference to said Sub1 in its Hashtable, and also now passed as a parameter. These reference the same object. What if foo has code: paramBase = new Sub2(); Will this change the reference in the Hashtable to now point to the same thing? Part of me wants to say yes, yet that command merely changes paramBase to point to something else; wouldn't the Sub1 still exist in memory, still referenced in the Hashtable? If indeed the Hashtable's reference is also changed to the new Sub2, then the Sub1 is effectively gone, waiting for the garbage collector, correct?
  3. It's fairly easy to prove that all squares are congruent to 0 or 1 modulo 4. Thus, n^2 + 1 must be either 1 or 2 modulo 4. Then you can easily remove half of your tests for numbers that are 0 or 3 modulo 4, since it's impossible for them to satisfy it. Similarly, all squares can only be 0, 1, or 4 modulo 8. So any numbers that are 0, 3, 4, 6, 7 modulo 8 can't satisfy either. To eliminate even more possibilities, note all squares can only be 0, 1, 4, or 9 modulo 16. Then you can eliminate 75% of all numbers, before having to do your square root check. This saves a lot of time. You can find these congruences pretty easily... when working in modular arithmetic, most things reduce with the modulus. Thus 7^2 = 2^2 (mod 5). By testing the squares of all possible residues with a specific modulus, we can find the only possible congruences.
  4. deej21

    Gravity

    Those equations seem correct, but can t be used as the time since the previous frame? dy = y0 + (1/2)g*(dt)^2. The displacement is based on the total time squared, thus the longer an object is falling, the faster it falls, since t^2 increases faster. If t is reset, wouldn't this represent an object that just starts its descent rather than continuing it? Perhaps the extra term in equation 2, the v0t, accounts for this.
  5. deej21

    camera transformation

    Sweet, that worked out great. Thanks a lot, johnbolton. Just a note, it also worked just using the 3x3 matrix. I just subtracted the eyepoint, then multiplied by the transposed rotation matrix. This eliminates the need to calculate T'
  6. deej21

    camera transformation

    Thanks a lot for the detailed reply! I will implement this and hopefully it works fine. I don't know a ton about transformation matrices, but I think that the top 3x3, or R, is just a rotation matrix, and T is a translation matrix, just combined into the 4x4 matrix that way. Could I simply perform the translation of -T, then multiply R * [point] to rotate the point? The inverse of a 3x3 matrix isn't hard to calculate, although your optimizations make a 4x4's easy also.
  7. deej21

    camera transformation

    Thanks for your response, but I knew all that... what I need IS that world to view transformation, given the sort of data I have about the camera.
  8. I'm trying to make a simple 3d renderer, without dx or ogl. I have all objects in world space as standard, and I use right = +x, up = +y, forward = +z, which is left-handed I believe. With the camera at (0,0,0) and facing the positive z-axis, all objects are rendered how they should. However, the camera should ideally be able to move around and rotate. I can handle the code for moving, but I can't figure out how to transform the points accordingly. The camera simply has two 3d vectors, one for the eyepoint, and the other for the lookAt point. The up vector is by default (0,1,0). I have functions for getting the view, side, and up vectors based on the eye and lookAt. However since I can't get the transformations to work, I can't be sure they are right. My current process is to subtract each point by the camera's eyepoint, setting it at the origin. The part I can't get is properly rotating the view vector to point along the positive z-axis. I've looked online extensively, and everything I find either tells me how to use directx or opengl's functions, or it didn't work for me. I have implementations of 3d vectors, 4d vectors, 3x3 matrices, 4x4 matrices, tons of stuff tried and failed. Alternatively, not a problem per se, but a question. Currently, my implementation of projection is just to divide the x and y coords by the z coord, something I remember hearing a while ago. It works, and moving the camera around (the eyepoint... it still has to look straight ahead) seems realistic. However, it tends to stretch things along the z-axis, ie. things look longer than they really are. I have seen many projection transformations in my searches for view transformations, and although I didn't try any of them, I still wonder: is my implementation acceptable and/or what is the best way to do projection?
  9. You can't use fermat's little theorem directly, but you can use a result of it, namely that, if gcd(a, c) = 1, then a^b = a^(b mod phi(c)) (mod c). When working with modular equations, you can always replace the base, and any other numbers not rooted within (like exponents, logs, etc) with any number that is congruent mod c. phi() is the Euler function. For instance 13^183 (mod 11) = 2^183 phi(11) = 10 183 = 3 (mod 10) 2^183 = 2^3 (mod 11) = 8 In the second example, 5*5*5 (mod 4) 5 = 1 (mod 4) You can replace all the 5s with 1 since they are congruent with the modulus. 5*5*5 = 1*1*1 = 1 (mod 4)
  10. Yeah, I found out that prepareImage() doesn't seem to work in browsers if your images are in the .jar. I tried IE and Firefox, and in both, it wouldn't work (it would, like you said, sit there waiting) although if I had the images folder in the directory, it would work.
  11. Ok, I figured out how to make a loading screen. Here is my code. public void start() { System.out.println("applet start"); paint(getGraphics()); if(!loaded) { new Thread(new Runnable(){ public void run() { load(); } }).start(); } else startGameLoop(); } private void load() { if(loaded) return; //stuff someImage = getImage(getCodeBase(), "foo.gif"); //stuff loaded = true; startGameLoop(); } public void paint(Graphics g) { if(loaded) return; g.setFont(new Font("Verdana", Font.BOLD, 24)); g.setColor(Color.black); g.drawString("Loading...", 180, 220); } The reason I use paint(getGraphics()) rather than repaint() is that repaint() waits calls paint() on a new thread, which doesn't get focus until later; namely, not until after everything is loaded, so it's pointless. This way, paint() is called and must return before any of the loading is begun. One thing is that, according to the Javadocs, Applet.getImage() always returns immediately and doesn't load the image until the applet attempts to draw it. Ideally, it would be best to have the images loaded so it doesn't take up extra time loading when it needs to be drawn to the screen. Any ideas? edit: Ok, I added your thing using prepareImage(), and it worked out well. There was no flicker or wait between the end of the loading screen and the game itself, and it took about twice as long, which is a good sign that it loaded the images.
  12. Thanks a lot. Could you elaborate more on how to use prepareImage()? For instance, what is an ImageObserver? Also, how can I display a loading screen while the images load?
  13. That's an interesting way to do it... I used to use Timers, but I don't like them that much. I prefer to use System.currentTimeMillis() and use delta / 1000 * pixelsPerSecond for movement. Also, the code is very simple. In the update() method, just have if(System.currentTimeMillis() - timeLastUpdate > waitTime) { genericUpdateEverythingMethod(); timeLastUpdate += waitTime; } Regardless, I got it to work, but am having problems in running the applet in a browser. I could have made a new thread, but figured it is appropriate here also. Since browsers don't let applets read or write any files, I can't read in the images I need. I tried archiving everything into a .jar file, but still got the same problem. I would think a .jar file would work, since I thought that was kinda the point of a .jar file. One possibility I thought of was making a server-side application to load the images and send them to the game, although I'm really not wanting to do that. Is there an easier way?
  14. Right... that's what I said. Would the most efficient way be to merely call new Thread(new Runnable(){ public void run(){ loop(); }}).start();
  15. Ok... I've been working on this for a bit. I figured out that, yes, adding the state like that does work. The reason it didn't work for me before is because I called the game loop in Applet.start(), which means start() doesn't return, so the applet isn't officially "started", thus only initialized, and nothing is shown. I tried calling state.update() only once at the end of start(), and it drew the proper screen. Of course, it didn't draw anything else since I didn't call update() anymore. What is the best way to have the game loop be called on a separate thread so it can work properly? Like I said, I tried SwingUtilities.invokeLater(), but I got the same results as calling the loop at the end of start(). (off subject) I was taught to use paint()... it works properly that way. What is the difference between using paint and paintComponent. Obviously different definitions in the super class, but what am I overriding?
  • Advertisement
×

Important Information

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

GameDev.net 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!