Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 4
1  Java Game APIs & Engines / Java 2D / Re: Finding the slope of an edge in a BufferedImage on: 2006-12-06 15:59:10
my suggestion would be to not model your game (?) using pixels, but geometric objects, and use pixels (bufferedImages) just as a "view" of your underwater-geometric world. Once you reduce your world to polygons, collision and physics emulation becomes much easier.
2  Java Game APIs & Engines / Java 2D / Re: Jpeg comments on: 2006-12-01 12:06:03
well if exif headers were fixed length you could use RandomAccessFile to read and manipulate just the headers. if it is some random-length string, then you are forced to update the rest of the file as well since you can't just 'insert' bytes. (technically if you had access to the underlying filesystem, you could just update the file allocation tables)
3  Java Game APIs & Engines / Java 2D / Re: questions about modifying image (raster) on: 2006-12-01 11:49:03
short answer:
 the int[] array is the final underlying array the bufferedimage ultimately uses.

long answer:

in BufferedImage

in the constructor of BufferedImage:
for RGB or RGBA images

1  
2  
colorModel = new DirectColorModel(...
raster = colorModel.createCompatibleWritableRaster(width, height);


for color bit depth > 16, in DirectColorModel.createCompatibleWritableRaster(width,height)
1  
2  
3  
4  
if (pixel_bits > 16) {
   return Raster.createPackedRaster(DataBuffer.TYPE_INT,
                                             w,h,bandmasks,null);
}


in Raster.createPackedRaster(DataBuffer.TYPE_INT

notice the DataBufferInt which is created here
 
1  
2  
3  
4  
5  
6  
7  
...
case DataBuffer.TYPE_INT:
            d = new DataBufferInt(w*h);
...
SunWritableRaster raster = (SunWritableRaster)
            createPackedRaster(d, w, h, w, bandMasks, location);
....


in Raster.createPackedRaster(DataBuffer buffer, ...

1  
2  
3  
case DataBuffer.TYPE_INT:
            return new IntegerInterleavedRaster(sppsm, dataBuffer, location);
....


finally, an IntegerInterleavedRaster is created, with the integer databuffer as basis..

now, in BufferedImage we can retrieve a reference to this raster.

1  
2  
3  
4  
private WritableRaster raster;
public WritableRaster getRaster() {
      return raster;
}


since IntegerInterleavedRaster ultimately extends WritableRaster, we can look at the method there

1  
2  
3  
public DataBuffer getDataBuffer() {
     return dataBuffer;
}


and finally, in DataBufferInt
1  
2  
3  
4  
private int[] data; 
public int[] getData() {
      return data;
}


so the method outlined will get you a reference to the underlying int array, for INT_ RGB or ARGB images.
4  Game Development / Newbie & Debugging Questions / Re: Questions about TGA Files on: 2006-11-28 10:28:33

Well, I have to admit my projects usually involve lots of small files as opposed to large files. But 30 sec vs <1sec ... it sounds unbelievable... does ImageIO suck that bad?
5  Game Development / Newbie & Debugging Questions / Re: Questions about TGA Files on: 2006-11-28 09:43:02
TBH,

I don't really see the need to store my images as TGA.

Loading times are trivial whichever format you use and it would make more sense in my mind (just a feeling) to use a more "advanced" format like PNG. For some reason, to me, a project feels more "robust" and "mature" when it uses PNGs instead of TGAs. silly ofcourse... oh well.. just my 2ct's  Grin
6  Games Center / Archived Projects / Re: W.I.P. - Advanced Particle Effects Editor on: 2006-11-28 00:28:35
Well you can still download a working version of the engine itself from

http://sourceforge.net/projects/particlereality

it's pretty well documented even.. *cough*..

you can define the particle effects' properties in the xml file ^_^

Regards,
- Tus
7  Games Center / Archived Projects / Re: W.I.P. - Advanced Particle Effects Editor on: 2006-11-28 00:20:47
and some more...

8  Games Center / Archived Projects / W.I.P. - Advanced Particle Effects Editor on: 2006-11-28 00:19:08
Hi,
just to get some feedback, here are some screenshots from the particle effects editor I am working on. I'll add more and even some webstarts as I add more and more functionality.

Regards,
-Tus



9  Java Game APIs & Engines / Tools Discussion / Re: Creating my own 'pak' file creator on: 2006-11-17 12:20:32
Who the hell would store ~40GB  of data in ONE file?
Beside polygons, models, textures, i'm also storing point clouds, where a single point of such an cloud consist of an
(x, y z ) (r, g, b) ( u,v ) and (normal.x, normal.y, normal.z) since this data is coming from a laser scanner it are billions of points(which are then divided in an octree)
so 40 gig is not that much

Perhaps it would make sense in this case to use a database instead of a file-structure?
10  Discussions / Miscellaneous Topics / Re: What's the next number in the sequence on: 2006-11-16 01:16:01
that's a nice formula.

now I want an explanation how it works Grin
11  Java Game APIs & Engines / Xith3D Forums / Re: Quality Code on: 2006-11-15 16:05:51
disclaimer: I'm just another programmer who doesn't contribute anything to xith.

from my work experience in tons of java projects (brackets at the same line) and .NET projects (brackets at the next line) ...

it doesn't matter one bit. Readability of bracketplacing is as measurable and objective as your personal experience of the color blue.

Personally I prefer brackets at the same line, but only because I'm used to it. Decide on a contract, interface, design etc and let the coder do his thing.

At work we let the editor's "reformat' options (eclipse & visual studio) decide.

Readability is very subjective and never really worth it to debate/enforce it beyond "good enough".
12  Java Game APIs & Engines / Tools Discussion / Re: 2D Particle Effect Editor on: 2006-11-15 15:20:18
Hi,

I'm going to revive my "particle reality project" and I'm bussy with a particle efffects editor for it which will be on par with the one used in particle illusion.

Particle Reality Project: http://sourceforge.net/projects/particlereality/
Particle Illusion (the editor and engine I'm trying to mimic): http://www.wondertouch.com

E.S.T.  - 20 december 2006 (depending on how much time I have)
13  Java Game APIs & Engines / JInput / Re: tablets & jinput on: 2006-04-09 16:30:10
Thats odd. My touchpad on my laptop has a pressure reading Smiley, although it's not listed as such.

So using JInput, how would you get to that data, could you give an example?  Grin (forgive my laziness)
14  Java Game APIs & Engines / JInput / Re: tablets & jinput on: 2006-04-09 16:20:36
Hi

I would *hope* these days, that directx exposes information on the tablets. Under linux the event API does it, and jinput sits right on that. So it *should* 'just work'.

I have *no* idea how it would work on the DS, unless someone gets me one and a dev kit, I’ll never find out either Smiley

Endolf
well the DS was just an example of a device which has great games using a pen. Smiley To be honest I'm only really interested to get pressure data (and 'it would be nice' to be able to get other data such as tilt) from tablets on the 3 PC platforms (windows, mac, linux).

With my tablet the stylus just appears as a regular mouse, I have no idea if it's possible to get the pressure out of it that way though.

well, the jinput api doc (don’t know about version 2 though) defines a
1  
Controller.Type.TRACKPAD
which is described as "A trackpad, such as a tablet, touchpad, or glidepad; note that this may sometimes be treated as a type of mouse."

I don't have a tablet right now (but I'm going to buy one next week) so I cannot test it right now, but I had some ideas I wanted to work on and I went on searching for information on tablets and java. I do believe JInput would benefit from exposing such information, but I don't know how hard it is to actually implement. (this remark is in case it is not possible, but perhaps it is... I'll go and poke around JInput 2, perhaps I can find some more clues there ^_^)
15  Java Game APIs & Engines / JInput / tablets & jinput on: 2006-04-09 12:11:50
Is it possible to retrieve pressure, tilt data from tablets using JINPUT (2)?

something like: http://www.csl.sony.co.jp/person/rekimoto/java/jwintab/ but I would like a multiplatform solution. You can use the data for some wicked games Smiley like the nintendo DS. 
16  Game Development / Shared Code / Re: Triangulizing any text, any Font, any Shape, for 3d use... on: 2006-04-02 15:03:30
Yeah, my host went down. Have to look for another one :<
17  Game Development / Performance Tuning / Re: png reading on: 2006-04-01 10:43:00
jpeg is lossy with no transparancy mask
gif is 256 color only with a 1 bit mask

png is far more advanced than either format. How exactly are they 'recommended'?

also, the problem was about dynamic loading of map portions, not about image formats.
18  Game Development / Newbie & Debugging Questions / Re: problem with calculation frames per second on: 2006-03-27 10:57:18
Get a start-time. (startTime = System.nano... for example)

in your drawing loop:
===
if (currentTime - startTime) >= 1 second {
     display or update the (fps) on screen;
     startTime = currentTime;
     fps = 0;
}
do your drawing.
Thread.yield();
fps++;
===

And be sure to let your sprite calculations be time-based, not frame-based.
19  Discussions / Miscellaneous Topics / Re: Oblivious on: 2006-03-26 15:44:31
6600GT, 1gb ram, 2.4 ghz P4. Settings on 'medium' and it runs as smooth as silk. It does crash sometimes... (every 5 hours ofzo). I love this game ^_^
20  Game Development / Newbie & Debugging Questions / Re: Want to make some small games in Java, am I realistic? And need advice on JO on: 2006-03-23 12:39:25
- Where can I find some free graphics and character animations? I am more into programming and do not like to spend too much time on the graphics, although I can do them pretty well if I have to

well, you can look here: http://sprites.fireball20xl.com/
and here: http://www.java-gaming.org/forums/index.php?topic=8246.0


- Does anyone have a good tutorial on how to be able to make a little game with a network and internet (IP) interface, so online multiplaying can be achieved? Is this a realistic goal for me to try this out, or will this take way too long to accomplish?

too long depends on what you want to do and what your definition of 'too long' is.  Tongue There are numerous threads on this forum about this subject, and basic client/server networking isn't that hard with java. Basically you have to ask yourself how 'synchronized' you want things to be. Personally I would recommend to assume the client has a crappy connection. Keep the game state on the server based on the input of the client, but on the client side interpolate between what you receive from the server. (and assume lost packets and long ping times)


- I also want to make a few simple 3D games. However, I have tried out both JOGL and LWJGL. I like them both but they both seem to be pretty platform dependent as they need the native libraries. How exactly can I make it happen that any 3d game I make will work with JOGL/LWJGL on any platform? I am using Netbeans by the way. Can I just add jogl.jar or lwjgl.jar to my project and import them inherently? What do I then do with all the natives from all the different systems? If I link to them, will they also be compiled in my eventual jar file? So the person who tries to play my game will not need to habe jogl/lwjgl installed himself?

Well, if you use java webstart for example, you can distribute both the lbrary as well as the native files (which are neccessary btw) and only the native files which the user needs through the specification of your webstart. I've stopped being afraid of native libraries. Its very easy. In your project, just import lwjgl or jogl. and have the native libraries available on your classpath.


- I saw a GLUT class somewhere in net.games.jogl. but I didn't see the possibility to really use the glut API like I am used to in C++   for example, I didnt see the glut function to draw a sphere. I am pretty sure GLU has one too though right? Is GLUT still in development for JOGL?


Well, for JOGL I'm not sure, but for LWJGL things have been shuffled around a bit. For example, there is a Sphere class, not a Sphere function. But I bet you can find most of the functionality of GLUT, their location, naming and implementation has just been shuffeled around.


- Do you think it is realistic for me to make little games in my spare time using Java? With little games I mean small 2d games with the complexity of something like bomberman. I got some ideas of my own too and I want to try to make some original but simple games, such that I can make them on my own, or maybe in a small group of enthousiasts. With 3D I will try to make some simple games too, like a racing game, or a fighting game, maybe a small fps. I am pretty sure I can program it all, I just need to get my hands on some graphics!


I'm pretty sure all of what you want can be done in your spare time. Especially the more simpler games can be done within a few weeks with only an hour a day. And since you already have that much experience with OpenGL and such it shouldn't be too much of a problem.


Anyways, my main purpose of this post was to get active on these forums. I am looking around on the forums as we speak to find some answers on the questions I posted here.

Looking forward to your contributions and games Smiley
21  Game Development / Performance Tuning / Re: A poor man's struct (err, MappedObject) on: 2006-03-22 19:06:11
Here are my results for both benchmarks. (including suggested improvements)

Benchy
1  
2  
3  
4  
5  
6  
7  
8  
9  
before FloatBuffer.allocate()
   float[]:               211ms
   unsafe:                218ms
   floatbuffer (direct):  304ms

after FloatBuffer.allocate()
   float[]:               249ms
   unsafe:                219ms
   floatbuffer (direct):  1150ms


UnsafeDemo:
1  
2  
3  
4  
5  
6  
7  
8  
Array time: 30.98215 ms
x array= 1.24908006E9
unsafe time 52.641886 ms
x unsafe= 1249216512
Floatbuffer time: 31.53641 ms
x array= 1.24949581E9
Directbytebuffer2float time: 101.041054 ms
x array= 1.14874189E9


22  Game Development / Shared Code / Re: Fastest get2fold algorithm on: 2006-03-21 13:35:04
Interesting results. Here are my results of your (slightly tweaked) benchmark: (numbers in seconds, lower is better)

1  
2  
3  
4  
Total Math.log method time: 35.26507531
Total Rolled out BS method time: 0.453305379
Total Shifty method time: 1.676443794
Total Logical method time: 0.957726191


(basically increased NUM to 5000000, changed System.currentTimeMillis() to System.nanoTime(), formatted the output to be in seconds and added all times from all runs of which you see the result here)
23  Game Development / Performance Tuning / Re: A poor man's struct on: 2006-03-20 09:38:23
Anyway, when I code the bytecode transformer on a rainy afternoon, you'll be the first to know.

It's raining where I am right now! and its almost afternoon Grin
24  Games Center / Archived Projects / Feedback Request: Interpolation Editor on: 2006-03-18 12:56:59

Hey all, I'm working on the editor for my particlereality project(also see the announcement on the forum here. )

please try it out and let me know
  • any general problems
  • the performance
  • odd behaviour
  • usability
  • missing features
  • likability  Grin



   
Webstart: http://cal007300.student.utwente.nl/vincent/particleReality/editor.jnlp

Features:
  • Change the scales of the grid axis by dragging the scrollbars
  • Drag the nodes around by left-clicking and dragging
  • Right click on a node to get a context menu where you can delete the node
  • Pressing Delete when hovering over a node deletes the node
  • Right click anywhere else to get a context menu where you can create a new node
  • Holding Shift while dragging a node snaps the node to the grid

Basically I want to know: is this a good UI? What would you change? What would you like to see?

Please have a look ^_^

Regards,
 - Vincent
25  Discussions / Miscellaneous Topics / Re: SUN Starfire on: 2006-03-17 23:08:26
One thing which I find funny is that when you look at "in-the-future" movies made in a few decades ago, is that the technological advances/dreams are there, but socialogical aspects always remain stuck in the 'then-current' timeframe. The way the woman and the men interact, the haircuts they have, the clothing, the language... everything still screams "1994! 1994! 1994!".
26  Discussions / General Discussions / Re: RuneScape is #1 on miniclip.com on: 2006-03-17 22:24:48
Quote
* Markus_Persson fails to see the connection between those two statements.
What I meant is that  what ever the language/technologies used, what makes a game a success is the contents and game play more than the visuals. We have a live example here.



a good example of this is Dofus Online a quite successfull niche-MMORPG in *drumroll* stand-alone flash!. you can sign up for a trial account if you like.
27  Java Game APIs & Engines / JOGL Development / Re: How to reduce video "tearing" (video texturing) / V-Sync ?? on: 2006-03-17 10:50:03
How did you get xvid/mp4 to work with JMF? I've written something similar to what you've done, but I never get sound with those :< only with MPG's I get sound
28  Game Development / Shared Code / Re: MoreMath (FastMath) on: 2006-03-15 19:51:51
...continued from post #1...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
    /**
     * Faster ceil function to convert a float to an int. Contrary to the java.lang.Math ceil function, this
     * function takes a float as an argument, returns an int instead of a double, and does not consider special
     * cases.
     */

    public static int ceil(float f) {
        if (f > 0) {
            return (int)f + 1;
        }
        else {
           return (int)f;
        }
    }

    /**
     * Faster floor function to convert a float to an int. Contrary to the java.lang.Math floor function, this
     * function takes a float as an argument, returns an int instead of a double, and does not consider special
     * cases.
     */

    public static int floor(float f) {
        if (f >= 0) {
            return (int)f;
        }
        else {
           return (int)f - 1;
        }
    }
   
    /**
     * Faster round function to convert a float to an int. Contrary to the java.lang.Math round function, this
     * function takes a float as an argument, returns an int and does not consider special
     * cases.
     */

    public static int round(float f) {
        return (int)MoreMath.floor(f+0.5f);
    }

    /**
     * Returns true if the specified number is a power of 2.
     */

    public static boolean isPowerOfTwo(int n) {
        return ((n & (n-1)) == 0);
    }
   
    /**
     * Gets the number of "on" bits in an integer.
     */

    public static int getBitCount(int n) {
        int count = 0;
        while (n > 0) {
            count+=(n & 1);
            n>>=1;
        }
        return count;
    }
   
    /**
     * A faster pow function tot calculate x^n. It is vital that n>0 or this function will have an infinite loop.
     * @param x a float number.
     * @param n an interger.
     * @return x^n is returned.
     */

    public static float pow(float x,int n) {
       if(n == 0) {
          return 1;
       }
       else {
         float y = x;
         for(int i=1; i!=n; i++) {
            y *= x;
         }
         return y;
       }
    }
   
    public static int abs(int x) {
       if(x < 0) {
          return (-x);
       }
       return x;
    }
   
   public static float abs(float x) {
      if(x < 0) {
         return (-x);
      }
      return x;
   }
   
   /**
    * This converts a color (3 int values representing red, green and blue components ranging from 0 to 255) to an
    * 8-bit ARGB color (0xAARRGGBB, where A for alpha, R for red, G for green and B for blue).
    * @param c1 the red component of the color to convert.
    * @param c2 the green component of the color to convert.
    * @param c3 the blue component of the color to convert.
    * @param alpha the alpha value.
    * @return the converted color.
    */

   public static int convertToARGB(int alpha,int c1,int c2,int c3) {
      return ((alpha << 24) | (c1 << 16) | (c2 << 8) | c3);
   }
   
   /**
    * This converts a color (3 float values representing red, green and blue components ranging from 0 to 1) to an
    * 8-bit ARGB color (0xAARRGGBB, where A for alpha, R for red, G for green and B for blue).
    * @param x the color to convert.
    * @param alpha the alpha value.
    * @return the converted color.
    */

   public static int convertToARGB(float alpha,float[] x) {
      return convertToARGB((int)(alpha*255),(int)(x[0]*255),(int)(x[1]*255),(int)(x[2]*255));
   }
   
   /**
    * This converts a color (3 int values representing red, green and blue components ranging from 0 to 255) to an
    * 8-bit RGB color (0xRRGGBB, where R for red, G for green and B for blue).
    * @param c1 the red component of the color to convert.
    * @param c2 the green component of the color to convert.
    * @param c3 the blue component of the color to convert.
    * @return the converted color.
    */

   public static int convertToRGB(int c1,int c2,int c3) {
      return ((c1 << 16) | (c2 << 8) | c3);
   }
   
   /**
    * This converts a color (3 float values representing red, green and blue components ranging from 0 to 1) to an
    * 8-bit RGB color (0xRRGGBB, where R for red, G for green and B for blue).
    * @param x the color to convert.
    * @return the converted color.
    */

   public static int convertToRGB(float[] x) {
      return convertToRGB((int)(x[0]*255),(int)(x[1]*255),(int)(x[2]*255));
   }
   
   /**
    * This converts a color (an integer value in the 8-bit RGB color model) to its components (3 float values
    * representing red, green and blue components ranging from 0 to 1).
    * @param color the color to convert.
    * @param dest the array to store the colors in (length must be >=3)
    */

   public static void convertFromRGB(int color,float[] dest) {
      dest[0] = (float)((color >> 16) & 0xFF) * ARGB_DECONVERT_SCALING;
      dest[1] = (float)((color >> 8) & 0xFF) * ARGB_DECONVERT_SCALING;
      dest[2] = (float)(color & 0xFF) * ARGB_DECONVERT_SCALING;
   }
   
   /**
    * This converts a color (an integer value in the 8-bit RGB color model) to its components (3 float values
    * representing red, green and blue components ranging from 0 to 1).
    * @param color the color to convert.
    * @return the converted color.
    */

   public static float[] convertFromRGB(int color) {
      float[] x = new float[3];
      convertFromRGB(color,x);
      return x;
   }
   
   public static float getAlphaf(int color) {
      return (float)((color >> 24) & 0xFF) * ARGB_DECONVERT_SCALING;
   }
   public static float getRedf(int color) {
      return (float)((color >> 16) & 0xFF) * ARGB_DECONVERT_SCALING;
   }
   public static float getGreenf(int color) {
      return (float)((color >> 8) & 0xFF) * ARGB_DECONVERT_SCALING;
   }
   public static float getBluef(int color) {
      return (float)(color & 0xFF) * ARGB_DECONVERT_SCALING;
   }
   public static int getAlphai(int color) {
      return (int)((color >> 24) & 0xFF);
   }
   public static int getRedi(int color) {
      return ((color >> 16) & 0xFF);
   }
   public static int getGreeni(int color) {
      return ((color >> 8) & 0xFF);
   }
   public static int getBluei(int color) {
      return (color & 0xFF);
   }
}
29  Game Development / Shared Code / MoreMath (FastMath) on: 2006-03-15 19:51:17
Hey, I found this in a realtime raytracing software thingie which I downloaded a long time ago. Could be interesting. Unfortunately there was no README or something in the package so I cannot give credit to the person who wrote this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
/**
 * The MoreMath class provides functions not contained in the java.lang.Math or java.lang.StrictMath classes.
 */

public class MoreMath {
   
   //a sin table with 4096 entries
  private static final int SIN_TABLE_SIZE_BITS = 12;
   private static final int SIN_TABLE_SIZE = 1 << SIN_TABLE_SIZE_BITS;
   private static final int SIN_TABLE_SIZE_MASK = SIN_TABLE_SIZE - 1;
   private static final int SIN_HALF_PI = SIN_TABLE_SIZE / 4;
   private static final float SIN_CONVERSION_FACTOR = (float)(SIN_TABLE_SIZE / (2*Math.PI));
   
   private static float[] sinTable;
   
   //a asin table with 2000 entries
  private static final int ASIN_TABLE_SIZE = 2001;
   private static final float ASIN_CONVERSION_FACTOR = (float)((ASIN_TABLE_SIZE-1) / 2);
   
   private static float[] asinTable;
   
   //a sqrt table with 1024 entries (for 0 to 1)
  private static final int SQRT_TABLE_SIZE = 1025;
   private static final float SQRT_CONVERSION_FACTOR = (float)((SQRT_TABLE_SIZE-1));
   
   private static float[] sqrtTable;
   
   public static final float PI = (float)(Math.PI);
   public static final float HALF_PI = (float)(Math.PI / 2.0);
   public static final float TWO_PI = (float)(Math.PI * 2.0);
   public static final float PI_INV = (float)(1.0 / Math.PI);
   public static final float HALF_PI_INV = (float)(2.0 / Math.PI);
   public static final float TWO_PI_INV = (float)(1.0 / (Math.PI * 2.0));
   
   //some coefficients for conversion from the RGB-model to RGB components.
  //Using bitshifting instead of multiplication is faster.
  //private final int[] RGB_CONVERT_COEFF = {0x010000,0x000100,0x000001};
  //The blue channel occupies the first 8 bits of the color, the green channel the next 8 bits and the
  //red channel the last 8 bits. I extract those bits by multiplying with a number that only has ones on those
  //bits. Finally I shift back and divide by 255.
  /*private static final int[] ARGB_DECONVERT_COEFF = {
       ((1<<24) + (1<<25) + (1<<26) + (1<<27) + (1<<28) + (1<<29) + (1<<30) + (1<<31)),
      ((1<<16) + (1<<17) + (1<<18) + (1<<19) + (1<<20) + (1<<21) + (1<<22) + (1<<23)),
      ((1<<8) + (1<<9) + (1<<10) + (1<<11) + (1<<12) + (1<<13) + (1<<14) + (1<<15)),
      ((1<<0) + (1<<1) + (1<<2) + (1<<3) + (1<<4) + (1<<5) + (1<<6) + (1<<7))
      };*/

   //I'm now shifting first and the just chop of what I need.
  private static final float ARGB_DECONVERT_SCALING = 1f / 255f;
   
   
   //init tables when this class is loaded
  static {
      init();
   }
   
   private static void init() {
      sinTable = new float[SIN_TABLE_SIZE];
      for(int i=0; i<SIN_TABLE_SIZE; i++) {
         sinTable[i] = (float)Math.sin(i / SIN_CONVERSION_FACTOR);
      }
     
      asinTable = new float[ASIN_TABLE_SIZE];
      for(int i=0; i<ASIN_TABLE_SIZE; i++) {
         asinTable[i] = (float)Math.asin((i / ASIN_CONVERSION_FACTOR) - 1);
      }
     
      sqrtTable = new float[SQRT_TABLE_SIZE];
      for(int i=0; i<SQRT_TABLE_SIZE; i++) {
         sqrtTable[i] = (float)Math.sqrt(i / SQRT_CONVERSION_FACTOR);
      }
   }
   
   /**
    * Gives the square root faster if 0 <= x <= 1.
    * @param x the value to get the root of.
    * @return the root.
    */

   public static float sqrt(float x) {
      if(x>1) {
         return (float)Math.sqrt(x);
      }
      return sqrtTable[(int)(x*SQRT_CONVERSION_FACTOR)];
   }
   
   /**
    * Cosine function with the angle from 0 to 2*Pi.
    * @param angle the angle (float).
    * @return the cosine of the angle.
    */

   public static float cos(float angle) {
      return sinTable[(SIN_HALF_PI-((int)(angle * SIN_CONVERSION_FACTOR))) & SIN_TABLE_SIZE_MASK];
   }
   
   /**
    * Sine function with the angle from 0 to 2*Pi.
    * @param angle the angle (float).
    * @return the sine of the angle.
    */

   public static float sin(float angle) {
      return sinTable[((int)(angle * SIN_CONVERSION_FACTOR)) & SIN_TABLE_SIZE_MASK];
   }
   
   /**
    * Acosine function with the x from -1 to 1.
    * @param x the x (float).
    * @return the acosine of the x.
    */

   public static float acos(float x) {
      if(x > 1) {
         x = 1;
      }
      else if(x < -1) {
          x = -1;
      }
      return (HALF_PI-asinTable[((int)((x+1) * ASIN_CONVERSION_FACTOR))]);
   }
   
   /**
    * Asine function with the x from -1 to 1.
    * @param x the x (float).
    * @return the asine of the x.
    */

   public static float asin(float x) {
      if(x > 1) {
         x = 1;
      }
      else if(x < -1) {
          x = -1;
      }
      return asinTable[((int)((x+1) * ASIN_CONVERSION_FACTOR))];
   }

    /**
     * Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.
     */

   public static int sign(short v) {
        return (v>0)?1:(v<0)?-1:0;
    }

    /**
     * Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.
     */

    public static int sign(int v) {
        return (v>0)?1:(v<0)?-1:0;
    }

    /**
     * Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.
     */

    public static int sign(long v) {
        return (v>0)?1:(v<0)?-1:0;
    }

    /**
     * Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.
     */

    public static int sign(float v) {
        return (v>0)?1:(v<0)?-1:0;
    }

    /**
     * Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.
     */

    public static int sign(double v) {
        return (v>0)?1:(v<0)?-1:0;
    }

.. continued..
30  Java Game APIs & Engines / Java 2D / Re: Java 2D FAQ on: 2006-03-14 17:45:54
I agree with the points you raised and I think I can manage to live with that Q/A entry Smiley
Pages: [1] 2 3 4
 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!