use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class LevelEditorView method updateGUIElements.
/**
* Update GUI elements
* screen caption
* level size
* selected object
* object properties
* object 3d transformations
* object data
*/
private void updateGUIElements() {
levelEditorScreenController.setScreenCaption("Level Editor - " + level.getFileName());
levelEditorScreenController.setLevelSize(level.getDimension().getX(), level.getDimension().getZ(), level.getDimension().getY());
if (selectedObjects.size() == 1) {
Entity selectedObject = selectedObjects.get(0);
if (selectedObject != null && selectedObject.getId().startsWith("leveleditor.") == false) {
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
PropertyModelClass preset = levelEditorObject.getProperty("preset");
levelEditorScreenController.setObjectProperties(preset != null ? preset.getValue() : "", levelEditorObject.getProperties(), null);
levelEditorScreenController.setObject(selectedObject.getTranslation(), selectedObject.getScale(), selectedObject.getRotations().get(level.getRotationOrder().getAxisXIndex()).getAngle(), selectedObject.getRotations().get(level.getRotationOrder().getAxisYIndex()).getAngle(), selectedObject.getRotations().get(level.getRotationOrder().getAxisZIndex()).getAngle());
// determine center
Vector3 objectCenter = null;
if (levelEditorObject.getEntity().getModel() != null) {
BoundingVolume bv = levelEditorObject.getEntity().getModel().getBoundingBox().clone();
bv.fromBoundingVolumeWithTransformations(bv, levelEditorObject.getTransformations());
objectCenter = bv.getCenter();
} else {
// TODO: this is not the center, applies currently to particle systems
objectCenter = levelEditorObject.getTransformations().getTranslation();
}
//
levelEditorScreenController.setObjectData(levelEditorObject.getId(), levelEditorObject.getDescription(), levelEditorObject.getEntity().getName(), objectCenter);
} else {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.unsetObject();
levelEditorScreenController.unsetObjectProperties();
}
} else if (selectedObjects.size() > 1) {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.setObject(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), 0f, 0f, 0f);
levelEditorScreenController.unsetObjectProperties();
} else if (selectedObjects.size() == 0) {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.unsetObject();
levelEditorScreenController.unsetObjectProperties();
}
// set up lights
for (int i = 0; i < 4; i++) {
levelEditorScreenController.setLight(i, level.getLightAt(i).getAmbient(), level.getLightAt(i).getDiffuse(), level.getLightAt(i).getSpecular(), level.getLightAt(i).getPosition(), level.getLightAt(i).getConstantAttenuation(), level.getLightAt(i).getLinearAttenuation(), level.getLightAt(i).getQuadraticAttenuation(), level.getLightAt(i).getSpotTo(), level.getLightAt(i).getSpotDirection(), level.getLightAt(i).getSpotExponent(), level.getLightAt(i).getSpotCutOff(), level.getLightAt(i).isEnabled());
}
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class EntityBoundingVolumeSubScreenController method onBoundingVolumeObbApply.
/**
* On bounding volume OBB apply
* @param entity
* @param idx
*/
public void onBoundingVolumeObbApply(LevelEditorEntity entity, int idx) {
try {
// rotation axes by rotation angle for x,y,z
Transformations rotations = new Transformations();
rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationZ[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_Z));
rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationY[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_Y));
rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationX[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_X));
rotations.update();
// extract axes from matrix
Vector3 xAxis = new Vector3();
Vector3 yAxis = new Vector3();
Vector3 zAxis = new Vector3();
rotations.getTransformationsMatrix().getAxes(xAxis, yAxis, zAxis);
// delegate to view
view.applyBoundingVolumeObb(entity, idx, Tools.convertToVector3(boundingvolumeObbCenter[idx].getController().getValue().toString()), xAxis, yAxis, zAxis, Tools.convertToVector3(boundingvolumeObbHalfextension[idx].getController().getValue().toString()));
} catch (NumberFormatException nfe) {
showErrorPopUp("Warning", "Invalid number entered");
}
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class EntityBoundingVolumeSubScreenController method setupOrientedBoundingBox.
/**
* Setup oriented bounding box
* @param idx
* @param center
* @param axis 0
* @param axis 1
* @param axis 2
* @param half extension
*/
public void setupOrientedBoundingBox(int idx, Vector3 center, Vector3 axis0, Vector3 axis1, Vector3 axis2, Vector3 halfExtension) {
// set up rotation maxtrix
Vector3 rotation = new Vector3();
Matrix4x4 rotationMatrix = new Matrix4x4().identity();
rotationMatrix.setAxes(axis0, axis1, axis2);
rotationMatrix.computeEulerAngles(rotation);
// set up obb in screen
selectBoundingVolume(idx, BoundingVolumeType.ORIENTEDBOUNDINGBOX);
boundingvolumeObbCenter[idx].getController().setValue(value.reset().append(Tools.formatFloat(center.getX())).append(", ").append(Tools.formatFloat(center.getY())).append(", ").append(Tools.formatFloat(center.getZ())));
boundingvolumeObbHalfextension[idx].getController().setValue(value.reset().append(Tools.formatFloat(halfExtension.getX())).append(", ").append(Tools.formatFloat(halfExtension.getY())).append(", ").append(Tools.formatFloat(halfExtension.getZ())));
boundingvolumeObbRotationX[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
boundingvolumeObbRotationY[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
boundingvolumeObbRotationZ[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class LevelEditorEntityLibrary method addModel.
/**
* Adds a model
* @param id
* @param name
* @param description
* @param path name
* @param file name
* @param pivot
* @return level editor entity
* @throws Exception
*/
public LevelEditorEntity addModel(int id, String name, String description, String pathName, String fileName, Vector3 pivot) throws Exception {
File modelFile = new File(pathName + File.separator + fileName);
LevelEditorEntity levelEditorEntity = null;
// parse models
if (modelFile.getName().toLowerCase().endsWith(".dae")) {
Model model = DAEReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3(0f, 0f, 0f));
} else if (modelFile.getName().toLowerCase().endsWith(".tm")) {
Model model = TMReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3(0f, 0f, 0f));
} else if (modelFile.getName().toLowerCase().endsWith(".tmm")) {
levelEditorEntity = ModelMetaDataFileImport.doImport(id == ID_ALLOCATE ? allocateEntityId() : id, pathName, fileName);
} else {
throw new Exception(pathName + "/" + fileName + ": Unknown model file format");
}
// add model
addEntity(levelEditorEntity);
//
return levelEditorEntity;
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class LevelEditorEntityLibrary method addParticleSystem.
/**
* Add a empty
* @param name
* @param description
* @return level editor entity
* @throws Exception
*/
public LevelEditorEntity addParticleSystem(int id, String name, String description) throws Exception {
// create entity
LevelEditorEntity levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, EntityType.PARTICLESYSTEM, name, description, null, null, null, null, new Vector3());
// add particle system
addEntity(levelEditorEntity);
//
return levelEditorEntity;
}
Aggregations