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();
}
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));
}
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;
}
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();
}
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());
}
}
Aggregations