Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 22nd, 2008, 07:55 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Thumbs up 3D Browser-based Game Development

I am developing a video game in JAVA, called "Universe Storage". It is going to be a multi-player online browser-based 3D video game. You will control a character who has been accidentally thrown into the future by a company called "Universe Storage". A disgruntled robot will be your guide as you learn to construct your home, go to school, earn money, build and program robots and weapons, and fight in futuristic battles. I am planning to post progress here throughout development, and problems I encounter along the way. Anyone interested in getting involved, providing feedback, beta testing, or obtaining source code, just send me an email to paul@paulscode.com .

Reply With Quote
  #2  
Old January 23rd, 2008, 05:23 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Lightbulb 3D in a JAVA Applet, and adding 2D Overlay

This is a progress update for my game. Earlier this week, I did a little research on using OpenGL within a JAVA applet. I came across an interesting 3D browser based game called "Zoltar's Return" (I can't post the link, since I am a new member, so if you want to see more about it, just email me, or google it). It is launched from something called JOGLAppletLauncher. This program has a lot of features I really like, such as simplifying the whole digital signatures and JAVA sandbox thing. I decided to try it out, so I downloaded everything I need to use the applet launcher. I made a simple test program which runs the famous JOGL gears demo as an applet. I know, there are plenty of intelligent folks out there who have done that before, but it was a learning process for me to figure it out for myself.
The next thing I decided to look into was putting a 2D overlay on top of the rendered 3D scene (basically a "heads-up" style overlay). I googled around a bit, and came across an interesting program called "Photo Cube". The source code for the program has a really sweet class in it called CompositeGLJPanel, which simplifies the mixing of JOGL and Swing. I only had to alter the class a little bit to get it working in a test applet, which combines the gears demo with a 2D background and forground.
Both these applets test important concepts I will need for my game. If you would like more information on them, you can post your questions here, or email me directly if you would like the source code.

Reply With Quote
  #3  
Old January 24th, 2008, 06:51 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Robot Builder: Essential Elements of a Game

There are several things that are essential to most games, like processing input, playing sounds, and the like. While I have made a few games in C++ before, I have not ever attempted one in JAVA. Therefore, I think the best way to pick up some of the basic skills I will need for Universe Storage, is to write a simple 2D game in JAVA first. Based on the applet-launcher and CompositeGLJPanel infrastructure I have now, I am going to create a 2D browser game. I decided that, since one of the things I want to have in Universe Storage is the ability to program robots, this test game will be a 2D robot builder game.

Reply With Quote
  #4  
Old January 26th, 2008, 10:47 AM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Basic Logic Gates

This is a progress update on Robot Builder. The basic idea of the game is to create IC chips, then wire them up inside a robot to make it do stuff. It is a little like the concept of an old game I used to play called "Robot Odyssey" (This game was a great way for anyone to learn the basics of logic and electric engineering in a relaxed-pace, fun environment - one of my favorites back in the day. I recommend googling it). I created a class called "Part", which is managed in a class called "PartManager". From the "Part" template, I created the following logic gates: AND, NAND, OR, NOR, XOR, XNOR, and NOT. I also made TFlipflops and SRFlipflops. From my tests they all seem to be functioning correctly, and the PartManager works like a charm. I am now moving on to the graphical components. If you are interested in reading more about electric engineering, Wikipedia has some great information on the subject.

Reply With Quote
  #5  
Old January 27th, 2008, 07:44 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Animated Robot

I have been making headway in the graphics for Robot Builder. I discovered two ways to load image files into BufferedImages (which can easily be put into Textures for use in 3D when I finish Robot Builder and work on Universe Storage). One way is (in NetBeans) to put the images into a package, and to get the image in the program, use:
Code:
BufferedImage img = ImageIO.read( new BufferedInputStream( 
    getClass().getClassLoader().getResourceAsStream( filename ) ) );

This appears to make the image part of the compiled jar. The other way is to use:
Code:
String imagesPath = "blah";  // put the url to your images
URL url = new URL( imagesPath + filename ); 
BufferedImage img = ImageIO.read(url);

This allows the program to pull the images of the web. I decided the best way for me is to use the URL method. That way it won't take as long to download the applet, and I could potentially display a message to the player while the images are loading. I created a simple template class for drawing animations. From this class I created a simple robot. It doesn't do anything yet, but it is animated.

Reply With Quote
  #6  
Old January 29th, 2008, 07:08 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Today I added a map to the Robot Builder game. It is a really simple 2-layer tile map, with tiles being either solid or not (I'm not going for awesome looks just yet).



If I ever decided to take Robot Builder to the next level: a real, distributable game, I could easily add in a foreground layer, draw a collection of really nice-looking tiles, and expand on the basic functionality I have in place now.
I also completed the code for object movement on the screen and hit-detection to prevent an object from passing through solid tiles. I've run several tests, and everything seems to be in order. I am now ready to move on to the wiring and IC chip creation parts of the game.

Reply With Quote
  #7  
Old January 30th, 2008, 09:47 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Menu and Mouse Functions

Today I created Robot Builder's tool menu, which has two buttons. The first one will open the IC Chip tool. The other will open and close the "Toolkit", which contains all the logic gates. I am also receiving and keeping track of mouse events from the two menu buttons and the robot.
When these interfaces are complete, this is how the game will work:

1) Open the Chip editor to create a new IC Chip
2) Open the toolkit and pull logic gates out
3) Hook them up inside the chip however you like.
4) Save your chip.
5) Click the robot to work on it.
6) Pull the chip out of the toolkit
7) Wire it up inside the robot.

When you are done, sit back and watch the robot go (or not go, depending on how good your logic skills are )

Reply With Quote
  #8  
Old January 31st, 2008, 06:55 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Hotwired Bot

Today I completed the code for bumpers (wall detectors), drive (robot movement), and antenna. I hotwired the robot with a simple wallhugger circuit, using 2 SR FlipFlops:



I am continuing work on the graphics interface for hooking up chips and logic gates. There is still quite a bit of work left to do on this.

Reply With Quote
  #9  
Old February 1st, 2008, 07:09 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Why Robot Builder?

I have been asked a few times how the concept of robot building is going to fit into Universe Storage, so I thought I would take a little time to explain it here, in case anyone else was wondering about that. Universe Storage is going to be an economy-driven game. Characters will have skills, which various activities in the game will increase. Higher skill numbers will mean better weapons you can use, more quests you can do, and more valuable things you can make. Robots will be useful for assisting players in combat, obtaining items, or completing quests. It will be possible to construct robots and weapons from parts you make yourself, buy in shops or from other players, or win in quests. Where the "Robot Builder" concept comes into play, is players will then be able to design chips, and wire them up in their robots and weapons. They can then either use the weapons and bots themselves, or sell them to other players who don't have the logic skills to design chips, or who are more interested in other aspects of the game, like leveling other skills, questing, or PK'ing.

Reply With Quote
  #10  
Old February 4th, 2008, 08:04 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Parts and Wiring

I have finished drawing the images for logic gates and chips. I am still working on the code for wiring parts together.



This is a bit more complicated than you might think. The wires that connect parts must be able to dynamically change their length and orientation as the player moves already-wired parts around on the screen. The player will need to be able to move parts and change the orientation of wires to avoid the "birds nest" effect (messy jumbles of wires and parts) that can happen when designing a complicated circuit.

Reply With Quote
  #11  
Old February 18th, 2008, 10:41 AM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Unhappy AppletLauncher Problems!

Well, as every developer knows, sometimes you try a path that looks good for a while, but then you hit a brick wall.
I have been trying some compatibility tests with the RobotBuilder program. I have been developing the game from my desktop PC, which is pretty fast, has a fair amount of RAM, and has a nice graphics card. For me, the game runs fast and smooth, exactly how you would expect such a really simple game to run.
However, on every one of my friends' computers, as well as on my two laptops, there are numerous problems. For more than half of the computers trying to run the game, the applet never loaded at all. This problem had a simple fix: updating the JAVA runtime environment. However, then there are more serious problems. It seems that for run-of-the-mill computers with fairly good graphics cards, the game will not crash, but it will run really slow and choppy. With run-of-the-mill graphics cards, computers will not only run slowly, but the game will crash the browser. On one machine, the program actually affected Microsoft Windows so badly, the computer had to be rebooted! I have done a lot of digging into the problem, rewritten some things, streamlined code. Nothing seems to help.
It occured to me that perhaps the problem is not from my code, but in the AppletLauncher technology I am using to launch the game. I had some of my friends run the Zoltar's Return game I mentioned earlier which also uses the AppletLauncher, and sure enough, many of them had problems running it too! The most common problem seemed to be only half the screen being drawn, and the browser eventually crashing.
This leaves me with a couple of options. One, I could simply require the user to have a fast computer with a good graphics card. That, of course, would limit the number of potential players, and could cause problems for people trying to run the game on not-so-good machines. The second option is to do some more research to see if there is a more stable way to run 3D within an applet (any suggestions would be appreciated!). I definitely prefer the second option, because if a tiny little game like RobotBuilder is so resource-intensive, who knows what a full 3D game would require!

Reply With Quote
  #12  
Old February 18th, 2008, 10:29 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Arrow A new way to put 3D into an applet

I did some research into other methods of running 3D inside an applet, and came across an interesting project called 3DzzD, located at:
http://www.dzzd.net
It has a couple of features I really like, such as working on all versions of Java back to 1.1, and the ability to let the user switch between either software rendered or hardware accelleration modes. Also, the library has a function for loading 3ds files, which is something I am going to need to be able to do in my game. 3ds files are loaded on seperate threads, allowing me to put up a progress indicator, which is also nice.
I ran the demo applets on three different machines, and they seems to run without problems (btw, if a few of you would go try them out and let me know how they run on your computer, that would be awesome).
As nice as it looks, I am having a tiny problem, though. I have been trying to re-create my 3D-gears test applet using the new 3DzzD library, but I do not seem to be able to load any 3ds files I create - only the 3ds files used in the demo programs will load. I even made a really small simple cube model, but it will not load. Tests show the code is getting into an unending loop in render3DObjectMonitor (the place where I would put the progress-bar). The file just never finishes loading. I am not sure if maybe I am creating my models incorrectly (wrong lighting, material, etc).
I am not giving up just yet - I really would like to get this library to work, as it would make things a lot easier down the road. Any help on this would be really appreciated, too, if any of you out there have either had experience with or at least an interest in 3ds files.

Reply With Quote
  #13  
Old February 22nd, 2008, 11:05 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Lightbulb Back on Track!

I am now using the jPCT 3D engine, which can be found at:
http://www.jpct.net
This library is really awesome. It is compatible with all versions of JAVA, back to 1.1, allows switching between hardware-accellerated or software-rendered modes, and can load .3ds 3D model files (definitely a bonus!)
BTW, if any of you want to know how to make 3ds files, here is what I am doing:

1) First you need to install "Turbo Squid gmax" (it's a free 3D modeling program), located at:
http://www.turbosquid.com/gmax
2) Next, you need the "Quake-3 MD3 exporter beta v1.0 - gmax" exporter pluggin, which you can get at:
http://www.davidhsmith.net/Essential_Tools.htm
3) Finally, you need LithUnwrap, located at:
http://www.sharecg.com/v/5169/softw...per-for-Windows

I simply create a model in gmax, export it to Quake MD3 format, open it in LithUnwrap to add materials etc, then save it as 3ds.
I made some gear models (which I am pretty proud of ), and recreated the gears demo - this time in jPCT.
Go take a look at it: http://www.paulscode.com/source/jPCTGears/
Let me know if it runs slow on your computer or any other issues.

Next, I will look into adding in a 2D overlay (that sounds familiar ...)

Reply With Quote
  #14  
Old February 23rd, 2008, 05:22 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Arrow Swing 2D Background and Foreground with jPCT

I finished writing the code for mixing Swing 2D background and foreground with jPCT.
To see the demo program I wrote, go to:

http://www.paulscode.com/source/jPCTSwingMix/

Let me know if any of you have problems running this applet. I am going to start transitioning the Robot Builder code over to this new framework.

Reply With Quote
  #15  
Old February 25th, 2008, 10:46 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Still tinkering with the gears demo...

In case anyone went to paulscode.com before and found the gears demo applet not working, I was doing some work on it at the time. I am trying to implement the ability to switch between hardware-accelerated and software-rendered modes. This will allow my programs to be useful to more people. I am using a program called lwjgl to load the applet, which allows me to display a logo and progress bar while the applet is loading. It will also simplify the digital-signature thing, and give me that hardware-accelerated capability, if I can ever figure the darn thing out, lol.

Reply With Quote
  #16  
Old February 26th, 2008, 08:48 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Finished tinkering...

I eventually figured out how to use lwjgl, and how to run my applet in hardware-accelerated mode. However, I have decided not to pursue the hardware-accelerated rout for my game. There are two reasons: The first reason is that writing the applet in hardware-accelerated mode is different enough from writing it in software-mode, that the code not only gets really complicated, but also it forces me to do some things in the applet which slow down performance when running in pure software mode. The second reason is that in hardware-accelerated mode, it is very difficult to add in the 2D overlay and background (it requires projecting the 2D image onto a polygon in the 3D world). So for now, I will just continue to write my game in software-rendered mode. At some later date I may tackle this issue again, but for now software mode is working well. I will, however, continue to use the lwjgl applet loader, because it loads up fast, and shows a progress bar as the main applet is loading. That way I can just stick all my resources inside the main JAR for easy referencing.

Reply With Quote
  #17  
Old February 27th, 2008, 09:03 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Thumbs up Robot Builder Back On Track!

I finished changing Robot Builder over to the new framework. It is running really well on my computer (I may have to limit the frame rate - that robot can really move!) I added an FPS indicator to the top-right of the applet. If any of you get a chance, go check it out and let me know what kind of frame rate you are getting. If you have any other problems, let me know! The address again, is: http://www.paulknows.com/Games/RobotBuilder/

Reply With Quote
  #18  
Old March 1st, 2008, 04:11 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Menus and Wiring

Today I finished writing the code for a class called "ComponentConnection", which connects two pins together and draws a circuit path between them. It changes color depending on whether or not the connection is "hot" (electricity flowing through). It's orientation can be changed by dragging it with the mouse or moving the two pins it is connecting. I have also begun writing the framework needed to incorporate this class into the Robot Builder game (you never realize the amount of work you have to do on something until you start doing it, seems like). I needed a menu system for the toolkit, the chip editor, and the robot circuitry components of the game, so that is something else I have been working on for the past few days. You may have noticed a few little changes if you've visited the link. I've been trying to re-upload the game each time I finish and test something new, so people can see the progress I'm slowly making on it.

Reply With Quote
  #19  
Old March 5th, 2008, 10:14 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Thumbs up Sound Effects

I was getting a little bored with the chip editor, so I decided to work on sound for a while. I will be using the JOAL library, because it plays sounds in 3D (which I will be needing when I get back to the 3D stuff). This library is really complicated, but the flexibility it offers is awesome. I purchased a book by Andrew Davison, called Pro Java 6 3D Game Development (a very good book, btw). There is a chapter in the book dedicated to JOAL, and it goes into creating a class to simplify loading, playing, and moving sounds in 3D. I followed the guide in the book to create a SoundManager class. Here is the source code for that class:
Code:
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import net.java.games.joal.AL;
import net.java.games.joal.ALException;
import net.java.games.joal.ALFactory;
import net.java.games.joal.util.ALut;

public class SoundManager
{
    // where the sound files are stored:
    private final static String SOUND_DIR = "Sounds\\";
    
    // Note: currently configured to only load WAV sounds
    private final static String FILE_EXT = ".wav";
    
    // Global stores for the sounds:
    private HashMap<String, int[]> buffersMap;  // (name, buffer) pairs
    private HashMap<String, int[]> sourcesMap;  // (name, buffer) pairs
    private AL al;    
    
    private float listenerX, listenerY, listenerZ;  // current position
    private float[] listenerOrientation;  // orientation
    private float listenerAngle = 0;  // listener's angle (in radians)
    
    public SoundManager()
    {
        buffersMap = new HashMap<String, int[]>();
        sourcesMap = new HashMap<String, int[]>();
        
        initOpenAL();
        initListener();
    }
    
    private void initOpenAL()
    {
        try
        {
            ALut.alutInit();   // creates an OpenAL context
            al = ALFactory.getAL();  // used to access OpenAL
            al.alGetError();
            
            // System.out.pringln( "JOAL version: " + Version.getVersion());
        }
        catch( ALException e )
        {
            e.printStackTrace();
            System.exit( 1 );
        }
    }    
    
    // Position and orientate the listener:
    private void initListener()
    {
        listenerX = 0.0f;
        listenerY = 0.0f;
        listenerZ = 0.0f;

        // position the listerner at the origin:
        al.alListener3f( AL.AL_POSITION, listenerX, listenerY, listenerZ );
        
        al.alListener3i( AL.AL_VELOCITY, 0, 0, 0 );  // no velocity
        
        // first 3 elements are "look at" point
        // second 3 are the "up direction"
        listenerOrientation = new float[] {listenerX, listenerY, listenerZ - 1.0f, 0.0f, 1.0f, 0.0f };
        
        al.alListenerfv( AL.AL_ORIENTATION, listenerOrientation, 0);
    }
    
    public void cleanUp()
    {
        Set<String> keys = sourcesMap.keySet();
        Iterator<String> iter = keys.iterator();
        
        String nm;
        int[] buffer, source;
        while( iter.hasNext() )
        {
            nm = iter.next();
            
            source = sourcesMap.get(nm);
            System.out.println( "Stopping " + nm);
            al.alSourceStop( source[0] );
            al.alDeleteSources( 1, source, 0 );
            
            buffer = buffersMap.get( nm );
            
            al.alDeleteBuffers( 1, buffer, 0 );
        }
        
        ALut.alutExit();
    }
    
    public boolean load( String nm, boolean toLoop )
    {
        if( sourcesMap.get( nm ) != null )
        {
            System.out.println( nm + " already loaded" );
            return true;
        }
        
        int[] buffer = initBuffer( nm );
        if( buffer == null )
            return false;
        
        int[] source = initSource( nm, buffer, toLoop );
        
        if( source == null )
        {
            // no need for the buffer anymore
            al.alDeleteBuffers( 1, buffer, 0 );
            return false;
        }
        
        if( toLoop )
            System.out.println( "Looping source created for " + nm );
        else
            System.out.println( "Source created for " + nm );
        
        buffersMap.put( nm, buffer );
        sourcesMap.put( nm, source );
        return true;
    }
        
    public boolean load( String nm, float x, float y, float z, boolean toLoop )
    {
        if( load( nm, toLoop ) )
            return setPos( nm, x, y, z );
        else
            return false;
    }
    
    // Create arrays for holding various sound files:
    private int[] initBuffer( String nm )
    {
        int[] format = new int[1];
        ByteBuffer[] data = new ByteBuffer[1];
        int[] size = new int[1];
        int[] freq = new int[1];
        int[] loop = new int[1];
        
        // load WAV file into the data arrays
        String fnm = SOUND_DIR + nm + FILE_EXT;
        try
        {
            ALut.alutLoadWAVFile( fnm, format, data, size, freq, loop );
        }
        catch( ALException e )
        {
            System.out.println( "Error loading WAV file: " + fnm );
            return null;
        }
        // System.out.println( "Sound size = " + size[0] );
        // System.out.println( "Sound freq = " + freq[0] );
        
        // create an empty buffer to hold the sound data
        int[] buffer = new int[1];
        al.alGenBuffers( 1, buffer, 0 );
        if( al.alGetError() != AL.AL_NO_ERROR )
        {
            System.out.println( "Could not create a buffer for " + nm );
            return null;
        }
        
        // store data in the buffer
        al.alBufferData( buffer[0], format[0], data[0], size[0], freq[0] );        
        
        return buffer;
    }
    
    // Create a source (a point in space that makes sound):
    private int[] initSource( String nm, int[] buf, boolean toLoop )
    {
        int[] source = new int[1];
        al.alGenSources( 1, source, 0 );
        if( al.alGetError() != AL.AL_NO_ERROR )
        {
            System.out.println( "Error creating source for " + nm );
            return null;
        }
        
        // configure the source
        al.alSourcei( source[0], AL.AL_BUFFER, buf[0] ); // bind buffer
        al.alSourcef( source[0], AL.AL_PITCH, 1.0f );
        al.alSourcef( source[0], AL.AL_GAIN, 1.0f );
        // Position the source at the origin:
        al.alSource3f( source[0], AL.AL_POSITION, 0.0f, 0.0f, 0.0f );
        al.alSource3f( source[0], AL.AL_VELOCITY, 0, 0, 0 ); // no velocity
        if( toLoop )
            al.alSourcei( source[0], AL.AL_LOOPING, AL.AL_TRUE );  // looping
        else
            al.alSourcei( source[0], AL.AL_LOOPING, AL.AL_FALSE ); // play once
        
        if( al.alGetError() != AL.AL_NO_ERROR )
        {
            System.out.println( "Error configuring source for " + nm );
            return null;
        }
        
        return source;
    }
    
    // Move the nm sound to (x, y, z):
    public boolean setPos( String nm, float x, float y, float z )
    {
        int[] source = (int[]) sourcesMap.get( nm );
        if( source == null )
        {
            System.out.println( "No source found for " + nm );
            return false;
        }
        
        al.alSource3f( source[0], AL.AL_POSITION, x, y, z );
        return true;
    }
    
    public boolean play( String nm )
    {
        int[] source = (int[]) sourcesMap.get( nm );
        if( source == null )
        {
            System.out.println( "No source found for " + nm );
            return false;
        }
        
        // System.out.println( "Playing " + nm );
        al.alSourcePlay( source[0] );
        return true;
    }
    
    // move the listener by (x, z) step
    public void moveListener( float xStep, float zStep )
    {
        float x = listenerX + xStep;
        float z = listenerZ + zStep;
        setListenerPos( x, z );
    }
    
    // position the listener at (xNew, zNew)
    public void setListenerPos( float xNew, float zNew )
    {
        float xOffset = xNew - listenerX;
        float zOffset = zNew - listenerZ;
        
        listenerX = xNew;
        listenerZ = zNew;
        al.alListener3f( AL.AL_POSITION, listenerX, listenerY, listenerZ );
        
        // keep the listener facing the same direction by
        // moving the "look at" point by the (x,z) offset
        listenerOrientation[0] += xOffset;
        listenerOrientation[2] += zOffset;
        // no need to change the y-coord since listener only moves over XZ plane
        
        al.alListenerfv( AL.AL_ORIENTATION, listenerOrientation, 0 );
    }
    
    // turn the listener counterclockwise by deg DEGREES
    public void turnListener( int deg )
    {
        setListenerOrientation( (int)Math.toDegrees(listenerAngle) + deg );
    }
    
    // turn the listener counterclockwise by rad RADIANS
    public void turnListener( float rad )
    {
        setListenerOrientation( listenerAngle + rad );
    }
    
    // set the listener's orientation to be deg DEGREES
    // in the counterclockwise direction around the y-axis
    public void setListenerOrientation( int deg )
    {
        listenerAngle = (float)Math.toRadians( deg );
        double angle = (double) listenerAngle;
        float xLen = -1.0f * (float) Math.sin( angle );
        float zLen = -1.0f * (float) Math.cos( angle );
        
        // face in the (xLen, zLen direction by adding the
        // values to te listener position
        listenerOrientation[0] = listenerX + xLen;
        listenerOrientation[2] = listenerZ + zLen;
        al.alListenerfv( AL.AL_ORIENTATION, listenerOrientation, 0 );
    }
    
    // set the listener's orientation to be rad RADIANS
    // in the counterclockwise direction around the y-axis
    public void setListenerOrientation( float rad )
    {
        listenerAngle = rad;
        double angle = (double) listenerAngle;
        float xLen = -1.0f * (float) Math.sin( angle );
        float zLen = -1.0f * (float) Math.cos( angle );
        
        // face in the (xLen, zLen) direction by adding the
        // values to te listener position
        listenerOrientation[0] = listenerX + xLen;
        listenerOrientation[2] = listenerZ + zLen;
        al.alListenerfv( AL.AL_ORIENTATION, listenerOrientation, 0 );
    }
    
}

As you can see, there are some functions for 3D sounds (which I have not yet tested, so there are probably bugs). Initial tests of loading sounds and playing them (looping and non-looping) seem to work. Next I will look into putting sound into Robot Builder (perhaps a bump sound when the robot hits the wall).

Reply With Quote
  #20  
Old March 6th, 2008, 08:12 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
lwjgl vs. JOAL

Well, I discovered that lwjgl has its own Java binding of the OpenAL sound library, and that it is incompatible with the JOAL binding I mentioned in my last post. I actually embarrassed myself a little yesterday by posting a JOAL question on an lwjgl forum -doh!

ANYWAY... since the applet loader program that I am using to load my game is written for lwjgl, I am already loading those libraries. Therefore, it seems logical to switch over to this other binding. They are actually quite similar, and I didn't have any trouble accomplishing the switch. I also have begun running more thorough tests on the code. Sounds are loading, and playing without any problem. However, tests of the 3D functions of the Sound Manager indicate that there is a problem (perhaps a simple typo - not sure yet). For example, a source that moves away from you should be getting quieter, but it is not. I will look into this problem further to see if I can solve it. This is kind of an important issue when you are talking about a 3D game.

I will post the working code for the Sound Manager, when I am finished working out all the kinks. It is designed to SIGNIFICANTLY simplify sound in 3D, so I am sure a few programmers will find it very helpful.

Reply With Quote
  #21  
Old March 8th, 2008, 03:08 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Cool Robot Builder with Sound

Robot Builder now has a couple of sound effects! I used the lwjgl binding of OpenAL. My Sound Manager still looks pretty rough, so I won't post the source code just yet. There are also still a few more 3D-related features I want to add to the class before releasing it.

Reply With Quote
  #22  
Old March 17th, 2008, 03:34 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
The "Sound Manager"

I have been doing a lot of work on the Sound Manager, and I finally feel like it is in a form that I can release. You can get the source code here:
http://www.paulscode.com/source/Sou...nagerSource.zip
Or if you just prefer to download the JAR:
http://www.paulscode.com/source/Sou...oundManager.jar

I made a simple test applet using the Sound Manager:
http://www.paulscode.com/source/Sou...oundApplet.html
And here the source code for the test applet:
http://www.paulscode.com/source/Sou...ppletSource.zip

I also wrote a really basic guide:
Code:
Guide to the SoundManager class

The simplest way to use SoundManager in your jPCT project:
Create the SoundManager object when you initialize things:
    soundManager = new SoundManager();
Bind the listener to the Camera after creating one:
    soundManager.bindListener( camera );
Create some sound sources:
    soundManager.newStreamingSource( "music", "deckthehalls.ogg", true );
    soundManager.newSource( "meow", "cat.wav", false );
    soundManager.newSource( "purr", "motor.wav", true );
Bind sound sources to Object3D's:
    soundManager.bindSource( "meow", my3DCat );
    soundManager.bindSource( "purr", my3DCat );
Call tick() in your main game loop:
    soundManager.tick();
Play the sounds any time you like:
    soundManager.play( "music" );
    soundManager.play( "meow" );
Call cleanup() at the end of your project:
    soundManager.cleanup();


Common Terms:
ATTENUATION:  How a sound "fades" with distance.
    If there is no attenuation, a sound will play at constant volume regardless of distance
FADE DISTANCE:  The distance at which a sound volume will become completely silent
    Used in Linear Attenuation
    (works for both mono and stereo sounds)
LINEAR ATTENUATION:  A sound's volume is inverse to it's distance
    A sound half fade-distance away will play at half volume
LOGRITHMIC ATTENUATION:  A sound's volume is a logrithmic function of it's distance
    A more realistic attenuation model - uses a rolloff factor
    (only works for mono sounds)
ROLLOFF:  A value used in logrithmic attenuation.
    Smaller values for rolloff fade away at longer distances
    If rolloff is 0, then the sound will not fade
STREAMING:  Using multiple buffers to break long sound files, (like background music) up
     into smaller pieces, so you can start playing immediately, rather than waiting to load.


Global References:
Attenuation models:
    public int ATTENUATION_NONE    = 0;  // no attenuation
    public int ATTENUATION_ROLLOFF = 1;  // logrithmic attenuation
    public int ATTENUATION_LINEAR  = 2;  // linear attenuation

Global Varriables (can be changed to fit your preference):
Package where the sound files are located:
    public String SOUNDFILES_LOCATION = "Sounds/";    
Attenuation model to use if not specified (one of the references listed above):
    public int DEFAULT_ATTENUATION_MODEL = ATTENUATION_ROLLOFF;
Default value to use for rolloff model when value isn't specified:
    public float DEFAULT_ROLLOFF_FACTOR = 0.03f;
Default fade distance for linear model if value isn't specified:
    public float DEFAULT_FADE_DISTANCE = 500.0f;    
Number of bytes to load at a time when streaming:
    public int STREAMING_BUFFER_SIZE = 4096*16;
The number of buffers used for each streaming sorce:
    public int STREAMING_NUM_BUFFERS = 2;    
The approximate size of a normal .ogg file:
    private int OGG_NORMAL_SIZE = 1048575;


Easy Interfacing with jPCT
When using these methods, don't forget to call tick() in the main game loop:
    bindListener( Camera c )
        Listener will automatically follow and align with the Camera object

   bindSource( Object3D o )
       A source will automatically follow an Object3D



Method Descriptions:

public void cleanUp()
    Stops all sounds and clears up any used resources

public boolean bindListener( Camera c )
    Orientates the listener to match the Camera orientation

public boolean bindSource( String sourcename, Object3D obj )
    Associates a sound source with an Object3D to follow

Releases a source from it's associated Object3D
    public void releaseSource( String sourcename )

public void releaseAllSources( Object3D obj )
    Releases all sources bound to this Object3D
    (Usually called before deleting an Object3D with sources attached to it, but not required)

public void tick()
    Re-aligns the listner to the camera, and keeps sources folowing the Object3D's they are bound to
    Should be called within the game loop
    (only required if you are using bindListener or bindSource)

public boolean load( String filename )
    Load the specified file (only used for non-streaming sources).
    It is not necessary for you to call this method in your program, but you can if you want to.
    (For example, you could load all the sounds at once and show a progress bar)
    SoundManager will automatically call this method if necessary when creating a source
    If "filename" is a url, it must begin with "http://"
    Returns "true" if there were no problems loading the file
    
public boolean newSource( String sourcename, String filename, boolean toLoop )
public boolean newSource( String sourcename, String filename, boolean toLoop, int attmodel )
public boolean newSource( String sourcename, String filename, boolean toLoop, int attmodel, float distORroll )
public boolean newSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel )
public boolean newSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distORroll )
public boolean newStreamingSource( String sourcename, String filename, boolean toLoop )
public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, int attmodel )
public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, int attmodel, float distORroll )
public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel )
public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distORroll )
    Create a new normal or streaming source.  A streaming source differs from a normal source, in that it has multiple, dynamic buffers.
    SoundManager will use default values for any value you don't specify when creating your source.
    sourcename: A unique identifier for this source (two sources may not use the same sourcename)
    filename: The name of the sound file to play at this source.  If "filename" is a url, it must begin with "http://"
        (if the sound file has not been loaded yet, then SoundManager will load it for you)
    toLoop: Should this source loop, or play the sound only once
    (x, y, z):  Location in 3D space for this source.  Default location is the origin ( 0, 0, 0 )
    attmodel:   Attenuation model to use.  Default is the value in DEFAULT_ATTENUATION_MODEL
    distORroll: Either the fading distance or rolloff factor, depending on the value of "attmodel".

public boolean deleteSource( String sourcename )
    Deletes the specified source

public boolean setPos( String sourcename, SimpleVector pos )
public boolean setPos( String sourcename, float x, float y, float z )
    Moves the named sound to the specified location.

public boolean play( String sourcename )
public boolean stop( String sourcename )
public boolean pause( String sourcename )
public boolean rewind( String sourcename )
    Controls for playing, stopping, pausing, and rewinding a source

public boolean playing( String sourcename )
    Returns true if the source is playing

public void moveListener( float xStep, float zStep )
public void moveListener( SimpleVector step )
public void moveListener( float xStep, float yStep, float zStep )
    Moves the listener, relative to their current position.

public void setListenerPos( float xNew, float zNew )
public void setListenerPos( SimpleVector posNew )
public void setListenerPos( float xNew, float yNew, float zNew )
    Positions the listener at the coordinates provided.

public void turnListener( float angle )
    Turns the listener counterclockwise by "angle" radians, relative to their current orientation.

public void setListenerOrientation( float angle )
    Sets the listener's orientation (counterclockwise rotation in radians along the y-axis)

public void setListenerOrientation( SimpleVector look, SimpleVector up )
public void setListenerOrientation( float lookX, float lookY, float lookZ, float upX, float upY, float upZ )
    Sets the listener's orientation based on a look-at point and an up-direction

public void recalculateDistances()
    Recalculates the distances between each source and the listener, and recalculates the gain if a
    source is using linear attenuation.  It is not necessary for you to use this method.
    SoundManager will automatically call this method when the listener moves or rotates, or a source moves.


One potential bug I am looking into is the fading between left and right speakers only seems to work when the source is really close to the listener. I haven't determined if it is a limitation with my soundcard, or a bug in the code. I am looking into this further. It would be helpful if a few people could run the above applet and see if they experience the same thing. Thanks in advance!

Reply With Quote
  #23  
Old March 19th, 2008, 07:30 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Talking CPU Intensiveness

I have been getting a few comments on various forums, that Robot Builder, although it is running much better than before, still seems to be quite CPU intensive for such a simple program. To be honest, even on my machine, I would actually expect to have a considerably higher FPS than I am getting. It's fast, but it really should be much faster.

Believe it or not, I think the issue is with the 2D components, not the 3D. I have to say -Java Swing is intuitive and easy to use, but I think it is the source of the speed issue - all my pure 3D applets run quite fast, and if I comment out the 2D rendering components of Robot Builder, it more than quadruples the speed. Instead of the Swing functions for mixing 2D with the 3D, I am looking into using direct bit-blitting, which takes away the BufferedImage overhead. EgonOlsen has added some brand new features into the latest compile of jPCT, which will make this much easier. I believe the new methods work the same for both software and hardware mode, so I am probably going to end up using hardware-accelleration after all. I plan to allow the player to choose whichever works better for their machine.

BTW, those of you interested in seeing Robot Builder completed, you may have a little while to wait before I get back to working on it. Besides the blitting issue, I am also doing an extensive overhaul of the SoundManager class. One thing you may have noticed if you've tried to create a lot of sources (depending on your sound card), at some point the sources will just not play - ie there is a maximum number of sources that can be played at one time. Unfortunately, it seems that a source's distance from the listener has no bearing on which sources OpenAL decides to play when you have too many. This would pose a serious problem in a 3D game where you could potentially have hundreds or thousands of sound sources.

So what I've decided to do, is make SoundManager smart enough to cull unnecessary sources. Basically, there would be a "maximum source number". Sources will have a priority based on their distance from the listener, closer sources having priority over further away sources. Sources will be culled down to the maximum source number based on their priority. Which sources are culled will change dynamically as the listener or sources move, or when non-looping sounds stop playing.

I will keep everyone posted on how progress goes for both of these projects.

Reply With Quote
  #24  
Old August 31st, 2008, 01:08 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
3D Sound

I haven't posted anything in a while, but this project has not been abandoned. I have been working on creating an easy-to-use 3D sound library that allows easy access to both OpenAL and JavaSound (in case one doesn't work on the end-user's computer). Anyone interested can read the history of that project at:
http://www.jpct.net/forum2/index.php/topic,1057.0.html

There are still a few things I need to do with the sound library, after which I will resume work on Universe Storage.

Reply With Quote
  #25  
Old September 14th, 2008, 08:09 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Cool 3D Sound Library and Source Code

Here is the latest version of my SoundSystem, the 3D sound library that provides an easy, common interface for both the lwjgl binding of OpenAL (http://www.lwjgl.com) and the JavaSound API. I've recently added support for MIDI and fixed some random bugs. This will probably be the final update on this library, so I thought I would post a link to it in case anyone is interested in a really easy-to-use 3D sound library for Java:

-- PREVIOUS LINKS ARE DEAD --

I am currently finishing up the new SoundManager class, which will make using SoundSystem with jPCT simpler, and handle source management for large numbers of sources. I am having a problem with source management, but after I get that fixed, I will be finished with sound-related stuff and get back to graphics. I am also going to write some tutorials for the sound library, and I'll post links to those when they are finished.

Last edited by paulscode : September 22nd, 2008 at 10:33 PM. Reason: Previous links are dead

Reply With Quote
  #26  
Old September 22nd, 2008, 10:33 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
I have made some final changes to the SoundSystem, and finished the SoundManager. I still don't like the speed of SoundManager, so I decided to not use source management in my game. SoundSystem handles sources well enough, as long as I keep the number of simultaneous playing sounds to around 32. I created a jPCT-specific version of SoundSystem which has the bind methods from SoundManager, but none of the source management stuff.

The previous links to the library are dead, so here are the current ones:

JARS:

Sound System Version date: September 20, 2008 (download the Source Code)
The base library used in Sound System jPCT and Sound Manager. It is designed to be an easy-to-use sound library for playing sound effects in 3D space. It provides a common interface to both the lwjgl binding of OpenAL (http://www.lwjgl.com) and the Java Sound API (http://java.sun.com/products/java-media/sound/). This makes SoundSystem compatible on Windows, Mac, and Linux. Currently, .wav, .ogg, and .mid audio formats are supported.

Sound Manager Version date: September 20, 2008 (download the Source Code)
Provides a customizable source management capability for cases where there are numerous simultaneously playing sources. The idea behind source management is that closer sources will play while further away ones will be culled. Currently, source-management is quite resource-intensive if there are more than 100 sources are active.

Sound System jPCT Version date: September 20, 2008 (download the Source Code)
The jPCT-friendly version of Sound System. Supports binding the Listener to a Camera and Source's to Object3D's. Also has additional methods for moving the Listener and Source's, which take SimpleVectors as parameters.


Sound System Resources Version date: September 10, 2008
(Only required for playing MIDI files). Contains a default sound bank (.gm) file to use if one is not already installed on the user's computer. When playing MIDI from within an applet, this JAR must be used unless another sound bank file is specified using the SoundSystemConfig.setDefaultMidiSoundBank method.


JavaDoc Version date: September 20, 2008
Includes the classes contained in all three of the above JARs.


3D Sound with SoundSystem PDF (download the example programs)
A tutorial-style guide to using the SoundSystem class.


Demos:

Sound Effects Player (download the Source Code)
Demonstrates library switching on the fly, streaming background music, and playing multiple sources simultaneously.

Holy Bouncing Helicopter Balls!! (download the Source Code)
Demonstrates the differences between the source-management models in the Sound Manager. Active sources appear red, while culled sources appear grey.

So moving on from 3D sound, I have decided not to finish the 2D version of Robot Builder, and create the mini-game in 3D instead. That will allow me to get more experience using jPCT before I start programming my RPG. Today I created a 3D robot model. It is rather ugly, but it will work for now. I made an applet to test the robot's inputs and outputs, sound effects, and screen animation, which you can see HERE

Reply With Quote
  #27  
Old September 29th, 2008, 06:11 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Map Maker

I have started creating a map maker program. It isn't anything too fancy, just a more visual way to generate ASCII maps for terrain, altitude, and solid objects. So far, it is able to read and write terain and altitude maps. Here are a couple of screenshots:



These maps were generated programatically, saved, and then loaded from the generated ASCII files. Now what I need to do create some type of GUI for manually editing maps.

In the above screenshots, I used a 32X32 grid, which is 2048 polys (two triangles per grid square). I can easily change the dimentions of a map if I decide that I want more or fewer polys. You may notice that the terrain looks somewhat faceted in these screenshots. That is because the normals are calculated on a per-square basis, and therefore they do not take into account the adjacent squares. The appearance can be made smoother by recalculating all the normals after the entire map has been loaded. I could also compress the mesh considerably, since each vertice inside the terrain is coppied 4 times. All this "beautification stuff" will be done in the actual game whenever a map is loaded. For the Map Maker program, the faceted look is not really a problem, since I am not going for anything super-professional looking at this point, just functional.

Reply With Quote
  #28  
Old October 19th, 2008, 02:01 AM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Interacting with the world via the mouse


I created a simple applet for generating the terrain Object3D from scratch rather than cloning a grid model loaded from a .3ds file. The entire terrain is a single Object3D. You can interact with the terrain via the mouse. When you click on the terrain, whatever cell you click gets colored red, and messages print out for the 3D point that you clicked on, what it translates to in 2D map coordinates, and the map cell number.

Here is a link to the applet:
http://www.paulscode.com/source/calcMinDistanceTest/

And here is the source code for this applet:
http://www.paulscode.com/source/cal...t/MapClick.java

Reply With Quote
  #29  
Old October 27th, 2008, 06:43 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Map Maker Update

Progress on the Map Maker has been a little slow because I am working on a couple of other projects as well, but I have managed to do some work on it. I created an applet to demonstrate what the program can do so far:

http://www.paulscode.com/games/Robo...aker/27OCT2008/

This is basically the same as the applet in my last post, except that now the terrain is not just a flat square, demonstrating that the Interact2D stuff will work with any shape of terrain. Additionally, actual terrain textures are used instead of solid colors, and I added in a click sound effect. SoundSystem is definitely overkill for this applet, but hey - I wrote a sound library so I figure I might as well use it once in a while

You will probably notice that you can't create a smooth curved road with just two textures. This will be solved the same way it is done for a 2D game map - by drawing edge and corner texture images.

Reply With Quote
  #30  
Old November 19th, 2008, 05:09 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
I took a small break from the Map Maker to work on another concept I will need for my game: Guns. This involved figuring out how to do things like firing direction, bullet management, and collision detection. I believe I now have a good understanding of the process. I created a small demo applet:

Demo applet (download the source code)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > 3D Browser-based Game Development


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap