I solved the problem. Thanks
The Config was the Problem
The Config was the Problem
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 Menupublic class TestCommand implements IHandler {
DDDInit window = new DDDInit();
@Override
public void addHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!window.isRunning()) {
window.init3D();
}
return null;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isHandled() {
return true;
}
@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
}
private void Config() {
// window name
Config.glWindowName = "3D Perspective";
Config.glAvoidTextureCopies = true;
// Config.useMultipleThreads = true;
}
public DDDInit() {
Config();
// is camera positioned
cameraSet = false;
world = new World();
// world light values
world.setAmbientLight(255, 255, 255);
// set init postion of camera
world.getCamera().setPosition(0, 0, distance);
// set fogging
world.setFogging(World.FOGGING_ENABLED);
// fog distance
world.setFogParameters(FOGGING_DISTANCE, FOG_COLOR.getRed(),
FOG_COLOR.getGreen(), FOG_COLOR.getBlue());
// render objects which are within 10000 range
world.setClippingPlanes(0, CLIPPING_DISTANCE);
camera = world.getCamera();
Bundle bundle = FrameworkUtil.getBundle(SimulationView.class);
URL url = FileLocator.find(bundle, new Path("texture"), null);
// load textures
TextureManager.getInstance().addTexture("skyDome",
new Texture(10, 10, Color.blue));
TextureManager.getInstance().addTexture("car.jpg",
new Texture(url, "car.jpg"));
TextureManager.getInstance().addTexture("carGreen",
new Texture(url, "carGreen.jpg"));
TextureManager.getInstance().addTexture("carBlue",
new Texture(url, "carBlue.jpg"));
TextureManager.getInstance().addTexture("carYellow",
new Texture(url, "carYellow.jpg"));
TextureManager.getInstance().addTexture("carRed",
new Texture(url, "carRed.jpg"));
TextureManager.getInstance().addTexture("White",
new Texture(8, 8, Color.white));
TextureManager.getInstance().addTexture("Gray",
new Texture(8, 8, new Color(200, 200, 200)));
TextureManager.getInstance().addTexture("Black",
new Texture(8, 8, Color.BLACK));
TextureManager.getInstance().addTexture("Blue",
new Texture(8, 8, Color.BLUE));
TextureManager.getInstance().addTexture("Underlay",
new Texture(8, 8, Color.GREEN));
// load 3ds file once
url = FileLocator.find(bundle, new Path("3dsObjects"), null);
ThreedsObjects = Loader.load3DS(url, "car.3ds", 1);
SimulationKernel.getInstance().addInputChangedListener(
new ModelInputChangedListener() {
@Override
public void inputChanged(SimulationModel newModel) {
world.removeAllObjects();
listOfRoadSegments = new Vector<RoadSegment>();
listOfAbstractJunctions = new Vector<AbstractJunction>();
vehicleMapping = new TreeMap<Vehicle, Object3D>();
firstTime = true;
worldOffsetX = 0;
worldOffsetY = 0;
underlayPlane = null;
}
});
}
/**
* Initialize the 3D world
*/
public void init3D() {
// app is running
isRunning = true;
// run in seperate thread
try {
Thread run = new Thread(new Runnable() {
@Override
public void run() {
// window size
buffer = new FrameBuffer(800, 600,
FrameBuffer.SAMPLINGMODE_NORMAL);
// hardware renderer
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
// draw loop
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
// background color
buffer.clear(java.awt.Color.WHITE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
// draw HUD
blitString();
buffer.displayGLOnly();
// check for mouse or key event
move();
poll();
if (world != null) {
updateRoadnetwork();
updateVehicles();
}
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
}
}
private static void getObject3DatMouse(int x, int y) {
SimpleVector dir = Interact2D.reproject2D3DWS(camera, buffer, x, y).normalize();
Object[] res = world.calcMinDistanceAndObject3D(camera.getPosition(),dir, 10000 /* or whatever */);
int[] res1 = Interact2D.pickPolygon(world.getVisibilityList(), camera.getPosition(), dir);
if (res1 != null) {
Object3D picked = world.getObject(res1[1]);
}
Object3D pciked = (Object3D) res[1];
System.out.println();
}
public static void drawRoadSegment(RoadSegment seg, Matrix matrix) {
for (LaneSegment ls : seg.getLaneSegments()) {
List leftEdge = ls.getLeftEdge();
List rightEdge = ls.getRightEdge();
leftEdge = matrix.multiply(leftEdge);
rightEdge = matrix.multiply(rightEdge);
Vector<Point> tmp = new Vector<Point>();
for (int i = 0; i < leftEdge.size() - 1; i++) {
int x11 = (int) leftEdge.get(i).x;
int y11 = (int) leftEdge.get(i).y;
int x21 = (int) leftEdge.get(i + 1).x;
int y21 = (int) leftEdge.get(i + 1).y;
tmp.add(new Point(x11, y11));
tmp.add(new Point(x21, y21));
}
for (int i = rightEdge.size() - 1; i > 0; i--) {
int x12 = (int) rightEdge.get(i).x;
int y12 = (int) rightEdge.get(i).y;
int x22 = (int) rightEdge.get(i - 1).x;
int y22 = (int) rightEdge.get(i - 1).y;
tmp.add(new Point(x12, y12));
tmp.add(new Point(x22, y22));
}
//the tmp vector contains the correct x/y points for the polygon
int j = tmp.size() - 1;
//loop to create the correct triangles
for (int i = 0; i < tmp.size() - 1; i++) {
if (j != i + 1) {
SimpleVector s1 = new SimpleVector(tmp.get(i).getX(), tmp
.get(i).getY(), 0);
SimpleVector s2 = new SimpleVector(tmp.get(i + 1).getX(),
tmp.get(i + 1).getY(), 0);
SimpleVector s3 = new SimpleVector(tmp.get(j).getX(), tmp
.get(j).getY(), 0);
Object3D obj = new Object3D(tmp.size() - 1);
obj.addTriangle(s1, s2, s3);
obj.build();
world.addObject(obj);
j--;
}
}
}
}
Page created in 0.036 seconds with 13 queries.