Show Posts

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.


Topics - miron123

Pages: [1]
1
Support / Problem with reinitializing
« on: April 25, 2014, 11:01:27 am »
Hallo I have a problem if I want to run my jpct world two times. My initializiation looks like this:
Code: [Select]
public 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
}

}

and my jpct class looks like this:
Code: [Select]
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();
}
}
If I run my code for the first time I have no Problems but if I close my window and want to reinitialize the same way I get a NullPointerException at world.draw(buffer).

Exception:
Exception in thread "Thread-9" java.lang.NullPointerException
   at org.lwjgl.util.glu.MipMap.gluScaleImage(MipMap.java:235)
   at org.lwjgl.util.glu.MipMap.gluBuild2DMipmaps(MipMap.java:142)
   at org.lwjgl.util.glu.GLU.gluBuild2DMipmaps(GLU.java:384)
   at com.threed.jpct.GLBase.convertTexture(GLBase.java:1738)
   at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:1438)
   at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:1051)
   at com.threed.jpct.World.draw(World.java:2100)
   at com.threed.jpct.World.draw(World.java:2011)
   at com.threed.jpct.World.draw(World.java:1607)
   at at.fhhooe.mc.trafficsim.threeDPerspective.DDDInit$2.run(DDDInit.java:238)
   at java.lang.Thread.run(Unknown Source)

I dont know why this is happening because I initialize each time a completely new Instance of the DDDInit class. Or does jpct use a seperate thread which doesn t close?
Please help.

2
Support / Picking
« on: March 08, 2014, 10:08:06 am »
Hello,
I m working on a 3D world and Im trying to translate my camera position but i want to attach the mouse cursor at the clicked position. If I move my camera my mouse cursor stays at the position where I first clicked. My problem now is that I implemented an orbital camera. cause of that I cant calc a factor based on the camera hight( camera.getPostion().z) but I need postion in the world where I clicked with the mouse.
I tried to implement the picking methods in the forum but I never got a correct object.
My code:

Code: [Select]
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();
}

I just tried to get an object based on the Mouse.getX() and Mouse.getY() positon but I always res:
  • = 1.0E12 and [1]= null

the res1 array is always empty.
So my question is, if I do the picking incorrectly or I have to improve it somehow.
Of cause I included:

obj.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
obj.setCollisionOptimization(true);

3
Support / Camera rotation span
« on: February 27, 2014, 01:01:45 pm »
Hello Im currently working on a project which needs an orbital camera movement. I want to rotate my camera vertically around a point. At the moment I tried it like this:

camera.moveCamera(Camera.CAMERA_MOVEIN, dist); //dist to rotation point
//-delta to invert camera
camera.rotateCameraAxis(new SimpleVector(1, 0, 0), -delta* cameraRotationFactor);
camera.moveCamera(Camera.CAMERA_MOVEOUT, dist);

Now I want to limit the range of the camera rotation. So I want the the camera can rotate between 1 and 90 Degrees.
My question is how can I limit the camera rotation to a specific rotation degree?.
I tried to calc the angle based on the rotation matrix and based on the methods in this forum but I didnt get the correct values.
Please help.

4
Support / Object3D possiblities
« on: January 10, 2014, 09:54:48 pm »
Hello
I'm working now on a 3D perspectiv of a roadnetwork. I have Geodatas where and how each road segment has to be drawn. My problem at the moment is the following:
I'm trying to create a Object3D object for each road segment but I don t know how to initialize this object correctly. Cause the roadsegments are polygons and i tried to initialize the
object with all points of the polygon, an uvs array, a  normals array and an empty texture, (TextureManager.TEXTURE_NOTFOUND ). But when I try to render the world(road segment included)
nothing is shown. Of course i changed the camera position and I always look at the object but there just isn't anything.
My question now is: if its better to draw polylines and create a custom polygon or have i done something wrong with the object3d?
Hopefully my english is understandable.

Code snip:
public static void drawRoadSegment(RoadSegment seg) {

      float[] tmp = new float[((seg.getBounds().xpoints.length) * 3)];

      int[] x = seg.getBounds().xpoints;
      int[] y = seg.getBounds().ypoints;
      Vector<Float> t = new Vector<Float>();

      for (int i = 0; i < seg.getBounds().xpoints.length; i++) {
         t.add((float) x);
         t.add((float) y);
         t.add(0.0f);
      }
      for (int i = 0; i < t.size(); i++) {
         tmp = t.elementAt(i);
      }

      Object3D obj = new Object3D(tmp, null, null, TextureManager.TEXTURE_NOTFOUND); //in this case I tried to use null for uvs and normals but I tried it also with initialized arrays
      obj.setVisibility(true);
      obj.build();

      box = Primitives.getBox(13f, 2f);
      box.setTexture("box");
      box.setEnvmapped(Object3D.ENVMAP_ENABLED);
      box.build();

      world.addObject(box);
      world.getCamera().lookAt(box.getTransformedCenter());
    }
   }

Please help

5
Support / Rounded Cube
« on: September 17, 2012, 10:38:32 am »
Hello.
I have a small problem. In the last 4 month i tried to create a cube with rounded edges. First I tried OpenGl ES and finally I found my way to jpct-ae. Now its a imported obj file.
Problem: I try to start new Activities based on the cube side the user is looking at, but I don t want to check for all 4 rotation matrices of each cube side. So I wanted to ask if someone knows a better solution. I heard Quaternion are a good way to go, but I don t realy have a clue how they work.
Code: [Select]
public class MyMath {

public static int getVisibleCubeSide(SimpleVector vector){
int vectorX = (int) Math.round(vector.x);
int vectorY = (int) Math.round(vector.y);
int vectorZ = (int) Math.round(vector.z);
    int[][] posibilities = new int[6][4];

//klassenbuch
posibilities[0][0] = 0;
posibilities[0][1] = 0;
posibilities[0][2] = 1;
posibilities[0][3] = 2;

//studenplan
posibilities[1][0] = 0;
posibilities[1][1] = 1;
posibilities[1][2] = 0;
posibilities[1][3] = 1;

//countdown
posibilities[2][0] = 0;
posibilities[2][1] = 0;
posibilities[2][2] = -1;
posibilities[2][3] = 0;

//Lehrer
posibilities[3][0] = 0;
posibilities[3][1] = -1;
posibilities[3][2] = 0;
posibilities[3][3] = 5;

//Trainer
posibilities[4][0] = 1;
posibilities[4][1] = 0;
posibilities[4][2] = 0;
posibilities[4][3] = 4;

//new termine
posibilities[5][0] = -1;
posibilities[5][1] = 0;
posibilities[5][2] = 0;
posibilities[5][3] = 3;

//checks if the parameter vector equals one of the vectors above
for(int i = 0; i < 6; i++){
if(vectorX == posibilities[i][0] && vectorY == posibilities[i][1] && vectorZ == posibilities[i][2]){
Log.i("side", "v" + vector.toString());
Log.i("side", "s: " + posibilities[i][3]);
return posibilities[i][3];
}
}

Log.i("side", "" + -1);
return -1;
}
Thats how i calculate my cube side atm. but it s not always correct cause i only check for one rotation matrix for each side but each side has 4 rotation matrices.
So I hope somebody has a good idea how to calculate the cube side based on matrices.

Pages: [1]