A Little Trigonometry

Started by AGP, May 30, 2009, 06:32:34 PM

Previous topic - Next topic

AGP

Sure, and thanks for your suggestion, but I recopied the lwjgl applet files and nothing changed (same error 7).

<html>
  <applet code="org.lwjgl.util.applet.AppletLoader" archive="lwjgl_util_applet.jar, lzma.jar" codebase="."

width="800" height="600">
    <param name="java_arguments" value="-Xmx320m">
    <param name="al_title" value="Racer v. 0.1">
    <param name="al_main" value="Racer">
    <!-- logo to paint while loading, will be centered -->
    <param name="al_logo" value="Car.gif">
    <!-- progressbar to paint while loading. Will be painted on top of logo, width clipped to percentage done -->
    <param name="al_progressbar" value="appletprogress.gif">
   
    <!-- signed windows natives jar in a jar -->
    <param name="al_windows" value="windows_natives.jar.lzma">

    <!-- List of Jars to add to classpath -->
    <param name="al_jars" value="Racer.jar, jpct.jar, lwjgl_applet.jar.pack.lzma, lwjgl.jar.pack.lzma,

jinput.jar.pack.lzma, lwjgl_util.jar.pack.lzma, res.jar.lzma">
   
    <!-- signed linux natives jar in a jar -->
    <param name="al_linux" value="linux_natives.jar.lzma">
   
    <!-- signed mac osx natives jar in a jar -->
    <param name="al_mac" value="macosx_natives.jar.lzma">

    <!-- signed solaris natives jar in a jar -->
    <param name="al_solaris" value="solaris_natives.jar.lzma">
   
    <!-- Tags under here are optional -->
   
    <!-- Version of Applet, important otherwise applet won't be cached, version change will update applet, must be

int or float -->
    <!-- <param name="al_version" value="0.8"> -->
   
    <!-- background color to paint with, defaults to white -->
    <!-- <param name="al_bgcolor" value="000000"> -->
   
    <!-- foreground color to paint with, defaults to black -->
    <!-- <param name="al_fgcolor" value="ffffff"> -->
   
    <!-- error color to paint with, defaults to red -->
    <!-- <param name="al_errorcolor" value="ff0000"> -->
   
    <!-- whether to run in debug mode -->
    <!-- <param name="al_debug" value="true"> -->
   
    <!-- whether to prepend host to cache path - defaults to true -->
    <param name="al_prepend_host" value="false">

  </applet>

  <p>
    if <code>al_debug</code> is true the applet will load and extract resources with a delay, to be able to see the

loader process.
  </p>

  </body>
</html>

paulscode

Does it help to use -Xmx300m instead of 320, or removing the parameter alltogether?

AGP

I took it out and it doesn't even get to the OutofMemoryError, but that was a good suggestion.

paulscode

That is really strange.  Have you tried loading a simpler applet to make sure the AppletLoader is able to load anything at all?

AGP

Yes, and it loads fine. Ever since they made appletviewer (and just to be clear I'm not using it, I'm using Explorer and Firefox) security permission-aware, I've found applet writing and testing to be a nightmare, which is why I first wrote this program as an application. But I'll solve it soon enough, I suppose. Really, my only rush is that I don't want you to go offline! :-)

paulscode

LOL, I'm working on my target shooter, so I should be around for a few hours.

AGP

Here's a note: while Egon's code rotates the car even on straight lines, paulscode's code doesn't. So if either of you is reading, I think that's an important observation. I'll try and get this thing working in applet form and post a link here tomorrow.

EgonOlsen

Quote from: AGP on June 03, 2009, 06:40:56 AM
Here's a note: while Egon's code rotates the car even on straight lines, paulscode's code doesn't.
...is that a good or a bad thing... ???

paulscode

Quote from: AGP on June 03, 2009, 06:40:56 AM
Here's a note: while Egon's code rotates the car even on straight lines, paulscode's code doesn't.
Since they don't behave exactly the same way, then one of the formulas is probably wrong (and guessing from past experience it is most likely mine).

I went back through this post to try and reconstruct what you are doing (I want to play around with a simple test case to try and get it working).  Correct me if the following is incorrect:

You have a car object, whose world coordinate is called "car center".  It has a child dummy object called "car pointer" which is in front of the car (or whatever direction the car is currently traveling - could be in reverse or sliding on gravel, for example).  There is a world coordinate called "direction", which is where the car is trying to end up.  You move the car some amount each frame, in the direction of the "car pointer" child.  You also rotate the car some angle amount each frame (not greater than "theta", which is the angle between "car pointer" and "direction").  In theory, this should cause your car to eventually end up at (or at least orbit around) world coordinate "direction".

AGP

Egon: it's a bad thing in that the car rotates awckwardly even on straight lines. Then again, if the formula eventually works...

Paulscode: yeah, the child object is directly in front of it, but no, the car isn't using pointer to move, it's chasing an array of SimpleVectors. I put the pointer there just so I could get a triangle from which to calculate theta. And the car is moving exactly as it should except that after the first turn it's not facing forward.

paulscode

#25
Hmm, having trouble visualizing.  So you are always moving in the correct direction, but the mesh is not lined up, correct?  Do the array of SimpleVectors represent "direction" then?  Perhaps a diagram and some code segments might help.

AGP

The world coordinates are invisible. I store them by setting the program in store mode, at which point the opponent car doesn't move and I drive in its place while my program stores my position. The rest you can see in the screenshot:

paulscode

Ok, I think I got how it works.  Let me rephrase, and tell me if I still don't have the system correct:

You store a number of world coordinates in an array, which more or less defines a path for the car to follow.  Each frame, the car moves some amount toward the first coordinate, and when it gets there, it moves toward the second, etc.  Since the coordinates are not always directly in front of the car, it must rotate.  The car's world position is "car center", the coordinate that the car is currently moving toward is called "direction", and the car has a dummy child object called "car pointer" which is in front of the car.  In order to get the car pointed in the direction that it is traveling, you also rotate the car some angle amount each frame (not greater than "theta", which is the angle between "car pointer" and "direction").

AGP

Almost right, except that I'm only rotating the car every time I increment the array index of world coordinates, as opposed to in every iteration of the game loop.

EgonOlsen