Search in sources :

Example 56 with Vector3

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

the class LevelEditorEntityLibrary method addTrigger.

/**
	 * Add a trigger
	 * @param name
	 * @param description
	 * @param width
	 * @param height
	 * @param depth
	 * @return level editor entity
	 * @throws Exception
	 */
public LevelEditorEntity addTrigger(int id, String name, String description, float width, float height, float depth) throws Exception {
    String cacheId = "leveleditor.trigger." + width + "mx" + height + "mx" + depth + "m";
    LevelEditorEntity levelEditorEntity = null;
    BoundingBox boundingBox = new BoundingBox(new Vector3(-width / 2f, 0f, -depth / 2f), new Vector3(+width / 2f, height, +depth / 2f));
    Model model = PrimitiveModel.createModel(boundingBox, cacheId + "_bv");
    levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, EntityType.TRIGGER, name, description, null, cacheId, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3());
    levelEditorEntity.addBoundingVolume(0, new LevelEditorEntityBoundingVolume(0, levelEditorEntity));
    levelEditorEntity.getBoundingVolumeAt(0).setupAabb(boundingBox.getMin(), boundingBox.getMax());
    id = levelEditorEntity.getId();
    // add trigger
    addEntity(levelEditorEntity);
    //
    return levelEditorEntity;
}
Also used : BoundingBox(net.drewke.tdme.engine.primitives.BoundingBox) Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) Vector3(net.drewke.tdme.math.Vector3)

Example 57 with Vector3

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

the class LevelEditorLevel method computeCenter.

/**
	 * @return level center
	 */
public Vector3 computeCenter() {
    Vector3 center = new Vector3();
    int objectCount = 0;
    for (LevelEditorObject levelEditorObject : objects) {
        if (levelEditorObject.getEntity().getType() != EntityType.MODEL)
            continue;
        center.add(levelEditorObject.getTransformations().getTranslation());
        objectCount++;
    }
    if (objectCount != 0)
        center.scale(1f / objectCount);
    return center;
}
Also used : Vector3(net.drewke.tdme.math.Vector3)

Example 58 with Vector3

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

the class TriggerView method updateGUIElements.

/**
	 * Init GUI elements
	 */
public void updateGUIElements() {
    if (entity != null) {
        triggerScreenController.setScreenCaption("Trigger - " + entity.getName());
        PropertyModelClass preset = entity.getProperty("preset");
        triggerScreenController.setEntityProperties(preset != null ? preset.getValue() : null, entity.getProperties(), null);
        triggerScreenController.setEntityData(entity.getName(), entity.getDescription());
        // trigger
        Vector3 dimension = new Vector3();
        dimension.set(entity.getModel().getBoundingBox().getMax());
        dimension.sub(entity.getModel().getBoundingBox().getMin());
        triggerScreenController.setTrigger(dimension.getX(), dimension.getY(), dimension.getZ());
    } else {
        triggerScreenController.setScreenCaption("Trigger - no trigger loaded");
        triggerScreenController.unsetEntityProperties();
        triggerScreenController.unsetEntityData();
        triggerScreenController.unsetTrigger();
    }
}
Also used : PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) Vector3(net.drewke.tdme.math.Vector3)

Example 59 with Vector3

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

the class Tools method computeMaxAxisDimension.

/**
	 * Compute max axis dimension b given bounding box
	 * @param model bounding box
	 * @return max axis dimension
	 */
public static float computeMaxAxisDimension(BoundingVolume modelBoundingVolume) {
    float maxAxisDimension = 0.0f;
    // model dimension
    Vector3 dimension = new Vector3(modelBoundingVolume.computeDimensionOnAxis(new Vector3(1f, 0f, 0f)), modelBoundingVolume.computeDimensionOnAxis(new Vector3(0f, 1f, 0f)), modelBoundingVolume.computeDimensionOnAxis(new Vector3(0f, 0f, 1f)));
    // determine max axis dimension
    if (dimension.getX() > maxAxisDimension)
        maxAxisDimension = dimension.getX();
    if (dimension.getY() > maxAxisDimension)
        maxAxisDimension = dimension.getY();
    if (dimension.getZ() > maxAxisDimension)
        maxAxisDimension = dimension.getZ();
    return maxAxisDimension;
}
Also used : Vector3(net.drewke.tdme.math.Vector3)

Example 60 with Vector3

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

the class Tools method convertToVector3.

/**
	 * Convert to vector 3
	 * @param text
	 * @return vector3
	 */
public static Vector3 convertToVector3(String text) throws NumberFormatException {
    Vector3 v = new Vector3();
    convertToArray(text, 3, v.getArray());
    return v;
}
Also used : 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