creating a 3d cylinder with edges

Started by ehud101, October 10, 2014, 11:14:50 PM

Previous topic - Next topic

ehud101

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

AGP

Do you just mean drawing a wireframe? If so, World.drawWireframe(FrameBuffer buffer, java.awt.Color color) (instead of World.draw()) will do it.

ehud101

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?                 

EgonOlsen

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:


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);
}
}

}


ehud101

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?

EgonOlsen

#5
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.