Author Topic: newbie: how to make a 3d grid  (Read 4227 times)

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
newbie: how to make a 3d grid
« on: June 11, 2007, 11:46:59 am »
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:
« Last Edit: June 11, 2007, 12:10:41 pm by stormp »

Offline halcor

  • byte
  • *
  • Posts: 28
    • View Profile
Re: newbie: how to make a 3d grid
« Reply #1 on: June 11, 2007, 12:38:00 pm »
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?

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
Re: newbie: how to make a 3d grid
« Reply #2 on: June 11, 2007, 12:57:26 pm »
Hi, thanks for the response.

I need to use software rendering.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: newbie: how to make a 3d grid
« Reply #3 on: June 11, 2007, 01:24:21 pm »
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.
« Last Edit: June 11, 2007, 01:29:57 pm by EgonOlsen »

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
Re: newbie: how to make a 3d grid
« Reply #4 on: June 11, 2007, 01:41:35 pm »
Thanks.

Planes will not work?

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

Thanks so much!

S.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: newbie: how to make a 3d grid
« Reply #5 on: June 11, 2007, 01:46:51 pm »
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.
« Last Edit: June 11, 2007, 01:53:24 pm by EgonOlsen »

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
Re: newbie: how to make a 3d grid
« Reply #6 on: June 11, 2007, 03:54:03 pm »
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:

Code: [Select]
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*

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: newbie: how to make a 3d grid
« Reply #7 on: June 11, 2007, 04:08:53 pm »
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.

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
Re: newbie: how to make a 3d grid
« Reply #8 on: June 11, 2007, 04:29:16 pm »
OK, that did the trick.

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