Author Topic: creating a 3d cylinder with edges  (Read 2880 times)

Offline ehud101

  • byte
  • *
  • Posts: 8
    • View Profile
creating a 3d cylinder with edges
« on: October 10, 2014, 11:14:50 pm »
Hi,
I'm totally new with jpct (to say the truth I'm new with java, but as I saw there's no problem learning a 3d engine before knowing all the basics, its even kind of helping knowing the language)

my problem: I want to create a 3d cylinder, at first I used the Primitives class but than I saw that I wouldn't go far with this object (and I'm planing to). so I'm going to make it manually like you did in the cube example.

the problem is that I don't see any way to show the edges of the cylinder since there are no "line objects" . so...
how can I do it?

thanks

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: creating a 3d cylinder with edges
« Reply #1 on: October 11, 2014, 04:03:38 am »
Do you just mean drawing a wireframe? If so, World.drawWireframe(FrameBuffer buffer, java.awt.Color color) (instead of World.draw()) will do it.

Offline ehud101

  • byte
  • *
  • Posts: 8
    • View Profile
Re: creating a 3d cylinder with edges
« Reply #2 on: October 11, 2014, 11:53:25 am »
tried it but nothing has changed.
I even drew a cube to make it more simple.... nothing.
I want a wireframe (edges) but also to keep the texture/ color.
and only to a specific object (the cylinder).

I'm used to use Matlab (don't worry I know its completely different) and there there are options for enabling/ disabling the edges. is there something similar  here I can do?                 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: creating a 3d cylinder with edges
« Reply #3 on: October 11, 2014, 02:31:36 pm »
There's no direct support for this. It would look ugly anyway, because you want to highlight the edges of the geometry but a wireframe would hightlight the edges of the triangles, so you would end up getting lines everywhere inside your geometry. You can solve this task in a rather clumsly by using Polylines. For that, you have to create two "objects". One is the normal Object3D and one is a simplified egde object in form of a Polyline instance. This is an example:

Code: [Select]
import java.awt.Color;

import org.lwjgl.opengl.Display;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Polyline;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
import com.threed.jpct.util.ExtendedPrimitives;
import com.threed.jpct.util.Light;

public class PolyCube {

/**
* @param args
*/
public static void main(String[] args) throws Exception {
FrameBuffer buffer = new FrameBuffer(1024, 768, FrameBuffer.SAMPLINGMODE_GL_AA_4X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

World world = new World();
Object3D obj = ExtendedPrimitives.createCube(10);
world.addObject(obj);

World linesWorld = new World();

Light light = new Light(world);
light.setAttenuation(-1);
light.setPosition(new SimpleVector(100, 100, 0));
light.setIntensity(255, 0, 0);
obj.build();
obj.compile();

float d = 5.2f;

SimpleVector[] sv = new SimpleVector[5];
sv[0] = new SimpleVector(-d, -d, d);
sv[1] = new SimpleVector(d, -d, d);
sv[2] = new SimpleVector(d, d, d);
sv[3] = new SimpleVector(-d, d, d);
sv[4] = new SimpleVector(-d, -d, d);

Polyline lines = new Polyline(sv, Color.WHITE);
lines.setParent(obj);
lines.setWidth(10);
linesWorld.addPolyline(lines);

sv = new SimpleVector[5];
sv[0] = new SimpleVector(-d, -d, -d);
sv[1] = new SimpleVector(d, -d, -d);
sv[2] = new SimpleVector(d, d, -d);
sv[3] = new SimpleVector(-d, d, -d);
sv[4] = new SimpleVector(-d, -d, -d);

lines = new Polyline(sv, Color.WHITE);
lines.setParent(obj);
lines.setWidth(10);
linesWorld.addPolyline(lines);

sv = new SimpleVector[5];
sv[0] = new SimpleVector(-d, -d, d);
sv[1] = new SimpleVector(-d, -d, -d);
sv[2] = new SimpleVector(-d, d, -d);
sv[3] = new SimpleVector(-d, d, d);
sv[4] = new SimpleVector(-d, -d, d);

lines = new Polyline(sv, Color.WHITE);
lines.setParent(obj);
lines.setWidth(10);
linesWorld.addPolyline(lines);

sv = new SimpleVector[5];
sv[0] = new SimpleVector(d, -d, d);
sv[1] = new SimpleVector(d, -d, -d);
sv[2] = new SimpleVector(d, d, -d);
sv[3] = new SimpleVector(d, d, d);
sv[4] = new SimpleVector(d, -d, d);

lines = new Polyline(sv, Color.WHITE);
lines.setParent(obj);
lines.setWidth(10);
linesWorld.addPolyline(lines);

linesWorld.setCameraTo(world.getCamera());
world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 50);

while (!buffer.isInitialized()) {
Thread.sleep(100);
}

while (!Display.isCloseRequested()) {
buffer.clear(Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
linesWorld.renderScene(buffer);
linesWorld.draw(buffer);
buffer.update();
buffer.displayGLOnly();
obj.rotateX(0.01f);
obj.rotateY(0.01f);
}
}

}


Offline ehud101

  • byte
  • *
  • Posts: 8
    • View Profile
Re: creating a 3d cylinder with edges
« Reply #4 on: October 11, 2014, 03:26:08 pm »
thanks, so I need now a little advice
I need to create a cylinder which is a little bit more complex than a cube.
I see that every thing is here must be defined with triangles (which I find hard to use to create a cylinder)
so for this matter should I use the j3d classes for the cylinder (there I can define exact height and radius) or is there a more useful way to do what  I want in the jpct environment?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: creating a 3d cylinder with edges
« Reply #5 on: October 11, 2014, 10:15:37 pm »
Which j3d classes? I'm not sure what you mean!?

Anyway, you can still create the cylinder by using either Primitives or ExtendedPrimitives from the util-package. In addition, you have to create the Polyline version of it by yourself, which is not based on triangles but on single lines.
« Last Edit: October 11, 2014, 11:59:04 pm by EgonOlsen »

Offline ehud101

  • byte
  • *
  • Posts: 8
    • View Profile
Re: creating a 3d cylinder with edges
« Reply #6 on: October 11, 2014, 11:12:21 pm »
thanks!