faster curve drawing

hi
My study group is making a cannon game. ( you control a cannon and shoot at a target )

I just have a question, we have made a mountain in the background and we use math to calculate the curves, and alot of calls to Math.sin() and other math functions. I can see with a profiler that the calculation of this mountain takes

i was wondering, is it better to create a custom shape with graphics2d and draw that instead of applying “theory math” in javacode to create curves? what is fastest?

http://home2.hit.no/~022304/AppletKanonTest.html

pre plotted points will always be better then calculating them on the fly. Trig functions inparticualr can be expensive. Amny 2D games, where trig is used to calculate motion, use pre-generated trig tables.

Here’s a brain teaser for you. To get both sin and cos from 0 to 360 degrees…
(1) How many tables do you need.
(2) What the minimum actual angle range you need to represent in the table?

The fastest way is drawing it once to a buffer instead of drawing it each time from scratch. That should be much faster especially if you use gradient filling and/or antialiasing.

However, since you have clouds behind the hills… you would need alpha if you use antialiasing.

Well imo it doesnt make much sense, that the clouds are behind of the mountains… but that’s intentional right? And the blue color should simulate transparency? :slight_smile:

Also… the clouds are just a bunch of fillOval right? The clipping on the left is too early. Btw it’s would be faster if you just create (let’s say) 10 kinds of different clouds wich you paint once into a buffer and then just draw that buffer onto the screen in your game loop.

Hope that makes sense.

[quote]The fastest way is drawing it once to a buffer instead of drawing it each time from scratch. That should be much faster especially if you use gradient filling and/or antialiasing.

However, since you have clouds behind the hills… you would need alpha if you use antialiasing.
[/quote]
Hmm. Did I download a different applet or something? What I see is a huge download time waiting for a big pre-rendered background image :).

I’m guessing the OP has decided a big PNG is the best way forwards :slight_smile:

At the risk of breaking netiquette, me too!

I figured something had broken, and it wasn’t getting off the intro screen…

One, because cos is a ‘shifted’ version of sin

90 degrees:
0-90 in table
90-180 is table[180-degree]
180-270 is -table[degree-180]
270-360 is -table[360-degree]

the rest should be mod (%) with 360 to one of these values, because it repeats itself

[quote]At the risk of breaking netiquette, me too!

I figured something had broken, and it wasn’t getting off the intro screen…
[/quote]
Hmyea… that was a problem for me too… dunno what I did to proceed… I think it was space(?) :>

Oh and zulo… the GUI is horrible. Just think about it for a moment. You have to adjust the angle and/or the speed and then you have to press “fyr” (or summin). Obviously these controls should be next to each other in order to minimize the travelling distance.

I suggest to place the “fyr” button below the angle and speed sliders, because it’s then next to each other and in addition it’s the way GUIs are build (and users are used to that). “ok”, “fire”, “post”, whatsoever should be on the bottom.

<see what’s up>

In this order and in this placement. It makes sense right? :wink:

hi
we made some updates now.

I fixed the gui, though our newest version is an application from now on without swign or awt components like buttons.

but you can see the applet with some updates…it now has a flying target which explodes. And the target can shoot the cannon, but the flying target (helicopter) doesnt know how to aim in this version. :slight_smile:

And we fixed the speed i think, the mointain was created out of 600 calculated double values that were calculated each frame in the paint method. Plus it calculated 600 Color objects each loop…so we precalculated it and put it in a table now. :slight_smile:

I think it is much faster now…

you can see it here:
http://home2.hit.no/~022304/AppletKanonTest.html

btw. first press one of the sliders to activate the keyboard, then you press enter to get past the intro image (images are now resized from 700KB to 15-20KB )