Search in sources :

Example 31 with Vector3

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

the class LevelEditorView method objectScaleApply.

/**
	 * Apply object scale
	 * @param x
	 * @param y
	 * @param z
	 */
public void objectScaleApply(float x, float y, float z) {
    if (selectedObjects.size() == 0)
        return;
    // handle single object
    if (selectedObjects.size() == 1) {
        Entity selectedObject = selectedObjects.get(0);
        LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
        if (currentEntity == null)
            return;
        currentEntity.getTransformations().getScale().set(x, y, z);
        currentEntity.getTransformations().update();
        selectedObject.fromTransformations(currentEntity.getTransformations());
    } else if (selectedObjects.size() > 1) {
        // multiple objects
        for (Entity selectedObject : selectedObjects) {
            LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
            if (currentEntity == null)
                continue;
            currentEntity.getTransformations().getScale().scale(new Vector3(x, y, z));
            currentEntity.getTransformations().update();
            selectedObject.fromTransformations(currentEntity.getTransformations());
        }
        // reset controller object properties
        levelEditorScreenController.setObject(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), 0f, 0f, 0f);
    }
    level.computeDimension();
    updateGUIElements();
}
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) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject)

Example 32 with Vector3

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

the class AngleTest method main.

public static void main(String[] args) {
    Vector3 a = new Vector3(0f, 0f, 1f).normalize();
    Vector3 b = new Vector3(-1f, 0f, +1f).normalize();
    Vector3 n = new Vector3(0f, 1f, 0f);
    System.out.println(Vector3.computeAngle(a, b, n));
}
Also used : Vector3(net.drewke.tdme.math.Vector3)

Example 33 with Vector3

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

the class LevelEditorView method createLevelEditorGroundPlateModel.

/**
	 * Creates a level editor ground plate
	 * @return ground
	 */
private Model createLevelEditorGroundPlateModel() {
    // ground selectedEntity
    Model groundPlate = new Model("leveleditor.ground", "leveleditor.ground", UpVector.Y_UP, RotationOrder.XYZ, (BoundingBox) BoundingBox.createBoundingVolume(new Vector3(0f, -0.01f, 0f), new Vector3(1f, +0.01f, 1f)));
    //	material
    Material groundPlateMaterial = new Material("ground");
    groundPlateMaterial.getDiffuseColor().setAlpha(0.75f);
    groundPlateMaterial.setDiffuseTexture("resources/tools/leveleditor/textures", "groundplate.png");
    groundPlateMaterial.getSpecularColor().set(0f, 0f, 0f, 1f);
    groundPlate.getMaterials().put("ground", groundPlateMaterial);
    //	group
    Group groundGroup = new Group(groundPlate, null, "ground", "ground");
    //	faces entity
    //		ground
    FacesEntity groupFacesEntityGround = new FacesEntity(groundGroup, "leveleditor.ground.facesentity");
    groupFacesEntityGround.setMaterial(groundPlateMaterial);
    //	faces entity 
    ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
    groupFacesEntities.add(groupFacesEntityGround);
    //	vertices
    ArrayList<Vector3> groundVertices = new ArrayList<Vector3>();
    // left, near, ground
    groundVertices.add(new Vector3(0.0f, 0.0f, 0.0f));
    // left, far, ground
    groundVertices.add(new Vector3(0.0f, 0.0f, +groundPlateDepth));
    // right far, ground
    groundVertices.add(new Vector3(+groundPlateWidth, 0.0f, +groundPlateDepth));
    // right, near, ground
    groundVertices.add(new Vector3(+groundPlateWidth, 0.0f, 0.0f));
    //	normals
    ArrayList<Vector3> groundNormals = new ArrayList<Vector3>();
    //		ground
    groundNormals.add(new Vector3(0f, 1f, 0f));
    // texture coordinates
    ArrayList<TextureCoordinate> groundTextureCoordinates = new ArrayList<TextureCoordinate>();
    groundTextureCoordinates.add(new TextureCoordinate(0f, 1f));
    groundTextureCoordinates.add(new TextureCoordinate(0f, 0f));
    groundTextureCoordinates.add(new TextureCoordinate(1f, 0f));
    groundTextureCoordinates.add(new TextureCoordinate(1f, 1f));
    //	faces ground
    ArrayList<Face> groundFacesGround = new ArrayList<Face>();
    groundFacesGround.add(new Face(groundGroup, 0, 1, 2, 0, 0, 0, 0, 1, 2));
    groundFacesGround.add(new Face(groundGroup, 2, 3, 0, 0, 0, 0, 2, 3, 0));
    // set up faces entity
    groupFacesEntityGround.setFaces(groundFacesGround);
    // setup ground group
    groundGroup.setVertices(groundVertices);
    groundGroup.setNormals(groundNormals);
    groundGroup.setTextureCoordinates(groundTextureCoordinates);
    groundGroup.setFacesEntities(groupFacesEntities);
    // register group
    groundPlate.getGroups().put(groundGroup.getId(), groundGroup);
    groundPlate.getSubGroups().put(groundGroup.getId(), groundGroup);
    // prepare for indexed rendering
    ModelHelper.prepareForIndexedRendering(groundPlate);
    //
    return groundPlate;
}
Also used : FacesEntity(net.drewke.tdme.engine.model.FacesEntity) Group(net.drewke.tdme.engine.model.Group) Model(net.drewke.tdme.engine.model.Model) ArrayList(java.util.ArrayList) Vector3(net.drewke.tdme.math.Vector3) Material(net.drewke.tdme.engine.model.Material) TextureCoordinate(net.drewke.tdme.engine.model.TextureCoordinate) Face(net.drewke.tdme.engine.model.Face)

Example 34 with Vector3

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

the class LevelEditorView method objectRotationsApply.

/**
	 * Apply object rotations
	 * @param x
	 * @param y
	 * @param z
	 */
public void objectRotationsApply(float x, float y, float z) {
    if (selectedObjects.size() == 0)
        return;
    // handle single object
    if (selectedObjects.size() == 1) {
        Entity selectedObject = selectedObjects.get(0);
        LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
        if (currentEntity == null)
            return;
        currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisXIndex()).setAngle(x);
        currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).setAngle(y);
        currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).setAngle(z);
        currentEntity.getTransformations().update();
        selectedObject.fromTransformations(currentEntity.getTransformations());
    } else if (selectedObjects.size() > 1) {
        // multiple objects
        for (Entity selectedObject : selectedObjects) {
            LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
            if (currentEntity == null)
                continue;
            currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisXIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisXIndex()).getAngle() + x);
            currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).getAngle() + y);
            currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).getAngle() + z);
            currentEntity.getTransformations().update();
            selectedObject.fromTransformations(currentEntity.getTransformations());
        }
        // reset controller object properties
        levelEditorScreenController.setObject(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), 0f, 0f, 0f);
    }
    level.computeDimension();
    updateGUIElements();
}
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) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject)

Example 35 with Vector3

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

the class LevelEditorEntityLibraryScreenController method onValueChanged.

/*
	 * (non-Javadoc)
	 * @see net.drewke.tdme.gui.events.GUIChangeListener#onValueChanged(net.drewke.tdme.gui.nodes.GUIElementNode)
	 */
public void onValueChanged(GUIElementNode node) {
    if (node.getId().equals("entity_library_listbox") == true) {
        onEntitySelectionChanged();
    } else if (node.getId().equals("dropdown_entity_action") == true) {
        if (node.getController().getValue().equals("edit") == true) {
            onEditEntity();
        } else if (node.getController().getValue().equals("delete") == true) {
            onDeleteEntity();
        } else // model
        if (node.getController().getValue().equals("create_model") == true) {
            // model library
            final LevelEditorEntityLibrary entityLibrary = TDMELevelEditor.getInstance().getEntityLibrary();
            //
            popUps.getFileDialogScreenController().show(modelPath, "Load from: ", new String[] { "tmm", "dae", "tm" }, "", new Action() {

                public void performAction() {
                    try {
                        // add model
                        LevelEditorEntity entity = entityLibrary.addModel(LevelEditorEntityLibrary.ID_ALLOCATE, popUps.getFileDialogScreenController().getFileName(), "", popUps.getFileDialogScreenController().getPathName(), popUps.getFileDialogScreenController().getFileName(), new Vector3(0f, 0f, 0f));
                        entity.setDefaultBoundingVolumes();
                        setEntityLibrary();
                        entityLibraryListBox.getController().setValue(entityLibraryListBoxSelection.set(entity.getId()));
                        onEditEntity();
                    } catch (Exception exception) {
                        popUps.getInfoDialogScreenController().show("Error", "An error occurred: " + exception.getMessage());
                    }
                    modelPath = popUps.getFileDialogScreenController().getPathName();
                    popUps.getFileDialogScreenController().close();
                }
            });
        } else // trigger
        if (node.getController().getValue().equals("create_trigger") == true) {
            try {
                LevelEditorEntity model = TDMELevelEditor.getInstance().getEntityLibrary().addTrigger(LevelEditorEntityLibrary.ID_ALLOCATE, "New trigger", "", 1f, 1f, 1f);
                setEntityLibrary();
                entityLibraryListBox.getController().setValue(entityLibraryListBoxSelection.set(model.getId()));
                onEditEntity();
            } catch (Exception exception) {
                popUps.getInfoDialogScreenController().show("Error", "An error occurred: " + exception.getMessage());
            }
        } else // empty
        if (node.getController().getValue().equals("create_empty") == true) {
            try {
                LevelEditorEntity model = TDMELevelEditor.getInstance().getEntityLibrary().addEmpty(LevelEditorEntityLibrary.ID_ALLOCATE, "New empty", "");
                setEntityLibrary();
                entityLibraryListBox.getController().setValue(entityLibraryListBoxSelection.set(model.getId()));
                onEditEntity();
            } catch (Exception exception) {
                popUps.getInfoDialogScreenController().show("Error", "An error occurred: " + exception.getMessage());
            }
        } else // light
        if (node.getController().getValue().equals("create_light") == true) {
        } else // particle
        if (node.getController().getValue().equals("create_particlesystem") == true) {
            try {
                LevelEditorEntity model = TDMELevelEditor.getInstance().getEntityLibrary().addParticleSystem(LevelEditorEntityLibrary.ID_ALLOCATE, "New particle system", "");
                setEntityLibrary();
                entityLibraryListBox.getController().setValue(entityLibraryListBoxSelection.set(model.getId()));
                onEditEntity();
            } catch (Exception exception) {
                popUps.getInfoDialogScreenController().show("Error", "An error occurred: " + exception.getMessage());
            }
        } else {
            System.out.println("LevelEditorEntityLibraryScreenController::onValueChanged: dropdown_model_create: " + node.getController().getValue());
        }
        // reset
        node.getController().setValue(dropdownEntityActionReset);
    } else {
        System.out.println("LevelEditorEntityLibraryScreenController::onValueChanged: " + node.getId());
    }
}
Also used : LevelEditorEntityLibrary(net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary) Action(net.drewke.tdme.gui.events.Action) Vector3(net.drewke.tdme.math.Vector3) MutableString(net.drewke.tdme.utils.MutableString) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity)

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