Author Topic: A Little Trigonometry  (Read 29542 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #15 on: May 30, 2009, 11:31:37 pm »
Sure, and thanks for your suggestion, but I recopied the lwjgl applet files and nothing changed (same error 7).

Code: [Select]
<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>

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #16 on: May 30, 2009, 11:43:56 pm »
Does it help to use -Xmx300m instead of 320, or removing the parameter alltogether?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #17 on: May 30, 2009, 11:56:48 pm »
I took it out and it doesn't even get to the OutofMemoryError, but that was a good suggestion.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #18 on: May 30, 2009, 11:59:29 pm »
That is really strange.  Have you tried loading a simpler applet to make sure the AppletLoader is able to load anything at all?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #19 on: May 31, 2009, 12:04:58 am »
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! :-)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #20 on: May 31, 2009, 12:07:05 am »
LOL, I'm working on my target shooter, so I should be around for a few hours.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #21 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. 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A Little Trigonometry
« Reply #22 on: June 03, 2009, 07:51:17 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... ???

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #23 on: June 03, 2009, 12:57:31 pm »
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".

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #24 on: June 03, 2009, 05:45:45 pm »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #25 on: June 03, 2009, 05:48:04 pm »
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.
« Last Edit: June 03, 2009, 05:51:05 pm by paulscode »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #26 on: June 03, 2009, 05:54:57 pm »
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:

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: A Little Trigonometry
« Reply #27 on: June 03, 2009, 06:04:18 pm »
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").

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: A Little Trigonometry
« Reply #28 on: June 03, 2009, 06:10:41 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A Little Trigonometry
« Reply #29 on: June 03, 2009, 07:33:51 pm »
The rest you can see in the screenshot:

...nifty!