Search in sources :

Example 46 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class CollisionDetection method doCollide.

/**
	 * Check if mesh collides with another mesh
	 * 	Will not yet provide hit points
	 * @param convex mesh 1
	 * @param convex mesh 2
	 * @param movement
	 * @param collision response
	 * @return if collided
	 */
public boolean doCollide(ConvexMesh mesh1, ConvexMesh mesh2, Vector3 movement, CollisionResponse collision) {
    collision.reset();
    // do broad test
    if (doBroadTest(mesh1, mesh2) == false)
        return false;
    // do triangle triangle test
    Vector3[] mesh1Vertices = mesh1.getVertices();
    Vector3[] mesh2Vertices = mesh2.getVertices();
    // compute axes and hit points
    resetTriangles();
    for (Triangle triangle1 : mesh1.getTriangles()) for (Triangle triangle2 : mesh2.getTriangles()) {
        // do broad test
        if (doBroadTest(triangle1, triangle2) == false)
            continue;
        //
        Vector3[] triangle1Vertices = triangle1.getVertices();
        triangle1Edge1.set(triangle1Vertices[1]).sub(triangle1Vertices[0]).normalize();
        triangle1Edge2.set(triangle1Vertices[2]).sub(triangle1Vertices[1]).normalize();
        triangle1Edge3.set(triangle1Vertices[0]).sub(triangle1Vertices[2]).normalize();
        Vector3.computeCrossProduct(triangle1Edge1, triangle1Edge2, triangle1Normal).normalize();
        Vector3[] triangle2Vertices = triangle2.getVertices();
        triangle2Edge1.set(triangle2Vertices[1]).sub(triangle2Vertices[0]).normalize();
        triangle2Edge2.set(triangle2Vertices[2]).sub(triangle2Vertices[1]).normalize();
        triangle2Edge3.set(triangle2Vertices[0]).sub(triangle2Vertices[2]).normalize();
        Vector3.computeCrossProduct(triangle2Edge1, triangle2Edge2, triangle2Normal).normalize();
        // compute axes
        resetSATAxes();
        addSATAxis(satAxis.set(triangle1Normal));
        addSATAxis(satAxis.set(triangle2Normal));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge1, triangle2Edge1, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge1, triangle2Edge2, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge1, triangle2Edge3, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge2, triangle2Edge1, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge2, triangle2Edge2, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge2, triangle2Edge3, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge3, triangle2Edge1, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge3, triangle2Edge2, satAxis));
        addSATAxis(Vector3.computeCrossProduct(triangle1Edge3, triangle2Edge3, satAxis));
        // do separating axis test for axes
        for (int satAxisIdx = 0; satAxisIdx < satAxesCount; satAxisIdx++) {
            // compute penetrations
            if (separatingAxisTheorem.doSpanIntersect(mesh1Vertices, mesh2Vertices, satAxes[satAxisIdx], satPenetrations, satAxisIdx) == false) {
                resetSATAxes();
                resetTriangles();
                return false;
            }
        }
        // determine best fit
        determineSatAxisBestFit();
        // store triangles
        testTriangles[testTriangleCount][0] = triangle1;
        testTriangles[testTriangleCount][1] = triangle2;
        testTriangleCount++;
    }
    // 
    if (haveSatAxisBestFit == true) {
        // create single collision response
        CollisionResponse.Entity entity = collision.addResponse(satAxisBestFitPenetration);
        entity.getNormal().set(satAxisBestFit);
        for (int i = 0; i < testTriangleCount; i++) {
            computeHitPoints(testTriangles[i][0], testTriangles[i][1], entity);
        }
    }
    // reset
    resetSATAxes();
    resetTriangles();
    // we have a collision, return collision response
    return collision.hasEntitySelected();
}
Also used : Triangle(net.drewke.tdme.engine.primitives.Triangle) Vector3(net.drewke.tdme.math.Vector3)

Example 47 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class ModelMetaDataFileImport method doImportFromJSON.

/**
	 * Imports a model meta data file from JSON object
	 * @param id or LevelEditorEntity.ID_NONE
	 * @param path name or null
	 * @param JSON entity root
	 */
public static LevelEditorEntity doImportFromJSON(int id, String pathName, JSONObject jEntityRoot) throws Exception {
    LevelEditorEntity levelEditorEntity;
    // check for version
    float version = Float.parseFloat(jEntityRoot.getString("version"));
    // pivot
    Vector3 pivot = new Vector3((float) jEntityRoot.getDouble("px"), (float) jEntityRoot.getDouble("py"), (float) jEntityRoot.getDouble("pz"));
    // String thumbnail = jRoot.getString("thumbnail");
    EntityType modelType = LevelEditorEntity.EntityType.valueOf(jEntityRoot.getString("type"));
    String modelFile = jEntityRoot.has("file") == true ? new File(jEntityRoot.getString("file")).getCanonicalPath() : null;
    String modelThumbnail = jEntityRoot.has("thumbnail") == true ? jEntityRoot.getString("thumbnail") : null;
    String name = jEntityRoot.getString("name");
    String description = jEntityRoot.getString("descr");
    // load model
    Model model = null;
    // having a model file?
    String gameRoot = Tools.getGameRootPath(pathName);
    String modelRelativeFileName = null;
    if (modelFile != null) {
        // yep, load it
        modelRelativeFileName = Tools.getRelativeResourcesFileName(gameRoot, modelFile);
        String modelPath = (gameRoot.length() > 0 ? gameRoot + "/" : "") + Tools.getPath(modelRelativeFileName);
        if (modelFile.toLowerCase().endsWith(".dae")) {
            model = DAEReader.read(modelPath, Tools.getFileName(modelRelativeFileName));
        } else if (modelFile.toLowerCase().endsWith(".tm")) {
            model = TMReader.read(modelPath, Tools.getFileName(modelRelativeFileName));
        } else {
            throw new Exception("Unsupported mode file: " + modelFile);
        }
    } else //	TODO: only load if required e.g. for LevelEditor
    if (modelType == EntityType.EMPTY) {
        model = DAEReader.read("resources/tools/leveleditor/models", "arrow.dae");
    }
    // load level editor model
    levelEditorEntity = new LevelEditorEntity(id, modelType, name, description, null, modelFile != null ? new File(gameRoot, modelRelativeFileName).getCanonicalPath() : null, modelThumbnail, model, pivot);
    // parse properties
    JSONArray jProperties = jEntityRoot.getJSONArray("properties");
    for (int i = 0; i < jProperties.length(); i++) {
        JSONObject jProperty = jProperties.getJSONObject(i);
        levelEditorEntity.addProperty(jProperty.getString("name"), jProperty.getString("value"));
    }
    // old: optional bounding volume
    if (jEntityRoot.has("bv") == true) {
        levelEditorEntity.addBoundingVolume(0, parseBoundingVolume(0, levelEditorEntity, jEntityRoot.getJSONObject("bv")));
    } else // new: optional bounding volumeS
    if (jEntityRoot.has("bvs") == true) {
        JSONArray jBoundingVolumes = jEntityRoot.getJSONArray("bvs");
        for (int i = 0; i < jBoundingVolumes.length(); i++) {
            JSONObject jBv = jBoundingVolumes.getJSONObject(i);
            levelEditorEntity.addBoundingVolume(i, parseBoundingVolume(i, levelEditorEntity, jBv));
        }
    }
    // parse particle system 
    if (modelType == EntityType.PARTICLESYSTEM) {
        LevelEditorEntityParticleSystem particleSystem = levelEditorEntity.getParticleSystem();
        JSONObject jParticleSystem = jEntityRoot.getJSONObject("ps");
        // type
        particleSystem.setType(Type.valueOf(jParticleSystem.getString("t")));
        switch(particleSystem.getType()) {
            case NONE:
                {
                    break;
                }
            case OBJECT_PARTICLE_SYSTEM:
                {
                    JSONObject jObjectParticleSystem = jParticleSystem.getJSONObject("ops");
                    ObjectParticleSystem objectParticleSystem = particleSystem.getObjectParticleSystem();
                    objectParticleSystem.setMaxCount(jObjectParticleSystem.getInt("mc"));
                    objectParticleSystem.getScale().setX((float) jObjectParticleSystem.getDouble("sx"));
                    objectParticleSystem.getScale().setY((float) jObjectParticleSystem.getDouble("sy"));
                    objectParticleSystem.getScale().setZ((float) jObjectParticleSystem.getDouble("sz"));
                    objectParticleSystem.setAutoEmit(jObjectParticleSystem.getBoolean("ae"));
                    try {
                        String particleModelFile = jObjectParticleSystem.getString("mf");
                        String particleModelRelativeFileName = Tools.getRelativeResourcesFileName(gameRoot, particleModelFile);
                        String particleModelPath = (gameRoot.length() > 0 ? gameRoot + "/" : "") + Tools.getPath(particleModelRelativeFileName);
                        objectParticleSystem.setModelFile(particleModelPath + "/" + Tools.getFileName(particleModelRelativeFileName));
                    } catch (Exception exception) {
                        exception.printStackTrace();
                        System.out.println("ModelMetaDataFileImport::doImport(): Failed to set model file: " + exception.getMessage());
                    }
                    break;
                }
            case POINT_PARTICLE_SYSTEM:
                {
                    JSONObject jPointParticleSystem = jParticleSystem.getJSONObject("pps");
                    particleSystem.getPointParticleSystem().setMaxPoints(jPointParticleSystem.getInt("mp"));
                    particleSystem.getPointParticleSystem().setAutoEmit(jPointParticleSystem.getBoolean("ae"));
                    break;
                }
            default:
                {
                    System.out.println("ModelMetaDataFileExport::export(): unknown particle system type '" + particleSystem.getType() + "'");
                    break;
                }
        }
        // emitter
        particleSystem.setEmitter(Emitter.valueOf(jParticleSystem.getString("e")));
        switch(particleSystem.getEmitter()) {
            case NONE:
                {
                    break;
                }
            case POINT_PARTICLE_EMITTER:
                {
                    JSONObject jPointParticleEmitter = jParticleSystem.getJSONObject("ppe");
                    PointParticleEmitter emitter = particleSystem.getPointParticleEmitter();
                    emitter.setCount(jPointParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jPointParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jPointParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jPointParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jPointParticleEmitter.getDouble("mrnd"));
                    emitter.getPosition().setX((float) jPointParticleEmitter.getDouble("px"));
                    emitter.getPosition().setY((float) jPointParticleEmitter.getDouble("py"));
                    emitter.getPosition().setZ((float) jPointParticleEmitter.getDouble("pz"));
                    emitter.getVelocity().setX((float) jPointParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jPointParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jPointParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jPointParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jPointParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jPointParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jPointParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jPointParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jPointParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jPointParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jPointParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jPointParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jPointParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jPointParticleEmitter.getDouble("cea"));
                    break;
                }
            case BOUNDINGBOX_PARTICLE_EMITTER:
                {
                    JSONObject jBoundingBoxParticleEmitter = jParticleSystem.getJSONObject("bbpe");
                    BoundingBoxParticleEmitter emitter = particleSystem.getBoundingBoxParticleEmitters();
                    emitter.setCount(jBoundingBoxParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jBoundingBoxParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jBoundingBoxParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jBoundingBoxParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jBoundingBoxParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jBoundingBoxParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jBoundingBoxParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jBoundingBoxParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jBoundingBoxParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jBoundingBoxParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jBoundingBoxParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jBoundingBoxParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jBoundingBoxParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jBoundingBoxParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jBoundingBoxParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jBoundingBoxParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jBoundingBoxParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jBoundingBoxParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jBoundingBoxParticleEmitter.getDouble("cea"));
                    emitter.getObbCenter().setX((float) jBoundingBoxParticleEmitter.getDouble("ocx"));
                    emitter.getObbCenter().setY((float) jBoundingBoxParticleEmitter.getDouble("ocy"));
                    emitter.getObbCenter().setZ((float) jBoundingBoxParticleEmitter.getDouble("ocz"));
                    emitter.getObbHalfextension().setX((float) jBoundingBoxParticleEmitter.getDouble("ohex"));
                    emitter.getObbHalfextension().setY((float) jBoundingBoxParticleEmitter.getDouble("ohey"));
                    emitter.getObbHalfextension().setZ((float) jBoundingBoxParticleEmitter.getDouble("ohez"));
                    emitter.getObbAxis0().setX((float) jBoundingBoxParticleEmitter.getDouble("oa0x"));
                    emitter.getObbAxis0().setY((float) jBoundingBoxParticleEmitter.getDouble("oa0y"));
                    emitter.getObbAxis0().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa0z"));
                    emitter.getObbAxis1().setX((float) jBoundingBoxParticleEmitter.getDouble("oa1x"));
                    emitter.getObbAxis1().setY((float) jBoundingBoxParticleEmitter.getDouble("oa1y"));
                    emitter.getObbAxis1().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa1z"));
                    emitter.getObbAxis2().setX((float) jBoundingBoxParticleEmitter.getDouble("oa2x"));
                    emitter.getObbAxis2().setY((float) jBoundingBoxParticleEmitter.getDouble("oa2y"));
                    emitter.getObbAxis2().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa2z"));
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER:
                {
                    JSONObject jCircleParticleEmitter = jParticleSystem.getJSONObject("cpe");
                    CircleParticleEmitter emitter = particleSystem.getCircleParticleEmitter();
                    emitter.setCount(jCircleParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jCircleParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jCircleParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jCircleParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jCircleParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jCircleParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jCircleParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jCircleParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jCircleParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jCircleParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jCircleParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jCircleParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jCircleParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jCircleParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jCircleParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jCircleParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jCircleParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jCircleParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jCircleParticleEmitter.getDouble("cea"));
                    emitter.getCenter().setX((float) jCircleParticleEmitter.getDouble("cx"));
                    emitter.getCenter().setY((float) jCircleParticleEmitter.getDouble("cy"));
                    emitter.getCenter().setZ((float) jCircleParticleEmitter.getDouble("cz"));
                    emitter.setRadius((float) jCircleParticleEmitter.getDouble("r"));
                    emitter.getAxis0().setX((float) jCircleParticleEmitter.getDouble("a0x"));
                    emitter.getAxis0().setY((float) jCircleParticleEmitter.getDouble("a0y"));
                    emitter.getAxis0().setZ((float) jCircleParticleEmitter.getDouble("a0z"));
                    emitter.getAxis1().setX((float) jCircleParticleEmitter.getDouble("a1x"));
                    emitter.getAxis1().setY((float) jCircleParticleEmitter.getDouble("a1y"));
                    emitter.getAxis1().setZ((float) jCircleParticleEmitter.getDouble("a1z"));
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY:
                {
                    JSONObject jCircleParticleEmitterPlaneVelocity = jParticleSystem.getJSONObject("cpeev");
                    CircleParticleEmitterPlaneVelocity emitter = particleSystem.getCircleParticleEmitterPlaneVelocity();
                    emitter.setCount(jCircleParticleEmitterPlaneVelocity.getInt("c"));
                    emitter.setLifeTime(jCircleParticleEmitterPlaneVelocity.getLong("lt"));
                    emitter.setLifeTimeRnd(jCircleParticleEmitterPlaneVelocity.getLong("ltrnd"));
                    emitter.setMass((float) jCircleParticleEmitterPlaneVelocity.getDouble("m"));
                    emitter.setMassRnd((float) jCircleParticleEmitterPlaneVelocity.getDouble("mrnd"));
                    emitter.setVelocity((float) jCircleParticleEmitterPlaneVelocity.getDouble("v"));
                    emitter.setVelocityRnd((float) jCircleParticleEmitterPlaneVelocity.getDouble("vrnd"));
                    emitter.getColorStart().setRed((float) jCircleParticleEmitterPlaneVelocity.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jCircleParticleEmitterPlaneVelocity.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jCircleParticleEmitterPlaneVelocity.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jCircleParticleEmitterPlaneVelocity.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jCircleParticleEmitterPlaneVelocity.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jCircleParticleEmitterPlaneVelocity.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jCircleParticleEmitterPlaneVelocity.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jCircleParticleEmitterPlaneVelocity.getDouble("cea"));
                    emitter.getCenter().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("cx"));
                    emitter.getCenter().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("cy"));
                    emitter.getCenter().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("cz"));
                    emitter.setRadius((float) jCircleParticleEmitterPlaneVelocity.getDouble("r"));
                    emitter.getAxis0().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0x"));
                    emitter.getAxis0().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0y"));
                    emitter.getAxis0().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0z"));
                    emitter.getAxis1().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1x"));
                    emitter.getAxis1().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1y"));
                    emitter.getAxis1().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1z"));
                    break;
                }
            case SPHERE_PARTICLE_EMITTER:
                {
                    JSONObject jSphereParticleEmitter = jParticleSystem.getJSONObject("spe");
                    SphereParticleEmitter emitter = particleSystem.getSphereParticleEmitter();
                    emitter.setCount(jSphereParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jSphereParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jSphereParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jSphereParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jSphereParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jSphereParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jSphereParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jSphereParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jSphereParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jSphereParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jSphereParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jSphereParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jSphereParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jSphereParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jSphereParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jSphereParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jSphereParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jSphereParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jSphereParticleEmitter.getDouble("cea"));
                    emitter.getCenter().setX((float) jSphereParticleEmitter.getDouble("cx"));
                    emitter.getCenter().setY((float) jSphereParticleEmitter.getDouble("cy"));
                    emitter.getCenter().setZ((float) jSphereParticleEmitter.getDouble("cz"));
                    emitter.setRadius((float) jSphereParticleEmitter.getDouble("r"));
                    break;
                }
            default:
                System.out.println("ModelMetaDataFileExport::export(): unknown particle system emitter '" + particleSystem.getEmitter() + "'");
        }
    }
    // done
    return levelEditorEntity;
}
Also used : CircleParticleEmitterPlaneVelocity(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity) JSONArray(org.json.JSONArray) CircleParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) JSONException(org.json.JSONException) IOException(java.io.IOException) LevelEditorEntityParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem) EntityType(net.drewke.tdme.tools.shared.model.LevelEditorEntity.EntityType) JSONObject(org.json.JSONObject) Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) BoundingBoxParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter) ObjectParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.ObjectParticleSystem) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) File(java.io.File) SphereParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter) PointParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)

Example 48 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class ModelMetaDataFileImport method parseBoundingVolume.

/**
	 * Parse bounding volume
	 * @param idx
	 * @param level editor entity
	 * @param JSON bounding volume node
	 * @return level editor entity bounding volume
	 * @throws JSONException
	 */
private static LevelEditorEntityBoundingVolume parseBoundingVolume(int idx, LevelEditorEntity levelEditorEntity, JSONObject jBv) throws JSONException {
    LevelEditorEntityBoundingVolume entityBoundingVolume = new LevelEditorEntityBoundingVolume(idx, levelEditorEntity);
    BoundingVolume bv;
    String bvTypeString = jBv.getString("type");
    if (bvTypeString.equalsIgnoreCase("none") == true) {
        entityBoundingVolume.setupNone();
    } else if (bvTypeString.equalsIgnoreCase("sphere") == true) {
        entityBoundingVolume.setupSphere(new Vector3((float) jBv.getDouble("cx"), (float) jBv.getDouble("cy"), (float) jBv.getDouble("cz")), (float) jBv.getDouble("r"));
    } else if (bvTypeString.equalsIgnoreCase("capsule") == true) {
        entityBoundingVolume.setupCapsule(new Vector3((float) jBv.getDouble("ax"), (float) jBv.getDouble("ay"), (float) jBv.getDouble("az")), new Vector3((float) jBv.getDouble("bx"), (float) jBv.getDouble("by"), (float) jBv.getDouble("bz")), (float) jBv.getDouble("r"));
    } else if (bvTypeString.equalsIgnoreCase("aabb") == true) {
        entityBoundingVolume.setupAabb(new Vector3((float) jBv.getDouble("mix"), (float) jBv.getDouble("miy"), (float) jBv.getDouble("miz")), new Vector3((float) jBv.getDouble("max"), (float) jBv.getDouble("may"), (float) jBv.getDouble("maz")));
    } else if (bvTypeString.equalsIgnoreCase("obb") == true) {
        entityBoundingVolume.setupObb(new Vector3((float) jBv.getDouble("cx"), (float) jBv.getDouble("cy"), (float) jBv.getDouble("cz")), new Vector3((float) jBv.getDouble("a0x"), (float) jBv.getDouble("a0y"), (float) jBv.getDouble("a0z")), new Vector3((float) jBv.getDouble("a1x"), (float) jBv.getDouble("a1y"), (float) jBv.getDouble("a1z")), new Vector3((float) jBv.getDouble("a2x"), (float) jBv.getDouble("a2y"), (float) jBv.getDouble("a2z")), new Vector3((float) jBv.getDouble("hex"), (float) jBv.getDouble("hey"), (float) jBv.getDouble("hez")));
    } else if (bvTypeString.equalsIgnoreCase("convexmesh") == true) {
        try {
            entityBoundingVolume.setupConvexMesh(jBv.getString("file"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // done
    return entityBoundingVolume;
}
Also used : LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) Vector3(net.drewke.tdme.math.Vector3) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 49 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class ParticleSystemScreenController method setParticleSystemEmitter.

/**
	 * Set particle system emitter
	 */
public void setParticleSystemEmitter() {
    particleSystemEmitter.getActiveConditions().removeAll();
    LevelEditorEntityParticleSystem particleSystem = view.getEntity().getParticleSystem();
    switch(particleSystem.getEmitter()) {
        case NONE:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_NONE));
                particleSystemEmitter.getActiveConditions().add(EMITTER_NONE);
                break;
            }
        case POINT_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_POINTPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_POINTPARTICLEEMITTER);
                PointParticleEmitter emitter = particleSystem.getPointParticleEmitter();
                ppeCount.getController().setValue(value.set(emitter.getCount()));
                ppeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                ppeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                ppeMass.getController().setValue(value.set(emitter.getMass(), 4));
                ppeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                ppePosition.getController().setValue(value.set(Tools.formatVector3(emitter.getPosition())));
                ppeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                ppeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                ppeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                ppeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                break;
            }
        case BOUNDINGBOX_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_BOUNDINGBOXPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_BOUNDINGBOXPARTICLEEMITTER);
                BoundingBoxParticleEmitter emitter = particleSystem.getBoundingBoxParticleEmitters();
                bbpeCount.getController().setValue(value.set(emitter.getCount()));
                bbpeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                bbpeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                bbpeMass.getController().setValue(value.set(emitter.getMass(), 4));
                bbpeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                bbpeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                bbpeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                bbpeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                bbpeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                bbpeObbCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getObbCenter())));
                bbpeObbHalfextension.getController().setValue(value.set(Tools.formatVector3(emitter.getObbHalfextension())));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getObbAxis0(), emitter.getObbAxis1(), emitter.getObbAxis2());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                bbpeObbRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                bbpeObbRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                bbpeObbRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case CIRCLE_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_CIRCLEPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_CIRCLEPARTICLEEMITTER);
                CircleParticleEmitter emitter = particleSystem.getCircleParticleEmitter();
                cpeCount.getController().setValue(value.set(emitter.getCount()));
                cpeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                cpeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                cpeMass.getController().setValue(value.set(emitter.getMass(), 4));
                cpeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                cpeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                cpeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                cpeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                cpeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                cpeCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                cpeRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getAxis0(), Vector3.computeCrossProduct(emitter.getAxis0(), emitter.getAxis1()), emitter.getAxis1());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                cpeRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                cpeRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                cpeRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_CIRCLEPARTICLEEMITTERPLANEVELOCITY));
                particleSystemEmitter.getActiveConditions().add(EMITTER_CIRCLEPARTICLEEMITTERPLANEVELOCITY);
                CircleParticleEmitterPlaneVelocity emitter = particleSystem.getCircleParticleEmitterPlaneVelocity();
                cpepvCount.getController().setValue(value.set(emitter.getCount()));
                cpepvLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                cpepvLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                cpepvMass.getController().setValue(value.set(emitter.getMass(), 4));
                cpepvMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                cpepvVelocity.getController().setValue(value.set(emitter.getVelocity(), 4));
                cpepvVelocityRnd.getController().setValue(value.set(emitter.getVelocityRnd(), 4));
                cpepvColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                cpepvColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                cpepvCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                cpepvRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getAxis0(), Vector3.computeCrossProduct(emitter.getAxis0(), emitter.getAxis1()), emitter.getAxis1());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                cpepvRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                cpepvRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                cpepvRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case SPHERE_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_SPHEREPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_SPHEREPARTICLEEMITTER);
                SphereParticleEmitter emitter = particleSystem.getSphereParticleEmitter();
                speCount.getController().setValue(value.set(emitter.getCount()));
                speLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                speLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                speMass.getController().setValue(value.set(emitter.getMass(), 4));
                speMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                speVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                speVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                speColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                speColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                speCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                speRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                break;
            }
        default:
            System.out.println("ParticleSystemScreenController::onParticleSystemEmitterApply(): unknown particle system emitter '" + particleSystem.getEmitter() + "'");
    }
    // re init entity in view
    view.initParticleSystem();
}
Also used : CircleParticleEmitterPlaneVelocity(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity) CircleParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter) BoundingBoxParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) LevelEditorEntityParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem) Matrix4x4(net.drewke.tdme.math.Matrix4x4) SphereParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter) PointParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)

Example 50 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class LevelEditorView method centerObject.

/**
	 * Centers selected objects
	 */
public void centerObject() {
    // skip if no objects selected
    if (selectedObjects.size() == 0) {
        return;
    }
    // compute center of selected objects
    Vector3 center = new Vector3();
    for (Entity selectedObject : selectedObjects) {
        center.add(selectedObject.getBoundingBoxTransformed().getMin().clone().add(selectedObject.getBoundingBoxTransformed().getMax()).scale(0.5f));
    }
    engine.getCamera().getLookAt().set(center.scale(1.0f / selectedObjects.size()));
}
Also used : Entity(net.drewke.tdme.engine.Entity) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) FacesEntity(net.drewke.tdme.engine.model.FacesEntity) Vector3(net.drewke.tdme.math.Vector3)

Aggregations

Vector3 (net.drewke.tdme.math.Vector3)75 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)20 Model (net.drewke.tdme.engine.model.Model)20 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)14 ArrayList (java.util.ArrayList)13 Rotation (net.drewke.tdme.engine.Rotation)12 Face (net.drewke.tdme.engine.model.Face)12 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)11 Material (net.drewke.tdme.engine.model.Material)10 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)10 Group (net.drewke.tdme.engine.model.Group)9 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)9 Entity (net.drewke.tdme.engine.Entity)8 Object3D (net.drewke.tdme.engine.Object3D)8 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)8 File (java.io.File)7 IOException (java.io.IOException)7 Transformations (net.drewke.tdme.engine.Transformations)7 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)7 Camera (net.drewke.tdme.engine.Camera)6