Search in sources :

Example 1 with Rotation

use of net.drewke.tdme.engine.Rotation in project tdme by andreasdr.

the class LevelFileExport method export.

/**
	 * Exports a level to a TDME level file
	 * @param file name
	 */
public static void export(String fileName, LevelEditorLevel level) throws Exception {
    FileOutputStream fos = null;
    PrintStream fops = null;
    level.setFileName(new File(fileName).getName());
    try {
        // generate json
        LevelEditorEntityLibrary entityLibrary = level.getEntityLibrary();
        JSONObject jRoot = new JSONObject();
        jRoot.put("version", "0.99");
        jRoot.put("ro", level.getRotationOrder().toString());
        JSONArray jLights = new JSONArray();
        for (int i = 0; i < level.getLightCount(); i++) {
            LevelEditorLight light = level.getLightAt(i);
            JSONObject jLight = new JSONObject();
            jLight.put("id", i);
            jLight.put("ar", light.getAmbient().getRed());
            jLight.put("ag", light.getAmbient().getGreen());
            jLight.put("ab", light.getAmbient().getBlue());
            jLight.put("aa", light.getAmbient().getAlpha());
            jLight.put("dr", light.getDiffuse().getRed());
            jLight.put("dg", light.getDiffuse().getGreen());
            jLight.put("db", light.getDiffuse().getBlue());
            jLight.put("da", light.getDiffuse().getAlpha());
            jLight.put("sr", light.getSpecular().getRed());
            jLight.put("sg", light.getSpecular().getGreen());
            jLight.put("sb", light.getSpecular().getBlue());
            jLight.put("sa", light.getSpecular().getAlpha());
            jLight.put("px", light.getPosition().getX());
            jLight.put("py", light.getPosition().getY());
            jLight.put("pz", light.getPosition().getZ());
            jLight.put("pw", light.getPosition().getW());
            jLight.put("stx", light.getSpotTo().getX());
            jLight.put("sty", light.getSpotTo().getY());
            jLight.put("stz", light.getSpotTo().getZ());
            jLight.put("sdx", light.getSpotDirection().getX());
            jLight.put("sdy", light.getSpotDirection().getY());
            jLight.put("sdz", light.getSpotDirection().getZ());
            jLight.put("se", light.getSpotExponent());
            jLight.put("sco", light.getSpotCutOff());
            jLight.put("ca", light.getConstantAttenuation());
            jLight.put("la", light.getLinearAttenuation());
            jLight.put("qa", light.getQuadraticAttenuation());
            jLight.put("e", light.isEnabled());
            jLights.put(jLight);
        }
        jRoot.put("lights", jLights);
        JSONArray jEntityLibrary = new JSONArray();
        for (int i = 0; i < entityLibrary.getEntityCount(); i++) {
            LevelEditorEntity entity = entityLibrary.getEntityAt(i);
            JSONObject jModel = new JSONObject();
            jModel.put("id", entity.getId());
            jModel.put("type", entity.getType());
            jModel.put("name", entity.getName());
            jModel.put("descr", entity.getDescription());
            jModel.put("entity", ModelMetaDataFileExport.exportToJSON(entity));
            jEntityLibrary.put(jModel);
        }
        JSONArray jMapProperties = new JSONArray();
        for (PropertyModelClass mapProperty : level.getProperties()) {
            JSONObject jMapProperty = new JSONObject();
            jMapProperty.put("name", mapProperty.getName());
            jMapProperty.put("value", mapProperty.getValue());
            jMapProperties.put(jMapProperty);
        }
        jRoot.put("properties", jMapProperties);
        jRoot.put("models", jEntityLibrary);
        JSONArray jObjects = new JSONArray();
        for (int i = 0; i < level.getObjectCount(); i++) {
            LevelEditorObject levelEditorObject = level.getObjectAt(i);
            JSONObject jObject = new JSONObject();
            Transformations transformations = levelEditorObject.getTransformations();
            Vector3 translation = transformations.getTranslation();
            Vector3 scale = transformations.getScale();
            Rotation rotationAroundXAxis = transformations.getRotations().get(level.getRotationOrder().getAxisXIndex());
            Rotation rotationAroundYAxis = transformations.getRotations().get(level.getRotationOrder().getAxisYIndex());
            Rotation rotationAroundZAxis = transformations.getRotations().get(level.getRotationOrder().getAxisZIndex());
            jObject.put("id", levelEditorObject.getId());
            jObject.put("descr", levelEditorObject.getDescription());
            jObject.put("mid", levelEditorObject.getEntity().getId());
            jObject.put("tx", translation.getX());
            jObject.put("ty", translation.getY());
            jObject.put("tz", translation.getZ());
            jObject.put("sx", scale.getX());
            jObject.put("sy", scale.getY());
            jObject.put("sz", scale.getZ());
            jObject.put("rx", rotationAroundXAxis.getAngle());
            jObject.put("ry", rotationAroundYAxis.getAngle());
            jObject.put("rz", rotationAroundZAxis.getAngle());
            JSONArray jObjectProperties = new JSONArray();
            for (PropertyModelClass objectProperty : levelEditorObject.getProperties()) {
                JSONObject jObjectProperty = new JSONObject();
                jObjectProperty.put("name", objectProperty.getName());
                jObjectProperty.put("value", objectProperty.getValue());
                jObjectProperties.put(jObjectProperty);
            }
            jObject.put("properties", jObjectProperties);
            jObjects.put(jObject);
        }
        jRoot.put("objects", jObjects);
        jRoot.put("objects_eidx", level.getObjectIdx());
        // save to file
        fos = new FileOutputStream(new File(fileName));
        fops = new PrintStream(fos);
        fops.print(jRoot.toString(2));
    } catch (JSONException je) {
        je.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        if (fops != null)
            fops.close();
        if (fos != null)
            try {
                fos.close();
            } catch (IOException ioe) {
            }
    }
}
Also used : PrintStream(java.io.PrintStream) LevelEditorLight(net.drewke.tdme.tools.shared.model.LevelEditorLight) PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Vector3(net.drewke.tdme.math.Vector3) IOException(java.io.IOException) Rotation(net.drewke.tdme.engine.Rotation) LevelEditorEntityLibrary(net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary) JSONObject(org.json.JSONObject) FileOutputStream(java.io.FileOutputStream) Transformations(net.drewke.tdme.engine.Transformations) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject) File(java.io.File) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity)

Example 2 with Rotation

use of net.drewke.tdme.engine.Rotation in project tdme by andreasdr.

the class LevelFileImport method doImport.

/**
	 * Imports a level from a TDME level file to Level Editor
	 * @param path name
	 * @param file name
	 * @param level
	 * @param object id prefix
	 */
public static void doImport(String pathName, String fileName, LevelEditorLevel level, String objectIdPrefix) throws Exception {
    pathName = pathName.replace(File.separatorChar == '/' ? '\\' : '/', File.separatorChar);
    fileName = fileName.replace(File.separatorChar == '/' ? '\\' : '/', File.separatorChar);
    JSONObject jRoot = null;
    InputStream is = null;
    try {
        jRoot = new JSONObject(new JSONTokener(FileSystem.getInstance().getContent(pathName, fileName)));
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        if (is != null)
            try {
                is.close();
            } catch (IOException ioei) {
            }
    }
    // game root path
    level.setGameRoot(Tools.getGameRootPath(pathName));
    // check for version
    float version = Float.parseFloat(jRoot.getString("version"));
    // new: rotation order
    level.setRotationOrder(jRoot.has("ro") == true ? RotationOrder.valueOf(jRoot.getString("ro")) : RotationOrder.XYZ);
    // map properties
    level.clearProperties();
    // parse properties
    JSONArray jMapProperties = jRoot.getJSONArray("properties");
    for (int i = 0; i < jMapProperties.length(); i++) {
        JSONObject jMapProperty = jMapProperties.getJSONObject(i);
        level.addProperty(jMapProperty.getString("name"), jMapProperty.getString("value"));
    }
    // lights
    if (jRoot.has("lights") == true) {
        JSONArray jLights = jRoot.getJSONArray("lights");
        for (int i = 0; i < jLights.length(); i++) {
            JSONObject jLight = jLights.getJSONObject(i);
            LevelEditorLight light = level.getLightAt(jLight.has("id") ? jLight.getInt("id") : i);
            // set up light in level
            light.getAmbient().set((float) jLight.getDouble("ar"), (float) jLight.getDouble("ag"), (float) jLight.getDouble("ab"), (float) jLight.getDouble("aa"));
            light.getDiffuse().set((float) jLight.getDouble("dr"), (float) jLight.getDouble("dg"), (float) jLight.getDouble("db"), (float) jLight.getDouble("da"));
            light.getSpecular().set((float) jLight.getDouble("sr"), (float) jLight.getDouble("sg"), (float) jLight.getDouble("sb"), (float) jLight.getDouble("sa"));
            light.getPosition().set((float) jLight.getDouble("px"), (float) jLight.getDouble("py"), (float) jLight.getDouble("pz"), (float) jLight.getDouble("pw"));
            light.setConstantAttenuation((float) jLight.getDouble("ca"));
            light.setLinearAttenuation((float) jLight.getDouble("la"));
            light.setQuadraticAttenuation((float) jLight.getDouble("qa"));
            light.getSpotTo().set((float) jLight.getDouble("stx"), (float) jLight.getDouble("sty"), (float) jLight.getDouble("stz"));
            light.getSpotDirection().set((float) jLight.getDouble("sdx"), (float) jLight.getDouble("sdy"), (float) jLight.getDouble("sdz"));
            light.setSpotExponent((float) jLight.getDouble("se"));
            light.setSpotCutOff((float) jLight.getDouble("sco"));
            light.setEnabled(jLight.getBoolean("e"));
        }
    }
    // entities
    level.getEntityLibrary().clear();
    JSONArray jModels = jRoot.getJSONArray("models");
    for (int i = 0; i < jModels.length(); i++) {
        JSONObject jModel = jModels.getJSONObject(i);
        // add model to library
        LevelEditorEntity levelEditorEntity = ModelMetaDataFileImport.doImportFromJSON(jModel.getInt("id"), new File(pathName).getCanonicalPath(), jModel.getJSONObject("entity"));
        // do we have a valid entity?
        if (levelEditorEntity == null) {
            throw new Exception("Invalid entity");
        }
        // add entity
        level.getEntityLibrary().addEntity(levelEditorEntity);
        // parse optional model properties
        if (jModel.has("properties")) {
            JSONArray jModelProperties = jModel.getJSONArray("properties");
            for (int j = 0; j < jModelProperties.length(); j++) {
                JSONObject jModelProperty = jModelProperties.getJSONObject(j);
                levelEditorEntity.addProperty(jModelProperty.getString("name"), jModelProperty.getString("value"));
            }
        }
    }
    // objects
    level.clearObjects();
    JSONArray jObjects = jRoot.getJSONArray("objects");
    for (int i = 0; i < jObjects.length(); i++) {
        JSONObject jObject = jObjects.getJSONObject(i);
        LevelEditorEntity model = level.getEntityLibrary().getEntity(jObject.getInt("mid"));
        Transformations transformations = new Transformations();
        transformations.getPivot().set(model.getPivot());
        transformations.getTranslation().set((float) jObject.getDouble("tx"), (float) jObject.getDouble("ty"), (float) jObject.getDouble("tz"));
        transformations.getScale().set((float) jObject.getDouble("sx"), (float) jObject.getDouble("sy"), (float) jObject.getDouble("sz"));
        Vector3 rotation = new Vector3((float) jObject.getDouble("rx"), (float) jObject.getDouble("ry"), (float) jObject.getDouble("rz"));
        transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis0VectorIndex()], level.getRotationOrder().getAxis0()));
        transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis1VectorIndex()], level.getRotationOrder().getAxis1()));
        transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis2VectorIndex()], level.getRotationOrder().getAxis2()));
        transformations.update();
        LevelEditorObject levelEditorObject = new LevelEditorObject(objectIdPrefix != null ? objectIdPrefix + jObject.getString("id") : jObject.getString("id"), jObject.has("descr") ? jObject.getString("descr") : "", transformations, model);
        levelEditorObject.clearProperties();
        // parse optional object properties, new in LE 0.3a
        if (jObject.has("properties")) {
            JSONArray jObjectProperties = jObject.getJSONArray("properties");
            for (int j = 0; j < jObjectProperties.length(); j++) {
                JSONObject jObjectProperty = jObjectProperties.getJSONObject(j);
                levelEditorObject.addProperty(jObjectProperty.getString("name"), jObjectProperty.getString("value"));
            }
        }
        // check if entity already exists
        //	small workaround for a bug that would allow to place to objects at same place with same model
        /*
			boolean skipObject = false;
			for (int j = 0; j < level.getObjectCount(); j++) {
				LevelEditorObject _levelEditorObject = level.getObjectAt(j);
				if (_levelEditorObject.getModel() == levelEditorObject.getModel() &&
					_levelEditorObject.getTransformations().getTranslation().equals(levelEditorObject.getTransformations().getTranslation())) {
					System.out.println("Skipping '" + levelEditorObject + "' as we already have a object with this model and translation.");
					// we already have a object with selected model on this translation
					skipObject = true;
					break;
				}
			}

			// skip on object if requested
			if (skipObject == true) continue;
			*/
        // otherwise add
        level.addObject(levelEditorObject);
    }
    level.setObjectIdx(jRoot.getInt("objects_eidx"));
    level.setPathName(pathName);
    level.setFileName(fileName);
    level.computeDimension();
}
Also used : LevelEditorLight(net.drewke.tdme.tools.shared.model.LevelEditorLight) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) Vector3(net.drewke.tdme.math.Vector3) IOException(java.io.IOException) Rotation(net.drewke.tdme.engine.Rotation) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) Transformations(net.drewke.tdme.engine.Transformations) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) File(java.io.File)

Example 3 with Rotation

use of net.drewke.tdme.engine.Rotation in project tdme by andreasdr.

the class CameraRotationInputHandler method handleInputEvents.

/*
	 * (non-Javadoc)
	 * @see net.drewke.tdme.gui.events.GUIInputEventHandler#handleInputEvents()
	 */
public void handleInputEvents() {
    // handle mouse events
    for (int i = 0; i < engine.getGUI().getMouseEvents().size(); i++) {
        GUIMouseEvent event = engine.getGUI().getMouseEvents().get(i);
        // skip on processed events
        if (event.isProcessed() == true)
            continue;
        // dragging
        if (mouseDragging == true) {
            if (event.getButton() == 1) {
                float xMoved = (event.getX() - mouseLastX) / 5f;
                float yMoved = (event.getY() - mouseLastY) / 5f;
                mouseLastX = event.getX();
                mouseLastY = event.getY();
                Rotation xRotation = lookFromRotations.getRotations().get(0);
                Rotation yRotation = lookFromRotations.getRotations().get(1);
                float xRotationAngle = xRotation.getAngle() + xMoved;
                float yRotationAngle = yRotation.getAngle() + yMoved;
                xRotation.setAngle(xRotationAngle);
                yRotation.setAngle(yRotationAngle);
                lookFromRotations.update();
            } else {
                mouseDragging = false;
            }
        } else {
            if (event.getButton() == 1) {
                mouseDragging = true;
                mouseLastX = event.getX();
                mouseLastY = event.getY();
            }
        }
        // process mouse wheel events
        float mouseWheel = event.getWheelY();
        if (mouseWheel != 0) {
            scale += mouseWheel * 0.05f;
            if (scale < 0.05f)
                scale = 0.05f;
        }
    }
    // handle keyboard events
    for (int i = 0; i < engine.getGUI().getKeyboardEvents().size(); i++) {
        GUIKeyboardEvent event = engine.getGUI().getKeyboardEvents().get(i);
        // skip on processed events
        if (event.isProcessed() == true)
            continue;
        //
        boolean isKeyDown = event.getType() == Type.KEY_PRESSED;
        if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_LEFT)
            keyLeft = isKeyDown;
        if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_RIGHT)
            keyRight = isKeyDown;
        if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_UP)
            keyUp = isKeyDown;
        if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_DOWN)
            keyDown = isKeyDown;
        if (Character.toLowerCase(event.getKeyChar()) == '.')
            keyPeriod = isKeyDown;
        if (Character.toLowerCase(event.getKeyChar()) == ',')
            keyComma = isKeyDown;
        if (Character.toLowerCase(event.getKeyChar()) == '+')
            keyPlus = isKeyDown;
        if (Character.toLowerCase(event.getKeyChar()) == '-')
            keyMinus = isKeyDown;
        if (Character.toLowerCase(event.getKeyChar()) == 'r')
            keyR = isKeyDown;
    }
    //
    // handle keyboard input
    //	get rotations
    Rotation rotationX = lookFromRotations.getRotations().get(0);
    Rotation rotationY = lookFromRotations.getRotations().get(1);
    Rotation rotationZ = lookFromRotations.getRotations().get(2);
    // 	transfer keyboard inputs to rotations
    if (keyLeft)
        rotationX.setAngle(rotationX.getAngle() - 1f);
    if (keyRight)
        rotationX.setAngle(rotationX.getAngle() + 1f);
    if (keyUp)
        rotationY.setAngle(rotationY.getAngle() + 1f);
    if (keyDown)
        rotationY.setAngle(rotationY.getAngle() - 1f);
    if (keyComma)
        rotationZ.setAngle(rotationZ.getAngle() - 1f);
    if (keyPeriod)
        rotationZ.setAngle(rotationZ.getAngle() + 1f);
    if (keyMinus)
        scale += 0.05f;
    if (keyPlus && scale > 0.05f)
        scale -= 0.05f;
    if (keyR == true || resetRequested == true) {
        rotationY.setAngle(-45f);
        rotationZ.setAngle(0f);
        scale = 1.0f;
    }
    // 	update transformations if key was pressed
    if (keyLeft || keyRight || keyUp || keyDown || keyComma || keyPeriod || keyR || resetRequested) {
        lookFromRotations.update();
        resetRequested = false;
    }
    // set up cam
    Camera cam = engine.getCamera();
    // we have a fixed look at
    Vector3 lookAt = cam.getLookAt();
    // look at -> look to vector
    Vector3 lookAtToFromVector = new Vector3(0f, 0f, +(maxAxisDimension * 1.2f));
    // apply look from rotations
    // apply look from rotations
    Vector3 lookAtToFromVectorTransformed = new Vector3();
    Vector3 lookAtToFromVectorScaled = new Vector3();
    Vector3 upVector = new Vector3();
    lookFromRotations.getTransformationsMatrix().multiply(lookAtToFromVector, lookAtToFromVectorTransformed);
    lookAtToFromVectorScaled.set(lookAtToFromVectorTransformed).scale(scale);
    lookFromRotations.getRotations().get(2).getQuaternion().multiply(new Vector3(0f, 1f, 0f), upVector);
    /*
		Vector3 forwardVector = lookAtToFromVectorTransformed.clone().scale(-1f);
		Vector3 sideVector = Vector3.computeCrossProduct(forwardVector, upVector);

		if (keyA) camLookAt.sub(sideVector.clone().scale(0.05f));
		if (keyD) camLookAt.add(sideVector.clone().scale(0.05f));
		if (keyW) camLookAt.add(upVector.clone().scale(0.05f * forwardVector.computeLength()));
		if (keyS) camLookAt.sub(upVector.clone().scale(0.05f * forwardVector.computeLength()));
		*/
    // look from with rotations
    Vector3 lookFrom = lookAt.clone().add(lookAtToFromVectorScaled);
    cam.getLookFrom().set(lookFrom);
    // up vector
    cam.getUpVector().set(upVector);
}
Also used : GUIKeyboardEvent(net.drewke.tdme.gui.events.GUIKeyboardEvent) Vector3(net.drewke.tdme.math.Vector3) Camera(net.drewke.tdme.engine.Camera) Rotation(net.drewke.tdme.engine.Rotation) GUIMouseEvent(net.drewke.tdme.gui.events.GUIMouseEvent)

Example 4 with Rotation

use of net.drewke.tdme.engine.Rotation in project tdme by andreasdr.

the class RigidBody method synch.

/**
	 * Synchronizes this rigid body with transformations
	 * @param transformations
	 */
public void synch(Transformations transformations) {
    this.transformations.fromTransformations(transformations);
    if (this.cbv != null)
        this.cbv.fromBoundingVolumeWithTransformations(this.obv, this.transformations);
    this.position.set(this.transformations.getTranslation());
    this.orientation.identity();
    for (int i = 0; i < this.transformations.getRotations().size(); i++) {
        Rotation r = this.transformations.getRotations().get(i);
        this.orientation.multiply(r.getQuaternion());
    }
    this.orientation.getArray()[1] *= -1f;
    this.orientation.normalize();
    this.awake(true);
}
Also used : Rotation(net.drewke.tdme.engine.Rotation)

Example 5 with Rotation

use of net.drewke.tdme.engine.Rotation in project tdme by andreasdr.

the class EngineTest method init.

/*
	 * (non-Javadoc)
	 * @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
	 */
public void init(GLAutoDrawable drawable) {
    engine.init(drawable);
    if (osEngine == null) {
        osEngine = Engine.createOffScreenInstance(drawable, 512, 512);
        //
        Light osLight0 = osEngine.getLightAt(0);
        osLight0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
        osLight0.getDiffuse().set(1.0f, 1.0f, 1.0f, 1.0f);
        osLight0.getPosition().set(0.0f, -4f, -4f, 1.0f);
        osLight0.getSpotDirection().set(new Vector3(osLight0.getPosition().getArray())).sub(new Vector3(0f, 0f, 0f));
        osLight0.setEnabled(true);
        // cam
        Camera osCam = osEngine.getCamera();
        osCam.setZNear(0.10f);
        osCam.setZFar(50.00f);
        osCam.getLookFrom().set(0f, 4f, -4f);
        osCam.getLookAt().set(0f, 0.50f, 0f);
        osCam.computeUpVector(osCam.getLookFrom(), osCam.getLookAt(), osCam.getUpVector());
        // scene color
        osEngine.getSceneColor().set(0.5f, 0.0f, 0.0f, 1.0f);
    }
    // cam
    Camera cam = engine.getCamera();
    cam.setZNear(0.10f);
    cam.setZFar(50.00f);
    cam.getLookFrom().set(0f, 3f, -8f);
    cam.getLookAt().set(0f, 0.50f, 0f);
    cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
    // lights
    Light light0 = engine.getLightAt(0);
    light0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
    light0.getDiffuse().set(0.5f, 0.5f, 0.5f, 1f);
    light0.getSpecular().set(1f, 1f, 1f, 1f);
    light0.getPosition().set(0f, 20000f, 0f, 1f);
    light0.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light0.getPosition().getArray()));
    light0.setConstantAttenuation(0.5f);
    light0.setLinearAttenuation(0f);
    light0.setQuadraticAttenuation(0f);
    light0.setSpotExponent(0f);
    light0.setSpotCutOff(180f);
    light0.setEnabled(true);
    Light light1 = engine.getLightAt(1);
    light1.getDiffuse().set(1.0f, 0.0f, 0.0f, 1.0f);
    light1.getPosition().set(-4.0f, 5.0f, -5.0f, 1.0f);
    light1.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light1.getPosition().getArray()));
    light1.setEnabled(true);
    Light light2 = engine.getLightAt(2);
    light2.getDiffuse().set(0.0f, 1.0f, 0.0f, 1.0f);
    light2.getPosition().set(+4.0f, 5.0f, 0.0f, 1.0f);
    light2.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light2.getPosition().getArray()));
    light2.setEnabled(true);
    // scene
    players = new ArrayList<Object3D>();
    playersBoundingVolumeModel = new ArrayList<Object3D>();
    playerBoundingVolumesTransformed = new ArrayList<BoundingVolume>();
    try {
        Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
        Object3D barrel = new Object3D("barrel", _barrel);
        barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
        barrel.getTranslation().set(1.5f, 0.35f, -2f);
        barrel.setDynamicShadowingEnabled(true);
        barrel.setEnabled(true);
        barrel.update();
        barrelBoundingVolumeTransformed = barrelBoundingVolume.clone();
        barrelBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(barrelBoundingVolume, barrel);
        engine.addEntity(barrel);
        // wall
        Model _farPlane = createWallModel();
        Object3D farPlane = new Object3D("wall", _farPlane);
        farPlane.bindDiffuseTexture("wall", "wall", osEngine.getFrameBuffer());
        engine.addEntity(farPlane);
        //
        Model _grass = DAEReader.read("resources/tests/models/grass", "grass.dae");
        Object3D grass = new Object3D("ground", _grass);
        grass.setEnabled(true);
        grass.getScale().set(8f, 1f, 8f);
        grass.update();
        engine.addEntity(grass);
        // players
        Model _player = DAEReader.read("resources/tests/models/dummy", "testDummy_textured.DAE");
        _player.addAnimationSetup("still", 3, 3, true);
        _player.addAnimationSetup("walk", 0, 18, true);
        // player bounding volume
        // playerBoundingVolume = Sphere.createBoundingVolume(new Vector3(0,90f/130f,0), 90f/130f);
        playerBoundingVolume = Capsule.createBoundingVolume(new Vector3(0, 30f / 130f, 0), new Vector3(0, 230f / 130f, 0), 25 / 130f);
        // playerBoundingVolume = BoundingBox.createBoundingVolume(new Vector3(-25f/130f, 0, -25f/130f), new Vector3(+25f/130f, 180f/130f, +25f/130f));
        /*
			playerBoundingVolume = OrientedBoundingBox.createBoundingVolume(
				new Vector3(0f, 90f/130f, 0f),
				new Vector3(1f, 0f, 0f),
				new Vector3(0f, 1f, 0f),
				new Vector3(0f, 0f, 1f),
				new Vector3(25f/130f, 90f/130f, 25f/130f)
			);
			*/
        playerBoundingVolumeModel = PrimitiveModel.createModel(playerBoundingVolume, "player_bv");
        // add player 1
        //	player
        Object3D player1 = new Object3D("player1", _player);
        player1.getTranslation().add(new Vector3(-1.50f, 0f, 0f));
        player1.setAnimation("still");
        player1.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
        player1.update();
        player1.setEnabled(true);
        player1.setPickable(true);
        player1.setDynamicShadowingEnabled(true);
        engine.addEntity(player1);
        //	bounding volume transformed
        BoundingVolume player1BoundingVolumeTransformed = playerBoundingVolume.clone();
        player1BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player1);
        playerBoundingVolumesTransformed.add(player1BoundingVolumeTransformed);
        //	add to engine
        players.add(player1);
        //	bounding volume
        Object3D player1BoundingVolume = new Object3D("player1_bv", playerBoundingVolumeModel);
        player1BoundingVolume.fromTransformations(player1);
        player1BoundingVolume.setEnabled(true);
        playersBoundingVolumeModel.add(player1BoundingVolume);
        // engine.addEntity(player1BoundingVolume);
        // add player 2
        //	player
        Object3D player2 = new Object3D("player2", _player);
        player2.getTranslation().add(new Vector3(1.50f, 0f, 0f));
        player2.setAnimation("still");
        player2.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
        player2.update();
        player2.setEnabled(true);
        player2.setPickable(true);
        player2.setDynamicShadowingEnabled(true);
        players.add(player2);
        //	bounding volume transformed
        BoundingVolume player2BoundingVolumeTransformed = playerBoundingVolume.clone();
        player2BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player2);
        playerBoundingVolumesTransformed.add(player2BoundingVolumeTransformed);
        //	add to engine
        engine.addEntity(player2);
        //	bounding volume
        Object3D player2BoundingVolume = new Object3D("player2_bv", playerBoundingVolumeModel);
        player2BoundingVolume.fromTransformations(player2);
        player2BoundingVolume.setEnabled(true);
        playersBoundingVolumeModel.add(player2BoundingVolume);
        // engine.addEntity(player2BoundingVolume);
        // add cube
        Model _cube = DAEReader.read("resources/tests/models/test", "cube.dae");
        cube = new Object3D("cube", _cube);
        cube.getTranslation().add(new Vector3(0f, 0f, 0f));
        cube.getScale().set(2f, 2f, 2f);
        cube.update();
        cube.setPickable(true);
        cube.setDynamicShadowingEnabled(true);
        cube.setEnabled(true);
        cubeBoundingVolume = cube.getBoundingBox();
        cubeBoundingVolumeTransformed = cubeBoundingVolume.clone();
        cubeBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(cubeBoundingVolume, cube);
        engine.addEntity(cube);
        //
        cubeBoundingVolumeModel = PrimitiveModel.createModel(cubeBoundingVolume, "cube_bv");
        //	bounding volume
        Object3D cubeBoundingVolumeObject3D = new Object3D("cube_bv", cubeBoundingVolumeModel);
        cubeBoundingVolumeObject3D.fromTransformations(cube);
        cubeBoundingVolumeObject3D.setEnabled(true);
        engine.addEntity(cubeBoundingVolumeObject3D);
        // wall
        Model _wall = DAEReader.read("resources/tests/models/wall", "wall.dae");
        Object3D wall0 = new Object3D("wall0", _wall);
        wall0.getTranslation().add(new Vector3(-1.00f, 0f, 3.00f));
        wall0.update();
        wall0.setPickable(true);
        wall0.setEnabled(true);
        engine.addEntity(wall0);
        Object3D wall1 = new Object3D("wall1", _wall);
        wall1.getTranslation().add(new Vector3(0f, 0f, 3.00f));
        wall1.update();
        wall1.setPickable(true);
        wall1.setEnabled(true);
        engine.addEntity(wall1);
        // os engine test
        Object3D osCube = new Object3D("cube", _cube);
        osCube.getTranslation().add(new Vector3(0f, 0f, 0f));
        osCube.getScale().set(2f, 2f, 2f);
        osCube.update();
        osEngine.addEntity(osCube);
        //
        circleTransformations = new Transformations();
        engine.addEntity(new PointsParticleSystemEntity("circle", false, new CircleParticleEmitter(3000, 50, 50, new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 0.4f, 0f, 0f, new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.2f, 0f), new Color4(1f, 1f, 1f, 0.3f), new Color4(1f, 1f, 1f, 0.3f)), 1000, true));
        engine.getEntity("circle").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("water", true, new SphereParticleEmitter(4000, 1000, 0, 0.1f, 0.0f, new Sphere(new Vector3(-1f, 1f, 0f), 0.05f), new Vector3(-4f, 0f, 1f), new Vector3(-1f, 0f, 0f), new Color4(0.8f, 0.8f, 1f, 0.25f), new Color4(0.8f, 0.8f, 1f, 0.25f)), 4000, true));
        engine.getEntity("water").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("snow", false, new BoundingBoxParticleEmitter(15, 15000, 1000, 0, 0, new OrientedBoundingBox(new Vector3(0f, 4f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(0f, 0f, 1f), new Vector3(4f, 0f, 4f)), new Vector3(0f, -0.5f, 0f), new Vector3(0f, -0.1f, 0f), new Color4(0.8f, 0.8f, 1f, 0.5f), new Color4(0.8f, 0.8f, 1f, 0.5f)), 1024, true));
        engine.getEntity("snow").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("firebase", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.2f, 0f), 0.2f), new Vector3(0f, 0.1f, 0f), new Vector3(0f, 0.1f, 0f), new Color4(0.0f, 0f, 0f, 0.5f), new Color4(0.4f, 0f, 0f, 0.5f)), 2048, true));
        engine.getEntity("firebase").setEnabled(true);
        //
        engine.addEntity(new PointsParticleSystemEntity("firetop", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.06f, 0f), new Vector3(0f, 0.12f, 0f), new Color4(0.75f, 0.0f, 0f, 0.5f), new Color4(1f, 1f, 0f, 0.5f)), 2048, true));
        engine.getEntity("firetop").setEnabled(true);
        //
        engine.addEntity(new PointsParticleSystemEntity("firesmoke", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.4f, 0f), new Color4(0.8f, 0.8f, 0.8f, 0.1f), new Color4(0.8f, 0.8f, 0.8f, 0.1f)), 2048, true));
        engine.getEntity("firesmoke").setEnabled(true);
        ((ParticleSystemEntity) engine.getEntity("circle")).setPickable(false);
        ((ParticleSystemEntity) engine.getEntity("snow")).setPickable(false);
        ((ParticleSystemEntity) engine.getEntity("firebase")).setPickable(true);
        ((ParticleSystemEntity) engine.getEntity("firetop")).setPickable(true);
        ((ParticleSystemEntity) engine.getEntity("firesmoke")).setPickable(true);
    } catch (Exception exception) {
        exception.printStackTrace();
        System.out.println("Could not load object: " + exception.getMessage());
    }
}
Also used : CircleParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.CircleParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh) Object3DModel(net.drewke.tdme.engine.Object3DModel) PointsParticleSystemEntity(net.drewke.tdme.engine.PointsParticleSystemEntity) PointsParticleSystemEntity(net.drewke.tdme.engine.PointsParticleSystemEntity) ParticleSystemEntity(net.drewke.tdme.engine.subsystems.particlesystem.ParticleSystemEntity) Rotation(net.drewke.tdme.engine.Rotation) Object3D(net.drewke.tdme.engine.Object3D) Sphere(net.drewke.tdme.engine.primitives.Sphere) Color4(net.drewke.tdme.engine.model.Color4) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) Light(net.drewke.tdme.engine.Light) Model(net.drewke.tdme.engine.model.Model) Object3DModel(net.drewke.tdme.engine.Object3DModel) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) Transformations(net.drewke.tdme.engine.Transformations) BoundingBoxParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.BoundingBoxParticleEmitter) Camera(net.drewke.tdme.engine.Camera) SphereParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.SphereParticleEmitter)

Aggregations

Rotation (net.drewke.tdme.engine.Rotation)14 Vector3 (net.drewke.tdme.math.Vector3)12 Transformations (net.drewke.tdme.engine.Transformations)8 Object3D (net.drewke.tdme.engine.Object3D)6 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)5 Camera (net.drewke.tdme.engine.Camera)4 Model (net.drewke.tdme.engine.model.Model)4 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)4 File (java.io.File)3 Light (net.drewke.tdme.engine.Light)3 Object3DModel (net.drewke.tdme.engine.Object3DModel)3 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)3 ConvexMesh (net.drewke.tdme.engine.primitives.ConvexMesh)3 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)3 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)3 Sphere (net.drewke.tdme.engine.primitives.Sphere)3 IOException (java.io.IOException)2 Entity (net.drewke.tdme.engine.Entity)2 Rotations (net.drewke.tdme.engine.Rotations)2 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)2