Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  faster curve drawing  (Read 1423 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Member




Java games rock!


« Posted 2003-11-10 20:13:48 »

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
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2003-11-10 20:26:47 »

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?


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #2 - Posted 2003-11-12 21:54:00 »

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? Smiley

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.

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2003-11-13 07:38:55 »

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.


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 Smiley.

I'm guessing the OP has decided a big PNG is the best way forwards Smiley

malloc will be first against the wall when the revolution comes...
Offline cfmdobbie

Senior Member




Who, me?


« Reply #4 - Posted 2003-11-13 09:08:09 »

At the risk of breaking netiquette, me too!

I figured something had broken, and it wasn't getting off the intro screen...

Hellomynameis Charlie Dobbie.
Offline kilvati

Senior Newbie





« Reply #5 - Posted 2003-11-13 09:14:22 »

Quote

(1) How many tables do you need.
represent in the table?


One, because cos is a 'shifted' version of sin

Quote

(1) How many tables do you need.
(2) What the minimum actual angle range you need to represent in the table?


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

Give a man a fire and he is warm for a day, set a man on fire and he is warm for the rest of his live.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #6 - Posted 2003-11-13 10:12:10 »

Quote
At the risk of breaking netiquette, me too!

I figured something had broken, and it wasn't getting off the intro screen...


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>
<adjust>
<fire>

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

弾幕 ☆ @mahonnaiseblog
Offline zulo

Junior Member




Java games rock!


« Reply #7 - Posted 2003-11-14 00:29:50 »

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. Smiley

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. Smiley

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 )
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (54 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (246 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!