newbie: how to make a 3d grid

Started by stormp, June 11, 2007, 11:46:59 AM

Previous topic - Next topic

stormp

Hi, I'm a newbie to jPCT.

I would like to place objects inside a variable lined 3D grid.  As i zoom into the object, i would like the grid lines to become more detailed.

Can someone point me into the right direction on how to accomplish this using jPCT?

Thanks so much  :)

    __|
        \
         
eg:

halcor

Maybe 3 perpendicular planes with alpha-enabled textures? If you want dynamic zoom you can have several versions of your textures and decide which one to show...

By the way, are alpha-enabled textures supported by the SoftGL renderer?

stormp

Hi, thanks for the response.

I need to use software rendering.

EgonOlsen

#3
Software renderer doesn't support alpha. But it does support transparency when the texture has black (or almost black) parts. The best way to do such a grid, would be to draw it yourself using simple line draws. But you would have to do the 3d->2D conversion (and maybe the clipping) yourself in that case. project3D2D() in Interact2D can help you to ease that task.

stormp

Thanks.

Planes will not work?

Are there any example code at all that would demonstrate using project3D2D for line drawing?

Thanks so much!

S.

EgonOlsen

#5
You just have to feed your points into that method and draw the result, i.e. if you want to draw a line between (10,10,10) and (20,30,50) use the method on both of them and draw a line (in 2D using Java2D's line method) between the resulting points.
But keep in mind that it can't look like it does in your example, because you are using parallel projection there but jPCT does perspective projection.

stormp

Thanks for the reply! :)

Actually, I do want perspective projection of course.  I used a bad graphic example I suppose.

Can I line draw on the buffer before the scene is rendered?  If so how?  I only seem to be able to figure out how to draw after.  I thought maybe I could use the IPaintListener?

Thanks so much for your help.

Where would I insert the g.drawLine(x1, y1, x2, y2); function call?

simple example code:


import java.awt.*;
import java.applet.*;
import com.threed.jpct.*;

public class View3D extends Applet
{
    World theWorld;              // The world. This Object will contain the 3D objects and the lightsources
    TextureManager texMan=null;  // The texture-manager. This is required for loading and managing textures
    Camera camera;               // The camera
    FrameBuffer buffer=null;     // The framebuffer. This is were jPCT will render the final image into
    Object3D objCube=null;
    Object3D objShpere=null;

    public void init()
    {
        getAppletContext().showStatus("Initializing...");

        resize(450,300);

        buffer=new FrameBuffer(450, 300, FrameBuffer.SAMPLINGMODE_NORMAL);
        buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE, IRenderer.MODE_OPENGL);
        buffer.setPaintListener(listener);

        theWorld= new World();

        objCube = Primitives.getCube(3);

        objCube.setAdditionalColor(Color.red);
        objCube.setTransparency(128);

        objShpere = Primitives.getSphere(2);

        theWorld.addObject(objShpere);
        theWorld.addObject(objCube);

        theWorld.buildAllObjects();
        theWorld.getCamera().setPosition(new SimpleVector(0,0,-30));

        getAppletContext().showStatus("Done !");
    }  // init()

    public void paint(Graphics g)
    {
        buffer.clear(Color.white);

        theWorld.renderScene(buffer);
        theWorld.draw(buffer);

        buffer.update();
        buffer.display(this.getGraphics());
     }  // paint()
}  // class View3D


*humble newb*

EgonOlsen

Right after the clear(), but you don't draw into g but into the Graphics-instance that you can obtain from the FrameBuffer. If you need 1.1 compatibility, it isn't that easy because the MemoryImageSource which is used as a backbuffer for the rendered scene doesn't support getting a Graphics-object from it.

stormp

OK, that did the trick.

Thanks for your help, I really appreciate it.  ;D