From 477447b95fd0bc76c9074a09745d1e75da3d718a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 6 May 2015 23:36:44 +0200 Subject: [PATCH 1/6] Planky game script --- examples/example/games/planky.js | 140 +++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 examples/example/games/planky.js diff --git a/examples/example/games/planky.js b/examples/example/games/planky.js new file mode 100644 index 0000000000..77711958ea --- /dev/null +++ b/examples/example/games/planky.js @@ -0,0 +1,140 @@ +// +// planky.js +// examples +// +// Created by Thijs Wenker on 5/2/14. +// Copyright 2015 High Fidelity, Inc. +// +// Pull blocks off the bottom and put them on the top using the grab.js script. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + +const NUM_LAYERS = 16; +const BASE_DIMENSION = { x: 7, y: 2, z: 7 }; +const BLOCKS_PER_LAYER = 3; +const BLOCK_SIZE = {x: 0.2, y: 0.1, z: 0.8}; +const BLOCK_SPACING = BLOCK_SIZE.x / 3; +const GRAVITY = {x: 0, y: -2.8, z: 0}; +const DENSITY = 2000; +const DAMPING_FACTOR = 0.98; +const ANGULAR_DAMPING_FACTOR = 0.8; +const SPAWN_DISTANCE = 3; +const BLOCK_YAW_OFFSET = 45; +const BUTTON_DIMENSIONS = {width: 49, height: 49}; + +var windowWidth = Window.innerWidth; +var size; +var pieces = []; +var ground = false; +var layerRotated = false; + +function grabLowestJointY() { + var jointNames = MyAvatar.getJointNames(); + var floorY = MyAvatar.position.y; + for (var jointName in jointNames) { + if (MyAvatar.getJointPosition(jointNames[jointName]).y < floorY) { + floorY = MyAvatar.getJointPosition(jointNames[jointName]).y; + } + } + return floorY; +} + +function getButtonPosX() { + return windowWidth - ((BUTTON_DIMENSIONS.width / 2) + BUTTON_DIMENSIONS.width); +} + +var button = Overlays.addOverlay('image', { + x: getButtonPosX(), + y: 10, + width: BUTTON_DIMENSIONS.width, + height: BUTTON_DIMENSIONS.height, + imageURL: HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/planky_button.svg', + alpha: 1 +}); + + +function resetBlocks() { + pieces.forEach(function(piece) { + Entities.deleteEntity(piece); + }); + pieces = []; + var avatarRot = Quat.fromPitchYawRollDegrees(0.0, MyAvatar.bodyYaw, 0.0); + basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(SPAWN_DISTANCE, Quat.getFront(avatarRot))); + basePosition.y = grabLowestJointY() - (BASE_DIMENSION.y / 2); + if (!ground) { + ground = Entities.addEntity({ + type: 'Model', + modelURL: HIFI_PUBLIC_BUCKET + 'eric/models/woodFloor.fbx', + dimensions: BASE_DIMENSION, + position: basePosition, + rotation: avatarRot, + shapeType: 'box' + }); + } else { + Entities.editEntity(ground, {position: basePosition, rotation: avatarRot}); + } + var offsetRot = Quat.multiply(avatarRot, Quat.fromPitchYawRollDegrees(0.0, BLOCK_YAW_OFFSET, 0.0)); + basePosition.y += (BASE_DIMENSION.y / 2); + for (var layerIndex = 0; layerIndex < NUM_LAYERS; layerIndex++) { + var layerRotated = layerIndex % 2 === 0; + var offset = -(BLOCK_SPACING); + var layerRotation = Quat.fromPitchYawRollDegrees(0, layerRotated ? 0 : 90, 0.0); + for (var blockIndex = 0; blockIndex < BLOCKS_PER_LAYER; blockIndex++) { + var blockPositionXZ = BLOCK_SIZE.x * blockIndex - (BLOCK_SIZE.x * 3 / 2 - BLOCK_SIZE.x / 2); + var localTransform = Vec3.multiplyQbyV(offsetRot, { + x: (layerRotated ? blockPositionXZ + offset: 0), + y: (BLOCK_SIZE.y / 2) + (BLOCK_SIZE.y * layerIndex), + z: (layerRotated ? 0 : blockPositionXZ + offset) + }); + pieces.push(Entities.addEntity({ + type: 'Model', + modelURL: HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx', + shapeType: 'box', + name: 'JengaBlock' + ((layerIndex * BLOCKS_PER_LAYER) + blockIndex), + dimensions: BLOCK_SIZE, + position: { + x: basePosition.x + localTransform.x, + y: basePosition.y + localTransform.y, + z: basePosition.z + localTransform.z + }, + rotation: Quat.multiply(layerRotation, offsetRot), + collisionsWillMove: true, + damping: DAMPING_FACTOR, + angularDamping: ANGULAR_DAMPING_FACTOR, + gravity: GRAVITY, + density: DENSITY + })); + offset += BLOCK_SPACING; + } + } +} + +function mousePressEvent(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + if (clickedOverlay === button) { + resetBlocks(); + } +} + +Controller.mousePressEvent.connect(mousePressEvent); + +function cleanup() { + Overlays.deleteOverlay(button); + if (ground) { + Entities.deleteEntity(ground); + } + pieces.forEach(function(piece) { + Entities.deleteEntity(piece); + }); + pieces = []; +} + +function onUpdate() { + +} + +Script.update.connect(onUpdate) +Script.scriptEnding.connect(cleanup); From 561d275dda13336df375ba625497b1ffeb4179b7 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 6 May 2015 15:18:17 -0700 Subject: [PATCH 2/6] Fix ensmallened overlay UI --- interface/src/ui/ApplicationOverlay.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index c410b992c4..71fe528700 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -190,8 +190,8 @@ void ApplicationOverlay::renderOverlay() { Overlays& overlays = qApp->getOverlays(); _textureFov = glm::radians(_hmdUIAngularSize); - auto deviceSize = Application::getInstance()->getDeviceSize(); - _textureAspectRatio = (float)deviceSize.width() / (float)deviceSize.height(); + glm::vec2 deviceSize = qApp->getCanvasSize(); + _textureAspectRatio = (float)deviceSize.x / (float)deviceSize.y; //Handle fading and deactivation/activation of UI @@ -209,7 +209,7 @@ void ApplicationOverlay::renderOverlay() { const float NEAR_CLIP = -10000; const float FAR_CLIP = 10000; glLoadIdentity(); - glOrtho(0, deviceSize.width(), deviceSize.height(), 0, NEAR_CLIP, FAR_CLIP); + glOrtho(0, deviceSize.x, deviceSize.y, 0, NEAR_CLIP, FAR_CLIP); glMatrixMode(GL_MODELVIEW); @@ -270,11 +270,11 @@ void ApplicationOverlay::displayOverlayTexture() { glEnable(GL_BLEND); } + static const glm::vec2 topLeft(-1, 1); + static const glm::vec2 bottomRight(1, -1); + static const glm::vec2 texCoordTopLeft(0.0f, 1.0f); + static const glm::vec2 texCoordBottomRight(1.0f, 0.0f); with_each_texture(_overlays.getTexture(), _newUiTexture, [&] { - static const glm::vec2 topLeft(-1, 1); - static const glm::vec2 bottomRight(1, -1); - static const glm::vec2 texCoordTopLeft(0.0f, 1.0f); - static const glm::vec2 texCoordBottomRight(1.0f, 0.0f); DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); }); From 3b8108e887bff2548b02ad2aac940cbaa8c5b682 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 6 May 2015 16:09:17 -0700 Subject: [PATCH 3/6] Fix inverted icons --- libraries/render-utils/src/TextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 2f9960355f..bd243cbe88 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -294,7 +294,7 @@ GLuint TextureCache::getShadowDepthTextureID() { /// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString & path) { - QImage image(path); + QImage image = QImage(path).mirrored(false, true); gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); if (image.hasAlphaChannel()) { From bba7dcfe5fc1191b981b8bcc776e57c7d7734d62 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 6 May 2015 23:32:02 -0700 Subject: [PATCH 4/6] Try to fix the transform stack issue in 1st person --- interface/src/avatar/MyAvatar.cpp | 6 ++++-- libraries/octree/src/ViewFrustum.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 667a89a46b..a470867129 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1173,8 +1173,10 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderArgs::RenderMode ren Camera *camera = Application::getInstance()->getCamera(); const glm::vec3 cameraPos = camera->getPosition(); + + // HACK: comment this block which possibly change the near and break the rendering 5/6/2015 // Only tweak the frustum near far if it's not shadow - if (renderMode != RenderArgs::SHADOW_RENDER_MODE) { + /* if (renderMode != RenderArgs::SHADOW_RENDER_MODE) { // Set near clip distance according to skeleton model dimensions if first person and there is no separate head model. if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) { renderFrustum->setNearClip(DEFAULT_NEAR_CLIP); @@ -1184,7 +1186,7 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderArgs::RenderMode ren + camera->getOrientation() * glm::vec3(0.0f, 0.0f, -clipDistance) - cameraPos); renderFrustum->setNearClip(clipDistance); } - } + }*/ // Render the body's voxels and head RenderArgs::RenderMode modelRenderMode = renderMode; diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index dfb0dcb308..5b20126293 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -30,7 +30,8 @@ const float DEFAULT_KEYHOLE_RADIUS = 3.0f; const float DEFAULT_FIELD_OF_VIEW_DEGREES = 45.0f; const float DEFAULT_ASPECT_RATIO = 16.0f/9.0f; -const float DEFAULT_NEAR_CLIP = 0.08f; +//const float DEFAULT_NEAR_CLIP = 0.08f; +const float DEFAULT_NEAR_CLIP = 0.25f; const float DEFAULT_FAR_CLIP = (float)TREE_SCALE; class ViewFrustum { From fe14202f512119ada1c633eda7dfa419eca8f597 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 7 May 2015 09:53:39 -0700 Subject: [PATCH 5/6] add getName passthrough to ObjecdtMotionState, don't compute model shapes until the model has been simulated --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 5 +++++ libraries/fbx/src/OBJReader.cpp | 4 ++-- libraries/physics/src/EntityMotionState.cpp | 9 +++++++++ libraries/physics/src/EntityMotionState.h | 2 ++ libraries/physics/src/ObjectMotionState.h | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f097ae4e2f..43112d7d73 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -278,6 +278,11 @@ bool RenderableModelEntityItem::isReadyToComputeShape() { return false; // hmm... } + if (_needsInitialSimulation) { + // the _model's offset will be wrong until _needsInitialSimulation is false + return false; + } + assert(!_model->getCollisionURL().isEmpty()); if (_model->getURL().isEmpty()) { diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index ebfa9b54f0..c4e2178b6b 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -484,7 +484,7 @@ FBXGeometry OBJReader::readOBJ(QIODevice* device, const QVariantHash& mapping, Q meshPart._material->setShininess(material->shininess); meshPart._material->setOpacity(material->opacity); } - qCDebug(modelformat) << "OBJ Reader part:" << meshPartCount << "name:" << leadFace.groupName << "material:" << groupMaterialName << "diffuse:" << meshPart._material->getDiffuse() << "faces:" << faceGroup.count() << "triangle indices will start with:" << mesh.vertices.count(); + // qCDebug(modelformat) << "OBJ Reader part:" << meshPartCount << "name:" << leadFace.groupName << "material:" << groupMaterialName << "diffuse:" << meshPart._material->getDiffuse() << "faces:" << faceGroup.count() << "triangle indices will start with:" << mesh.vertices.count(); foreach(OBJFace face, faceGroup) { glm::vec3 v0 = vertices[face.vertexIndices[0]]; glm::vec3 v1 = vertices[face.vertexIndices[1]]; @@ -526,7 +526,7 @@ FBXGeometry OBJReader::readOBJ(QIODevice* device, const QVariantHash& mapping, Q mesh.meshExtents.addPoint(vertex); geometry.meshExtents.addPoint(vertex); } - fbxDebugDump(geometry); + // fbxDebugDump(geometry); } catch(const std::exception& e) { qCDebug(modelformat) << "OBJ reader fail: " << e.what(); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f1c0daea26..1e5bdac32d 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -502,3 +502,12 @@ void EntityMotionState::setMotionType(MotionType motionType) { ObjectMotionState::setMotionType(motionType); resetMeasuredBodyAcceleration(); } + + +// virtual +QString EntityMotionState::getName() { + if (_entity) { + return _entity->getName(); + } + return ""; +} diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 71b1962368..1c45b40627 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -81,6 +81,8 @@ public: void resetMeasuredBodyAcceleration(); void measureBodyAcceleration(); + virtual QString getName(); + friend class PhysicalEntitySimulation; protected: diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index 4836cf52fd..edfff27e8d 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -119,6 +119,8 @@ public: virtual QUuid getSimulatorID() const = 0; virtual void bump() = 0; + virtual QString getName() { return ""; } + friend class PhysicsEngine; protected: From 867fe184724c6b98ff61a81b5d23069a5784bc5e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 7 May 2015 10:11:36 -0700 Subject: [PATCH 6/6] put some code back now that entity-server is doing simple simulation again. don't draw blue physics-enabled dot unless debug menu-item is checked --- .../src/RenderableDebugableEntityItem.cpp | 21 ++++--------------- libraries/physics/src/EntityMotionState.cpp | 16 +++----------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index 98ec154d01..017cb289f0 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -79,22 +79,9 @@ void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) glm::vec4 yellowColor(1.0f, 1.0f, 0.2f, 1.0f); renderBoundingBox(entity, args, 0.3f, yellowColor); } + + if (PhysicsEngine::physicsInfoIsActive(entity->getPhysicsInfo())) { + renderHoverDot(entity, args); + } } - - if (PhysicsEngine::physicsInfoIsActive(entity->getPhysicsInfo())) { - renderHoverDot(entity, args); - } - - glm::vec3 position; - glm::quat rotation; - - // - // XXX for future debugging - // - // if (PhysicsEngine::getBodyLocation(entity->getPhysicsInfo(), position, rotation)) { - // glm::vec3 positionOffset = glm::abs(position - entity->getPosition()); - // if (positionOffset[0] > 0.001 || positionOffset[1] > 0.001 || positionOffset[2] > 0.001) { - // qDebug() << positionOffset[0] << positionOffset[1] << positionOffset[2]; - // } - // } } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 1e5bdac32d..1428287f8f 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -48,7 +48,6 @@ EntityMotionState::~EntityMotionState() { } void EntityMotionState::updateServerPhysicsVariables(uint32_t flags) { - /* if (flags & EntityItem::DIRTY_POSITION) { _sentPosition = _entity->getPosition(); } @@ -61,7 +60,6 @@ void EntityMotionState::updateServerPhysicsVariables(uint32_t flags) { if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) { _sentAngularVelocity = _entity->getAngularVelocity(); } - */ } // virtual @@ -96,17 +94,9 @@ bool EntityMotionState::isMoving() const { } bool EntityMotionState::isMovingVsServer() const { - // auto alignmentDot = glm::abs(glm::dot(_sentRotation, _entity->getRotation())); - // if (glm::distance(_sentPosition, _entity->getPosition()) > IGNORE_POSITION_DELTA || - // alignmentDot < IGNORE_ALIGNMENT_DOT) { - // return true; - // } - // return false; - - if (glm::length(_entity->getVelocity()) > IGNORE_LINEAR_VELOCITY_DELTA) { - return true; - } - if (glm::length(_entity->getAngularVelocity()) > IGNORE_ANGULAR_VELOCITY_DELTA) { + auto alignmentDot = glm::abs(glm::dot(_sentRotation, _entity->getRotation())); + if (glm::distance(_sentPosition, _entity->getPosition()) > IGNORE_POSITION_DELTA || + alignmentDot < IGNORE_ALIGNMENT_DOT) { return true; } return false;