use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class Level method addLevel.
/**
* Add level to physics world
* @param world
* @param level
* @param rigid bodies (will be filled by logic)
* @param translation
*/
public static void addLevel(World world, LevelEditorLevel level, ArrayList<RigidBody> rigidBodies, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// skip on empties or trigger
if (object.getEntity().getType() == EntityType.EMPTY)
continue;
if (object.getEntity().getType() == EntityType.TRIGGER)
continue;
if (object.getEntity().getType() == EntityType.PARTICLESYSTEM)
continue;
//
for (int j = 0; j < object.getEntity().getBoundingVolumeCount(); j++) {
LevelEditorEntityBoundingVolume entityBv = object.getEntity().getBoundingVolumeAt(j);
// keep track of world ids
String worldId = object.getId() + ".bv." + j;
// TODO: apply transformations
Transformations transformations = new Transformations();
// apply transformations
transformations.fromTransformations(object.getTransformations());
// apply translation
if (translation != null) {
transformations.getTranslation().add(translation);
transformations.update();
}
// add to physics world
RigidBody rigidBody = world.addStaticRigidBody(worldId, true, RIGIDBODY_TYPEID_STATIC, transformations, entityBv.getBoundingVolume(), 1.0f);
rigidBody.setCollisionTypeIds(RIGIDBODY_TYPEID_STATIC | RIGIDBODY_TYPEID_PLAYER);
// add to rigid bodies
rigidBodies.add(rigidBody);
}
}
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class Level method addLevel.
/**
* Add level to engine
* @param engine
* @param level
* @param add empties
* @param add trigger
* @param dynamic shadowing
* @param pickable
* @param translation
*/
public static void addLevel(Engine engine, LevelEditorLevel level, boolean addEmpties, boolean addTrigger, boolean dynamicShadowing, boolean pickable, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
Properties properties = object.getTotalProperties();
// skip on empties or trigger
if (addEmpties == false && object.getEntity().getType() == EntityType.EMPTY)
continue;
if (addTrigger == false && object.getEntity().getType() == EntityType.TRIGGER)
continue;
// add to 3d engine
Entity entity = null;
if (object.getEntity().getModel() != null) {
entity = new Object3D(object.getId(), object.getEntity().getModel());
} else if (object.getEntity().getType() == EntityType.PARTICLESYSTEM) {
entity = createParticleSystem(object.getEntity().getParticleSystem(), object.getId(), false);
}
// skip if we have no entity
if (entity == null)
continue;
// apply transformations
entity.fromTransformations(object.getTransformations());
// apply translation
if (translation != null) {
entity.getTranslation().add(translation);
}
// pickable
entity.setPickable(pickable);
// dynamic shadowing
PropertyModelClass shadowingProperty = properties.getProperty("shadowing");
boolean omitShadowing = shadowingProperty != null && shadowingProperty.getValue().equalsIgnoreCase("false");
entity.setDynamicShadowingEnabled(omitShadowing == true ? false : dynamicShadowing);
// do not scale empties
if (object.getEntity().getType() == EntityType.EMPTY) {
entity.getScale().set(MathTools.sign(entity.getScale().getX()), MathTools.sign(entity.getScale().getY()), MathTools.sign(entity.getScale().getZ()));
}
// update
entity.update();
// add
engine.addEntity(entity);
}
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class Level method disableLevel.
/**
* Disable level in engine
* @param engine
* @param level
*/
public static void disableLevel(Engine engine, LevelEditorLevel level) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// get from 3d engine
Entity entity = engine.getEntity(object.getId());
// skip if entity not found
if (entity == null)
continue;
// disable
entity.setEnabled(false);
}
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class Level method enableLevel.
/**
* Enable disabled level in engine
* @param engine
* @param level
* @param translation
*/
public static void enableLevel(Engine engine, LevelEditorLevel level, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// get from 3d engine
Entity entity = engine.getEntity(object.getId());
// skip if entity not found
if (entity == null)
continue;
// apply transformations
entity.fromTransformations(object.getTransformations());
// apply transformation
if (translation != null) {
entity.getTranslation().add(translation);
}
// do not scale empties
if (object.getEntity().getType() == EntityType.EMPTY) {
entity.getScale().set(MathTools.sign(entity.getScale().getX()), MathTools.sign(entity.getScale().getY()), MathTools.sign(entity.getScale().getZ()));
}
// update
entity.update();
// enable
entity.setEnabled(true);
}
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method handleInputEvents.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.events.GUIInputEventHandler#handleInputEvents()
*/
public void handleInputEvents() {
boolean keyDeleteBefore = keyDelete;
boolean keyControlBefore = keyControl;
boolean keyCBefore = keyC;
boolean keyVBefore = keyV;
boolean keyXBefore = keyX;
// handle keyboard events
for (int i = 0; i < engine.getGUI().getKeyboardEvents().size(); i++) {
GUIKeyboardEvent event = engine.getGUI().getKeyboardEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
//
boolean isKeyDown = event.getType() == Type.KEY_PRESSED;
//
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_CONTROL)
keyControl = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_ESCAPE)
keyEscape = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_LEFT)
keyLeft = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_RIGHT)
keyRight = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_UP)
keyUp = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_DOWN)
keyDown = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_BACKSPACE)
keyDelete = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'x')
keyX = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'c')
keyC = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'v')
keyV = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'a')
keyA = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'd')
keyD = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'w')
keyW = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 's')
keyS = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '+')
keyPlus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '-')
keyMinus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'r')
keyR = isKeyDown;
}
// unselect objects by key escape
if (keyEscape == true && selectedObjects.size() > 0) {
ArrayList<Entity> objectsToRemove = new ArrayList<Entity>();
for (Entity selectedObject : selectedObjects) {
objectsToRemove.add(selectedObject);
}
for (Entity objectToRemove : objectsToRemove) {
setStandardObjectColorEffect(objectToRemove);
selectedObjects.remove(objectToRemove);
selectedObjectsById.remove(objectToRemove.getId());
}
levelEditorScreenController.unselectObjectsInObjectListBox();
}
// handle mouse events
for (int i = 0; i < engine.getGUI().getMouseEvents().size(); i++) {
GUIMouseEvent event = engine.getGUI().getMouseEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
// check if dragging
if (event.getButton() != MOUSE_BUTTON_NONE) {
// check if dragging
if (mouseDragging == false) {
if (mouseDownLastX != event.getX() || mouseDownLastY != event.getY()) {
mouseDragging = true;
}
}
} else {
// unset dragging
if (mouseDragging == true) {
mouseDownLastX = MOUSE_DOWN_LAST_POSITION_NONE;
mouseDownLastY = MOUSE_DOWN_LAST_POSITION_NONE;
mouseDragging = false;
mouseDraggingLastObject = null;
}
}
// selection
if (event.getButton() == MOUSE_BUTTON_LEFT) {
// check if dragging
if (mouseDragging == false) {
if (mouseDownLastX != event.getX() || mouseDownLastY != event.getY()) {
mouseDragging = true;
}
}
// unselect current selected objects
if (keyControl == false) {
ArrayList<Entity> objectsToRemove = new ArrayList<Entity>();
for (Entity selectedObject : selectedObjects) {
if (mouseDragging == true && mouseDraggingLastObject == selectedObject) {
/// no op
} else {
objectsToRemove.add(selectedObject);
}
}
for (Entity objectToRemove : objectsToRemove) {
setStandardObjectColorEffect(objectToRemove);
selectedObjects.remove(objectToRemove);
selectedObjectsById.remove(objectToRemove.getId());
levelEditorScreenController.unselectObjectInObjectListBox(objectToRemove.getId());
}
}
// check if object was clicked first
Entity selectedObject = engine.getObjectByMousePosition(event.getX(), event.getY(), entityPickingFilterNoGrid);
// if not, check if ground plate was clicked
if (selectedObject == null) {
selectedObject = engine.getObjectByMousePosition(event.getX(), event.getY());
}
// select cell if any was selected
if (selectedObject != null) {
// add to selected objects if not yet done
if (mouseDragging == true && mouseDraggingLastObject == selectedObject) {
// no op
} else {
if (selectedObjects.contains(selectedObject) == false) {
setStandardObjectColorEffect(selectedObject);
setHighlightObjectColorEffect(selectedObject);
selectedObjects.add(selectedObject);
selectedObjectsById.put(selectedObject.getId(), selectedObject);
// select in objects listbox
levelEditorScreenController.selectObjectInObjectListbox(selectedObject.getId());
// select in entity library
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
if (levelEditorObject != null) {
TDMELevelEditor.getInstance().getLevelEditorEntityLibraryScreenController().selectEntity(levelEditorObject.getEntity().getId());
}
} else {
// undo add
setStandardObjectColorEffect(selectedObject);
selectedObjects.remove(selectedObject);
selectedObjectsById.remove(selectedObject.getId());
// unselect in objects listbox
levelEditorScreenController.unselectObjectInObjectListBox(selectedObject.getId());
}
}
}
// set mouse dragging last
mouseDraggingLastObject = selectedObject;
// update gui elements
updateGUIElements();
} else // panning
if (event.getButton() == MOUSE_BUTTON_RIGHT) {
if (mouseDownLastX != MOUSE_DOWN_LAST_POSITION_NONE && mouseDownLastY != MOUSE_DOWN_LAST_POSITION_NONE) {
mousePanningSide = event.getX() - mouseDownLastX;
mousePanningForward = event.getY() - mouseDownLastY;
}
} else if (event.getButton() == MOUSE_BUTTON_MIDDLE) {
centerObject();
if (mouseDownLastX != MOUSE_DOWN_LAST_POSITION_NONE && mouseDownLastY != MOUSE_DOWN_LAST_POSITION_NONE) {
mouseRotationX = event.getX() - mouseDownLastX;
mouseRotationY = event.getY() - mouseDownLastY;
}
}
// last mouse down position
if (event.getButton() != MOUSE_BUTTON_NONE) {
//
mouseDownLastX = event.getX();
mouseDownLastY = event.getY();
}
// process mouse wheel events
float mouseWheel = event.getWheelY();
if (mouseWheel != 0) {
camScale += -mouseWheel * 0.05f;
if (camScale < camScaleMin)
camScale = camScaleMin;
if (camScale > camScaleMax)
camScale = camScaleMax;
}
}
// delete objects
if (keyDeleteBefore == true && keyDelete == false) {
removeObject();
}
// cut objects
if ((keyControlBefore == true || keyControl == true) && keyXBefore == true && keyX == false) {
copyObjects();
removeObject();
}
// copy objects
if ((keyControlBefore == true || keyControl == true) && keyCBefore == true && keyC == false) {
copyObjects();
}
// paste objects
if ((keyControlBefore == true || keyControl == true) && keyVBefore == true && keyV == false) {
pasteObjects();
}
}
Aggregations