Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Veko

#1
Support / Re: collision detection
January 27, 2009, 09:54:47 PM
ow ok, cool I thought every object the partakes in the collision needs to be ellipsoid or sphererical
#2
Support / Re: collision detection
January 27, 2009, 08:32:33 PM
alright i'll give it a shot

* what should the SimpleVector ellipsoid be ? (i.e how do I determine the radius of the epplisoid in x,y and z direction for a box)
#3
Support / Re: collision detection
January 27, 2009, 08:28:12 PM
the boxes are static objects in the game and they're used for blocking access (so the player has to go around them)
they stand in a 3d plane

They're much like the boxes and walls in your game robombs
#4
Support / Re: collision detection
January 27, 2009, 08:01:42 PM
I need the corrected translation vector
but that works fine with spheres and ellipses, but with boxes i'm not sure how to proceed,

I'm trying to mess around a bit with the boundingboxes, but so far I'm not succesfull
#5
Support / Re: collision detection
January 27, 2009, 06:32:54 PM
ok that helped :p

Now I got a dillema, I mainly got square objects like boxes etc. in my scene and I don't really know what to pick for the collision detection, ellipsoid or spherical. I'm worried about the corners of the square objects not being collided with.

Is there somekind of way that I could use similiar to the checkForCollisionSpherical, because the return vector is really handy
#6
Support / collision detection
January 27, 2009, 02:47:06 PM
Got a new problem :D.

If I understand checkForCollisionSpherical correct; when there is collision, checkForCollisionSpherical returns a vector different from the translation vector you entered with the check (the correct new translation)

I tried to apply this to my code :

m_ClientObjects is a Vector<Object3D>

all the Object3D in the vector have   
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

the object where I'm testing the collision for has
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF);

  for (int i=0;i<STATE.m_ClientObjects.size();++i)
            {
                SimpleVector temp= STATE.m_ClientObjects.elementAt(i).checkForCollisionSpherical(a, 128);

                if (temp != a)
                {
                    a = temp;
                    System.out.println("New translation: " + temp);
                }
            }


But this snippet of code doesn't work, the SimpleVectors a and temp are always the same... so there is always collision ?? (eventhough there isn't)

What am I doing wrong ?
#7
Support / Re: deleting light ?
January 25, 2009, 06:51:34 PM
Yes I know about the Light class here's what I'm doing

    public Entity
    {
        ... blah
        // Create a extra light source for the bullet:
        tracer = new Light(m_World);
        Util.setColor(tracer,new Color(255, 210, 0, 5));
        tracer.setPosition(start_pos);
    }

    protected void finalize() throws Throwable
    {
        ...
        m_World.removeObject(model);
        tracer.disable();
    }


The Light position gets updated with the transformedCenter of the model.

That all works but when I delete my Entity I get a null pointer when the tick tries to find the tracer object but can't because the Entity doesn't exist anymore,
That's why I thought it would be logical that I could delete my Light object like deleting an Object3D from the world (disabling a Light works fine, as long as I don't delete the entire Entity :p)


What goes on behind the scenes when adding a Object3D's to a world ? You could use a similiar structure for the Light objects, no ?
#8
Support / deleting light ?
January 25, 2009, 03:22:35 PM
Hi, I've got an Entity where I create a new Light along with some other stuff
This Entity has a limited life, so when the Entity reaches his max lifetime the Entity gets deleted (along with all the crap in it)

I haven't found a way to delete a light source from the world.
I know you can disable a light, but that doesn't work seeing I would receive a null pointer to the Entity's Light the next tick

I've been trying to find the Lights Object id so I could use the removeObject function, but lights don't seem to have that function ?

Can it be done with world.removeObject(...), or is there another way I'm missing to remove a Light.

greetz,
Veko
#9
Support / Re: problems with gears example
January 24, 2009, 03:26:59 PM
ok silly me, you're right I forgot to initialize :D
can someone also point me in the right direction for bitmapFonts ?
#10
Support / Re: problems with gears example
January 24, 2009, 01:08:28 PM
I've set aside the FengGUI for a moment (think its to overkill for what I want, I just want some simple text in a custom font on my screen)

so now I'm looking into the whole blitting thingie and stumbled on this topic
http://www.jpct.net/forum2/index.php/topic,1074.0.html

this looks very promising, but when I try to do:

private GLFONT glfont;
...
m_Buffer.update();

glfont.blitString(m_Buffer, "this is a blitted text", 10, 10, 1, Color.ORANGE);

m_Buffer.displayGLOnly();
       
m_Canvas.repaint();


I'm getting null pointer exception:

Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at facebookgame.IngameState.paint(IngameState.java:218)
at facebookgame.MainApp.paint(MainApp.java:58)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
#11
Support / Re: problems with gears example
January 24, 2009, 02:14:32 AM
ok I'm back with a new question. I'm still using this system for my applet and now I'm trying to implement FengGUI.
I've gotten so far as

private org.fenggui.Display display;
...

this.display = new Display(new AWTGLCanvasBinding((AWTGLCanvas)m_Canvas));

Window window = FengGUI.createWindow(display, true, false, false, true);
window.setTitle("my window");
window.setPosition(new Point(50,200));
window.getContentContainer().setLayoutManager(new RowLayout(false));
window.getContentContainer().getAppearance().setPadding(new Spacing(10, 10));


after that I tried adding stuff (but here I stumbled upon the null pointer exception)

final ToggableGroup<String> toggableGroup = new ToggableGroup<String>();
RadioButton<String> radioButtonCoffee = new RadioButton<String>("coffee", toggableGroup, "coffee");
RadioButton<String> radioButtonTea = new RadioButton<String>("tea", toggableGroup, "tea");
radioButtonTea.setSelected(true);

Container container = new Container(new RowLayout(true));
container.addWidget(radioButtonCoffee);
container.addWidget(radioButtonTea);
window.getContentContainer().addWidget(container);


but why I try to add stuff to the window (like radio buttons etc.) I get a null pointer exception. I've been reading up about common null pointer exceptions with FengGUI, but I haven't found a solution yet

here's the exception:

Exception in thread "Thread-21" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1348)
at org.fenggui.render.lwjgl.LWJGLTexture.createTextureID(Unknown Source)
at org.fenggui.render.lwjgl.LWJGLTexture.createTexture(Unknown Source)
at org.fenggui.render.lwjgl.AWTGLCanvasBinding.getTexture(Unknown Source)
at org.fenggui.theme.DefaultTheme.setUp(Unknown Source)
at org.fenggui.theme.StandardTheme.setUp(Unknown Source)
at org.fenggui.StandardWidget.setupTheme(Unknown Source)
at org.fenggui.RadioButton.<init>(Unknown Source)
at facebookgame.IngameState.buildGUI(IngameState.java:417)
at facebookgame.IngameState.enter(IngameState.java:105)
at facebookgame.MainApp.switchState(MainApp.java:136)
at facebookgame.MainApp.stateEvent(MainApp.java:148)
at facebookgame.LoadingState.tick(LoadingState.java:75)
at facebookgame.MainApp.run(MainApp.java:87)
at java.lang.Thread.run(Unknown Source)


also, I have no idea where to put the display.display()

hopefully you guys can help me as good as before :)
#12
Support / Re: problems with gears example
December 17, 2008, 01:46:04 PM
wow, sweet man :D
will test this asap

*edit* very nice, that should be stickied up :D + big thanks for the fast support
#13
Support / Re: problems with gears example
December 17, 2008, 02:44:46 AM
I got another non jcpt canvas working :s
so it must be an interferance between Display and jpct.

Is there a way to work with 'gamestates' in jpct (like menustate, ingamestate, etc.) ?
#14
Support / Re: problems with gears example
December 17, 2008, 01:39:32 AM
nice :)

I got myself a new problem now :p. I'm trying to work with a kind of gamestate system in the applet and I'm trying to use to the Gears demo as 1 of the states. But I think I'm not doing it correctly because he isn't drawing anything on screen when he is in the 'Gears-state'

I'm not very familiar with applets and I started working with them without jcpt using examples on the LWJGL-forums (That's why I use Display etc.),
but because I had no 3d animation support yet, I needed an easy to use engine with animation support and thats when I found Jcpt.

here's my code:

MainApp

package testgame;

import java.util.HashMap;
import java.util.Iterator;
import java.awt.BorderLayout;
import java.awt.Canvas;

import org.lwjgl.Sys;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;

public class MainApp extends javax.swing.JApplet
{
    // DATAMEMBERS -----------------------------------

        protected Thread gameThread = null;
        private HashMap gameStates = new HashMap();
        private GameState currentState = null;
        public Canvas display_parent = null;
        private boolean running = false;

    // -----------------------------------------------

    @Override
    public void destroy()
    {
        remove(display_parent);
        super.destroy();
        System.out.println("Clear Up");
    }

    @Override
    public void start()
    {
        gameThread = new Thread()
        {

            @Override
            public void run()
            {
                running = true;
                try
                {
                    initGL();
                }
                catch(LWJGLException e)
                {
                    e.printStackTrace();
                }
                System.out.println("Entering Gameloop");
                gameLoop();
            }
        };
        // If setDaemon(true) the JVM will exit as soon as the main reaches completion?
        gameThread.setDaemon(true);
        gameThread.start();
    }

    @Override
    public void stop()
    {
        //
    }

    @Override
    public void init()
    {
        setLayout(new BorderLayout());
        try
        {
            display_parent = new Canvas()
            {

                @Override
                public final void removeNotify()
                {
                    destroyLWJGL();
                    super.removeNotify();
                }
            };
            display_parent.setSize(getWidth(),getHeight());
            add(display_parent);
            display_parent.setFocusable(true);
            display_parent.requestFocus();
            setVisible(true);
        }
        catch(Exception e)
        {
            System.err.println(e);
            throw new RuntimeException("Unable to create display");
        }
    }

    private void destroyLWJGL()
    {
        stopApplet();
        try
        {
            gameThread.join();
        }
        catch(InterruptedException e)
        {
            e.printStackTrace();
        }
    }
    private void stopApplet()
    {
        running = false;
    }

    private void addState(GameState state)
    {
        if (currentState == null) currentState = state;
        gameStates.put(state.GetName(), state);
    }

    private void initGL() throws LWJGLException
    {
        System.out.println("display_parent.isDisplayable() = " + display_parent.isDisplayable());
        // setParent needed for embedding screen in canvas
        Display.setParent(display_parent);
        Display.setVSyncEnabled(false);
        Display.create();

        // add the game states that build up our game
        addState(new GearsState());

        try
        {
            // initialise all the game states we've just created. This allows
            // them to load any resources they require
            Iterator states = gameStates.values().iterator();

            // loop through all the states that have been registered
            // causing them to initialise
            while (states.hasNext())
            {
                    GameState state = (GameState) states.next();

                    state.StateInitialize();
            }
        }
        catch (Exception e)
        {
                // if anything goes wrong, show an error message and then exit.
                // This is a bit abrupt but for the sake of this tutorial its
                // enough.
                Sys.alert("Error", "Unable to initialise state: " + e.getMessage());
                System.exit(0);
        }
    }

    private void gameLoop()
    {
        currentState.Enter(this);

        long oldTime = getTime();
        System.out.println("Got Time : " + oldTime);

        // while the game is running we loop round updating and rendering the current game state
        while (running)
        {
            long dTime = (getTime() - oldTime);
            oldTime = getTime();

            Display.update();

            if (Display.isCloseRequested())
            {
                running = false;
                break;
            }

            // the window is in the foreground, so we should play
            else if (Display.isActive())
            {
                int remainder = (int) (dTime % 10);
                int step = (int) (dTime / 10);
                for (int i=0;i<step;i++)
                {
                    currentState.StateCycle(10);
                }
                if (remainder != 0)
                {
                    currentState.StateCycle(remainder);
                }

                currentState.StatePaint();
                Display.sync(60);
            }
            else
            {
                try
                {
                    Thread.sleep(100);
                }
                catch (InterruptedException e)
                {
                    //
                }
                currentState.StateCycle(dTime);

                // only bother rendering if the window is visible or dirty
                if (Display.isVisible() || Display.isDirty())
                {
                    currentState.StatePaint();
                    Display.sync(60);
                }
            }
        }
    }

    // Change the current state being rendered and updated.
    // Note if no state with the specified name can be found no action is taken.
    protected void changeToState(String name)
    {
            GameState newState = (GameState) gameStates.get(name);
            if (newState == null)
            {
                    return;
            }

            currentState.Leave();
            currentState = newState;
            currentState.Enter(this);
    }
   
    private long getTime()
    {
            return (Sys.getTime() * 1000) / Sys.getTimerResolution();
    }
}


Gears-state

package testgame;

import java.awt.BorderLayout;
import java.awt.Canvas;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Lights;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;

import java.awt.Color;

import testgame.modelloader.Loader3ds;

public class GearsState extends javax.swing.JPanel implements testgame.GameState//, MouseListener, MouseMotionListener, Runnable
{
    // -----------------------------------------------

        protected static final String NAME = "gears";
        private jPCTGears m_pWindow = null;
        private FrameBuffer m_Buffer = null;
        private World m_World = null;
        private Camera m_Camera = null;
        private Canvas myCanvas = null;
        private Object3D redGear, greenGear, blueGear, assemblyPivot;
        private float gear_rotation = 0.02f;
   
    // -----------------------------------------------
   
    public String GetName()
    {
        return NAME;
    }
       
    public void StateInitialize()
    {
        //
    }
       
    public void Enter(MainApp window)
    {
        System.out.println("Entering Menu state");

        m_pWindow = window;

        // sign the applet up to receive mouse messages:
        m_World = new World();  // create a new world

        World.setDefaultThread(Thread.currentThread());

        // create a new buffer to draw on:
        m_Buffer = new FrameBuffer( m_pWindow.getWidth(), m_pWindow.getHeight(), FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY );
        m_Buffer.disableRenderer( IRenderer.RENDERER_SOFTWARE );

        myCanvas = m_Buffer.enableGLCanvasRenderer();

        m_pWindow.add( myCanvas, BorderLayout.CENTER);
        myCanvas.setVisible(true);
        myCanvas.requestFocus();

        Loader3ds temp = new Loader3ds();

        // load some 3D objects and make sure they have the correct orientation:
        redGear = temp.loadMeshFile("http://users.telenet.be/decoy/FacebookApp/models/RedGear.3ds");
        redGear.rotateY( (float)Math.PI / 2.0f );
        redGear.rotateMesh();
        redGear.setRotationMatrix( new Matrix() );
        redGear.setOrigin( new SimpleVector( 0, 0, 0 ) );
        redGear.build();
        greenGear = temp.loadMeshFile("http://users.telenet.be/decoy/FacebookApp/models/GreenGear.3ds");
        greenGear.rotateY( (float)Math.PI / 2.0f );
        greenGear.rotateZ( 0.35f );
        greenGear.rotateMesh();
        greenGear.setRotationMatrix( new Matrix() );
        greenGear.setOrigin( new SimpleVector( -145.0f, 0, 0 ) );
        greenGear.build();
        blueGear = temp.loadMeshFile("http://users.telenet.be/decoy/FacebookApp/models/BlueGear.3ds");
        blueGear.rotateY( (float)Math.PI / 2.0f );
        //blueGear.rotateZ( 0.40f );
        blueGear.rotateMesh();
        blueGear.setRotationMatrix( new Matrix() );
        blueGear.setOrigin( new SimpleVector( 0, -140.0f, 0 ) );
        blueGear.build();

        // Set up a pivot point for the entire gear assembly:
        assemblyPivot = Object3D.createDummyObj();
        assemblyPivot.setOrigin( new SimpleVector( 0, 0, 0 ) );
        // Make the gears children to assemblyPivot.
        // Translations and rotations to assemblyPivot
        // will affect the entire gear assembly:
        assemblyPivot.addChild(redGear);
        assemblyPivot.addChild(greenGear);
        assemblyPivot.addChild(blueGear);

        // add the objects our world:
        m_World.addObject(redGear);
        m_World.addObject(greenGear);
        m_World.addObject(blueGear);
       
        redGear.build();
        greenGear.build();
        blueGear.build();
        m_World.buildAllObjects();

        lookAt(redGear);  // make sure the camera is facing towards the object
        letThereBeLight();  // create light sources for the scene

        // receive mouse input from the main applet:
        //addMouseListener(m_pWindow);
        //addMouseMotionListener(m_pWindow);

        // also get mouse input picked up by the canvas:
        //myCanvas.addMouseListener(this);
        //myCanvas.addMouseMotionListener(this);
       
        //new Thread(this).start();
    }

    public void Leave()
    {
        m_pWindow = null;
        m_World.dispose();
    }
       
public void StatePaint()
    {
        // He enters and does StatePaint, but nothing happens.
        m_Buffer.clear(new Color(100, 100, 100));   // erase the previous frame

        // render the world onto the buffer:
        m_World.renderScene(m_Buffer);
        m_World.draw(m_Buffer);
        m_Buffer.update();

        m_Buffer.displayGLOnly();
        myCanvas.repaint();    // Paint the canvas onto the applet (hardware mode)

        System.out.println("Painting");
}
       
    public void StateCycle(long dTime)
    {
        redGear.rotateAxis( redGear.getZAxis(), -gear_rotation );
        greenGear.rotateAxis( greenGear.getZAxis(), 2.0f * gear_rotation );
        blueGear.rotateAxis( blueGear.getZAxis(), 2.0f * gear_rotation );
    }

    // create light sources for the scene
    private void letThereBeLight()
    {
        m_World.getLights().setOverbrightLighting (Lights.OVERBRIGHT_LIGHTING_DISABLED );
        m_World.getLights().setRGBScale(Lights.RGB_SCALE_2X);

        // Set the overall brightness of the world:
        m_World.setAmbientLight(50, 50, 50);

        // Create a main light-source:
        m_World.addLight(new SimpleVector(50, -50, 300 ), 20, 20, 20);
    }

    // point the camera toward the given object
    private void lookAt( Object3D obj )
    {
        m_Camera = m_World.getCamera();  // grab a handle to the camera
        m_Camera.setPosition( 0, 0, 500 );  // set its *relative* position
        m_Camera.lookAt( obj.getTransformedCenter() );  // look toward the object
    }
}


I'm not sure if creating a Display in my MainApp is causing interferance with the jcpt engine,
but when I run this applet he enters the GearsState with no problems (he even does the StatePaint etc.), but nothing is painted to screen, it just stays black (No errors in console though)

I tried clearing with a different color than black, but that didn't work (still the black screen),
then I added the "System.out.println("Painting");" to check if he actually uses StatePaint, and yes the applet does use it.

I haven't a clue what I'm doing wrong, but I suspect I'm painting the display_parent over the canvas of the GearsState

Is it possible to have world within worlds ?
#15
Support / Re: problems with gears example
December 17, 2008, 12:24:42 AM
alright I got the thing working in 2sec now :p (took some hours of coding to clear my head),
don't know what I did differently now, but it works

thnx for the fast responses !

+ paulscode, nono I meant to say applet :)