From 4881b0c53c48b37a1c8c0cff0641952e61826fd9 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 11 May 2015 19:25:14 -0700 Subject: [PATCH 1/5] copy box to make a new type of line entity item --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 2 ++ libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityTypes.cpp | 2 ++ libraries/entities/src/EntityTypes.h | 7 ++++--- libraries/shared/src/ShapeInfo.h | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 50477356cb..beb8b27e48 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -36,6 +36,7 @@ #include "RenderableSphereEntityItem.h" #include "RenderableTextEntityItem.h" #include "RenderableZoneEntityItem.h" +#include "RenderableLineEntityItem.h" #include "EntitiesRendererLogging.h" EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, @@ -59,6 +60,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(Text, RenderableTextEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(ParticleEffect, RenderableParticleEffectEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) + REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory) _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 0accdf0899..956065d069 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -52,6 +52,7 @@ class EntityItemProperties { friend class TextEntityItem; // TODO: consider removing this friend relationship and use public methods friend class ParticleEffectEntityItem; // TODO: consider removing this friend relationship and use public methods friend class ZoneEntityItem; // TODO: consider removing this friend relationship and use public methods + friend class LineEntityItem; // TODO: consider removing this friend relationship and use public methods public: EntityItemProperties(); virtual ~EntityItemProperties(); diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index f0baa3da93..a9eee5da90 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -25,6 +25,7 @@ #include "SphereEntityItem.h" #include "TextEntityItem.h" #include "ZoneEntityItem.h" +#include "LineEntityItem.h" QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; @@ -41,6 +42,7 @@ REGISTER_ENTITY_TYPE(Light) REGISTER_ENTITY_TYPE(Text) REGISTER_ENTITY_TYPE(ParticleEffect) REGISTER_ENTITY_TYPE(Zone) +REGISTER_ENTITY_TYPE(Line) const QString& EntityTypes::getEntityTypeName(EntityType entityType) { QMap::iterator matchedTypeName = _typeToNameMap.find(entityType); diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 28cfe2278b..28cce52778 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -35,9 +35,10 @@ public: Sphere, Light, Text, - ParticleEffect, - Zone, - LAST = Zone + ParticleEffect, + Zone, + Line, + LAST = Line } EntityType; static const QString& getEntityTypeName(EntityType entityType); diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index 0bfc91c9c5..e10cf1a149 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -31,7 +31,8 @@ enum ShapeType { SHAPE_TYPE_CAPSULE_Z, SHAPE_TYPE_CYLINDER_X, SHAPE_TYPE_CYLINDER_Y, - SHAPE_TYPE_CYLINDER_Z + SHAPE_TYPE_CYLINDER_Z, + SHAPE_TYPE_LINE }; class ShapeInfo { From 38caed00ca903f0b9bad04afb3559703f02a3a16 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 12 May 2015 10:25:50 -0700 Subject: [PATCH 2/5] Attempt to draw line entity item --- examples/grab.js | 15 +++ .../src/RenderableLineEntityItem.cpp | 56 ++++++++ .../src/RenderableLineEntityItem.h | 29 +++++ libraries/entities/src/LineEntityItem.cpp | 108 ++++++++++++++++ libraries/entities/src/LineEntityItem.h | 62 +++++++++ .../src/DeferredLightingEffect.cpp | 120 ++++++++++-------- .../render-utils/src/DeferredLightingEffect.h | 4 + 7 files changed, 341 insertions(+), 53 deletions(-) create mode 100644 libraries/entities-renderer/src/RenderableLineEntityItem.cpp create mode 100644 libraries/entities-renderer/src/RenderableLineEntityItem.h create mode 100644 libraries/entities/src/LineEntityItem.cpp create mode 100644 libraries/entities/src/LineEntityItem.h diff --git a/examples/grab.js b/examples/grab.js index 552a194100..b81c70c541 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -13,6 +13,7 @@ var isGrabbing = false; var grabbedEntity = null; +var lineEntityID = null; var prevMouse = {}; var deltaMouse = { z: 0 @@ -86,6 +87,17 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); + + lineEntityID = Entities.addEntity({ + type: "Line", + position: MyAvatar.position, + // dimensions: {x:5, y:5, z:5}, + dimensions: Vec3.subtract(targetPosition, MyAvatar.position), + color: { red: 0, green: 255, blue: 0 } + // lifetime: 10 + }); + + Audio.playSound(grabSound, { position: props.position, volume: 0.4 @@ -133,6 +145,9 @@ function mouseReleaseEvent() { visible: false }); targetPosition = null; + + Entities.deleteEntity(lineEntityID); + Audio.playSound(grabSound, { position: entityProps.position, volume: 0.25 diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp new file mode 100644 index 0000000000..6f8aed930c --- /dev/null +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -0,0 +1,56 @@ +// +// RenderableLineEntityItem.cpp +// libraries/entities-renderer/src/ +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include + +#include +#include + +#include "RenderableLineEntityItem.h" + +EntityItem* RenderableLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + return new RenderableLineEntityItem(entityID, properties); +} + +void RenderableLineEntityItem::render(RenderArgs* args) { + PerformanceTimer perfTimer("RenderableLineEntityItem::render"); + assert(getType() == EntityTypes::Line); + glm::vec3 position = getPosition(); + // glm::vec3 center = getCenter(); + glm::vec3 dimensions = getDimensions(); + glm::quat rotation = getRotation(); + + const float MAX_COLOR = 255.0f; + + glm::vec4 lineColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, + getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); + + glPushMatrix(); + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + // glPushMatrix(); + // glm::vec3 positionToCenter = center - position; + // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + // glScalef(dimensions.x, dimensions.y, dimensions.z); + + glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; + glm::vec3& p2 = dimensions; + + DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); + + // glPopMatrix(); + glPopMatrix(); + + RenderableDebugableEntityItem::render(this, args); +}; diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.h b/libraries/entities-renderer/src/RenderableLineEntityItem.h new file mode 100644 index 0000000000..0de7cd43ae --- /dev/null +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.h @@ -0,0 +1,29 @@ +// +// RenderableLineEntityItem.h +// libraries/entities-renderer/src/ +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RenderableLineEntityItem_h +#define hifi_RenderableLineEntityItem_h + +#include +#include "RenderableDebugableEntityItem.h" + +class RenderableLineEntityItem : public LineEntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + RenderableLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + LineEntityItem(entityItemID, properties) { } + + virtual void render(RenderArgs* args); +}; + + +#endif // hifi_RenderableLineEntityItem_h diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp new file mode 100644 index 0000000000..61c9542834 --- /dev/null +++ b/libraries/entities/src/LineEntityItem.cpp @@ -0,0 +1,108 @@ +// +// LineEntityItem.cpp +// libraries/entities/src +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include + +#include + +#include "LineEntityItem.h" +#include "EntityTree.h" +#include "EntitiesLogging.h" +#include "EntityTreeElement.h" + + +EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem* result = new LineEntityItem(entityID, properties); + return result; +} + +LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + EntityItem(entityItemID) +{ + _type = EntityTypes::Line; + _created = properties.getCreated(); + setProperties(properties); +} + +EntityItemProperties LineEntityItem::getProperties() const { + EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class + + properties._color = getXColor(); + properties._colorChanged = false; + + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + + return properties; +} + +bool LineEntityItem::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = false; + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qCDebug(entities) << "LineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; +} + +int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + + int bytesRead = 0; + const unsigned char* dataAt = data; + + READ_ENTITY_PROPERTY_COLOR(PROP_COLOR, _color); + + return bytesRead; +} + + +// TODO: eventually only include properties changed since the params.lastViewFrustumSent time +EntityPropertyFlags LineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + return requestedProperties; +} + +void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); +} + +void LineEntityItem::debugDump() const { + quint64 now = usecTimestampNow(); + qCDebug(entities) << " LINE EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(_position); + qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); +} + diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h new file mode 100644 index 0000000000..a834fee816 --- /dev/null +++ b/libraries/entities/src/LineEntityItem.h @@ -0,0 +1,62 @@ +// +// LineEntityItem.h +// libraries/entities/src +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_LineEntityItem_h +#define hifi_LineEntityItem_h + +#include "EntityItem.h" + +class LineEntityItem : public EntityItem { + public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + + ALLOW_INSTANTIATION // This class can be instantiated + + // methods for getting/setting all properties of an entity + virtual EntityItemProperties getProperties() const; + virtual bool setProperties(const EntityItemProperties& properties); + + // TODO: eventually only include properties changed since the params.lastViewFrustumSent time + virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; + + virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const; + + virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData); + + const rgbColor& getColor() const { return _color; } + xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } + + void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); } + void setColor(const xColor& value) { + _color[RED_INDEX] = value.red; + _color[GREEN_INDEX] = value.green; + _color[BLUE_INDEX] = value.blue; + } + + virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } + + virtual void debugDump() const; + + protected: + rgbColor _color; +}; + +#endif // hifi_LineEntityItem_h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index ed24f089d6..4dd31ae92c 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -129,6 +129,20 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) releaseSimpleProgram(); } +void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2) { + + qDebug() << "LINE -- " + << p1[0] << p1[1] << p1[2] + << "," + << p2[0] << p2[1] << p2[2]; + + bindSimpleProgram(); + DependencyManager::get()->renderLine(p1, p2, color1, color2); + releaseSimpleProgram(); +} + + void DeferredLightingEffect::renderSolidCone(float base, float height, int slices, int stacks) { bindSimpleProgram(); DependencyManager::get()->renderCone(base, height, slices, stacks); @@ -288,21 +302,21 @@ void DeferredLightingEffect::render() { program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i)); } } - + if (useSkyboxCubemap) { glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_CUBE_MAP, gpu::GLBackend::getTextureID(_skybox->getCubemap())); - } - - if (locations->lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + } + + if (locations->lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } if (_atmosphere && (locations->atmosphereBufferUnit >= 0)) { - gpu::Batch batch; - batch.setUniformBuffer(locations->atmosphereBufferUnit, _atmosphere->getDataBuffer()); + gpu::Batch batch; + batch.setUniformBuffer(locations->atmosphereBufferUnit, _atmosphere->getDataBuffer()); gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(locations->invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -366,11 +380,11 @@ void DeferredLightingEffect::render() { for (auto lightID : _pointLights) { auto light = _allocatedLights[lightID]; - - if (_pointLightLocations.lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + + if (_pointLightLocations.lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(_pointLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -412,10 +426,10 @@ void DeferredLightingEffect::render() { for (auto lightID : _spotLights) { auto light = _allocatedLights[lightID]; - if (_spotLightLocations.lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + if (_spotLightLocations.lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(_spotLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -535,42 +549,42 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit locations.ambientSphere = program.uniformLocation("ambientSphere.L00"); locations.invViewMat = program.uniformLocation("invViewMat"); - GLint loc = -1; - -#if (GPU_FEATURE_PROFILE == GPU_CORE) - const GLint LIGHT_GPU_SLOT = 3; - loc = glGetUniformBlockIndex(program.programId(), "lightBuffer"); - if (loc >= 0) { - glUniformBlockBinding(program.programId(), loc, LIGHT_GPU_SLOT); - locations.lightBufferUnit = LIGHT_GPU_SLOT; - } else { - locations.lightBufferUnit = -1; - } -#else - loc = program.uniformLocation("lightBuffer"); - if (loc >= 0) { - locations.lightBufferUnit = loc; - } else { - locations.lightBufferUnit = -1; - } + GLint loc = -1; + +#if (GPU_FEATURE_PROFILE == GPU_CORE) + const GLint LIGHT_GPU_SLOT = 3; + loc = glGetUniformBlockIndex(program.programId(), "lightBuffer"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, LIGHT_GPU_SLOT); + locations.lightBufferUnit = LIGHT_GPU_SLOT; + } else { + locations.lightBufferUnit = -1; + } +#else + loc = program.uniformLocation("lightBuffer"); + if (loc >= 0) { + locations.lightBufferUnit = loc; + } else { + locations.lightBufferUnit = -1; + } #endif -#if (GPU_FEATURE_PROFILE == GPU_CORE) - const GLint ATMOSPHERE_GPU_SLOT = 4; - loc = glGetUniformBlockIndex(program.programId(), "atmosphereBufferUnit"); - if (loc >= 0) { - glUniformBlockBinding(program.programId(), loc, ATMOSPHERE_GPU_SLOT); - locations.atmosphereBufferUnit = ATMOSPHERE_GPU_SLOT; - } else { - locations.atmosphereBufferUnit = -1; - } -#else - loc = program.uniformLocation("atmosphereBufferUnit"); - if (loc >= 0) { - locations.atmosphereBufferUnit = loc; - } else { - locations.atmosphereBufferUnit = -1; - } +#if (GPU_FEATURE_PROFILE == GPU_CORE) + const GLint ATMOSPHERE_GPU_SLOT = 4; + loc = glGetUniformBlockIndex(program.programId(), "atmosphereBufferUnit"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, ATMOSPHERE_GPU_SLOT); + locations.atmosphereBufferUnit = ATMOSPHERE_GPU_SLOT; + } else { + locations.atmosphereBufferUnit = -1; + } +#else + loc = program.uniformLocation("atmosphereBufferUnit"); + if (loc >= 0) { + locations.atmosphereBufferUnit = loc; + } else { + locations.atmosphereBufferUnit = -1; + } #endif program.release(); @@ -597,4 +611,4 @@ void DeferredLightingEffect::setGlobalLight(const glm::vec3& direction, const gl void DeferredLightingEffect::setGlobalSkybox(const model::SkyboxPointer& skybox) { _skybox = skybox; -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 66cc6f59e9..fa37d48221 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -54,6 +54,10 @@ public: //// Renders a wireframe cube with the simple program. void renderWireCube(float size, const glm::vec4& color); + //// Renders a line with the simple program. + void renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2); + //// Renders a solid cone with the simple program. void renderSolidCone(float base, float height, int slices, int stacks); From 7a85bfa0d159fcfe6d812f559409f775fae4e70d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 12 May 2015 11:36:05 -0700 Subject: [PATCH 3/5] fix up grab.js to use line entity --- examples/grab.js | 32 ++++++++++--------- .../src/DeferredLightingEffect.cpp | 6 ---- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index b81c70c541..abffef6cb2 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -61,8 +61,13 @@ function vectorIsZero(v) { return v.x == 0 && v.y == 0 && v.z == 0; } -function vectorToString(v) { - return "(" + v.x + ", " + v.y + ", " + v.z + ")" +function nearLinePoint(targetPosition) { + // var handPosition = Vec3.sum(MyAvatar.position, {x:0, y:0.2, z:0}); + var handPosition = MyAvatar.getRightPalmPosition(); + var along = Vec3.subtract(targetPosition, handPosition); + along = Vec3.normalize(along); + along = Vec3.multiply(along, 0.4); + return Vec3.sum(handPosition, along); } @@ -77,7 +82,6 @@ function mousePressEvent(event) { var props = Entities.getEntityProperties(grabbedEntity) isGrabbing = true; originalGravity = props.gravity; - print("mouse-press setting originalGravity " + originalGravity + " " + vectorToString(originalGravity)); targetPosition = props.position; currentPosition = props.position; currentVelocity = props.velocity; @@ -87,17 +91,14 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); - lineEntityID = Entities.addEntity({ - type: "Line", - position: MyAvatar.position, - // dimensions: {x:5, y:5, z:5}, - dimensions: Vec3.subtract(targetPosition, MyAvatar.position), - color: { red: 0, green: 255, blue: 0 } - // lifetime: 10 + type: "Line", + position: nearLinePoint(targetPosition), + dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)), + color: { red: 255, green: 255, blue: 255 }, + lifetime: 300 // if someone crashes while moving something, don't leave the line there forever. }); - Audio.playSound(grabSound, { position: props.position, volume: 0.4 @@ -133,12 +134,9 @@ function mouseReleaseEvent() { // 4. interface A releases the entity and puts the original gravity back // 5. interface B releases the entity and puts the original gravity back (to zero) if (!vectorIsZero(originalGravity)) { - print("mouse-release restoring originalGravity" + vectorToString(originalGravity)); Entities.editEntity(grabbedEntity, { gravity: originalGravity }); - } else { - print("mouse-release not restoring originalGravity of zero"); } Overlays.editOverlay(dropLine, { @@ -162,7 +160,6 @@ function mouseMoveEvent(event) { var props = Entities.getEntityProperties(grabbedEntity); if (!vectorIsZero(props.gravity)) { originalGravity = props.gravity; - print("mouse-move adopting originalGravity" + vectorToString(originalGravity)); } deltaMouse.x = event.x - prevMouse.x; @@ -194,6 +191,11 @@ function mouseMoveEvent(event) { axisAngle = Quat.axis(dQ); angularVelocity = Vec3.multiply((theta / dT), axisAngle); } + + Entities.editEntity(lineEntityID, { + position: nearLinePoint(targetPosition), + dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)) + }); } prevMouse.x = event.x; prevMouse.y = event.y; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 4dd31ae92c..9b0c5647ed 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -131,12 +131,6 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2) { - - qDebug() << "LINE -- " - << p1[0] << p1[1] << p1[2] - << "," - << p2[0] << p2[1] << p2[2]; - bindSimpleProgram(); DependencyManager::get()->renderLine(p1, p2, color1, color2); releaseSimpleProgram(); From 4e679c7e3afcae0f5b89bc6dfab694974babf9b6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 12 May 2015 15:08:26 -0700 Subject: [PATCH 4/5] use toGlm for color. remove some commented-out code --- .../src/RenderableLineEntityItem.cpp | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 6f8aed930c..aaed52c20c 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -26,31 +26,19 @@ void RenderableLineEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLineEntityItem::render"); assert(getType() == EntityTypes::Line); glm::vec3 position = getPosition(); - // glm::vec3 center = getCenter(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); const float MAX_COLOR = 255.0f; - glm::vec4 lineColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, - getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); - + glm::vec4 lineColor(toGlm(getColor()), getLocalRenderAlpha()); glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - // glPushMatrix(); - // glm::vec3 positionToCenter = center - position; - // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - // glScalef(dimensions.x, dimensions.y, dimensions.z); - - glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3& p2 = dimensions; - - DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); - - // glPopMatrix(); + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; + glm::vec3& p2 = dimensions; + DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); glPopMatrix(); - RenderableDebugableEntityItem::render(this, args); }; From 500bb13cbb40b2deb5dbb13665e0fe9073c9c389 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 12 May 2015 15:17:27 -0700 Subject: [PATCH 5/5] c++ --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index aaed52c20c..14628d0a7a 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -28,10 +28,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 position = getPosition(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); - - const float MAX_COLOR = 255.0f; - - glm::vec4 lineColor(toGlm(getColor()), getLocalRenderAlpha()); + glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation);