mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 08:26:36 +02:00
another attempt at zones starting from box
This commit is contained in:
parent
a9c2a6e048
commit
8ce4cb628a
4 changed files with 263 additions and 0 deletions
50
libraries/entities-renderer/src/RenderableZoneEntityItem.cpp
Normal file
50
libraries/entities-renderer/src/RenderableZoneEntityItem.cpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
//
|
||||||
|
// RenderableZoneEntityItem.cpp
|
||||||
|
// interface/src
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 8/6/14.
|
||||||
|
// Copyright 2014 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 <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
|
#include <gpu/GPUConfig.h>
|
||||||
|
|
||||||
|
#include <DeferredLightingEffect.h>
|
||||||
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
#include "RenderableZoneEntityItem.h"
|
||||||
|
|
||||||
|
EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
|
return new RenderableZoneEntityItem(entityID, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderableZoneEntityItem::render(RenderArgs* args) {
|
||||||
|
PerformanceTimer perfTimer("RenderableZoneEntityItem::render");
|
||||||
|
assert(getType() == EntityTypes::Zone);
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
glm::vec3 center = getCenter();
|
||||||
|
glm::vec3 dimensions = getDimensions();
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
const float MAX_COLOR = 255.0f;
|
||||||
|
|
||||||
|
glm::vec4 cubeColor(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);
|
||||||
|
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(1.0f, cubeColor);
|
||||||
|
glPopMatrix();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
};
|
29
libraries/entities-renderer/src/RenderableZoneEntityItem.h
Normal file
29
libraries/entities-renderer/src/RenderableZoneEntityItem.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
//
|
||||||
|
// RenderableZoneEntityItem.h
|
||||||
|
// interface/src/entities
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 8/6/14.
|
||||||
|
// Copyright 2014 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_RenderableZoneEntityItem_h
|
||||||
|
#define hifi_RenderableZoneEntityItem_h
|
||||||
|
|
||||||
|
#include <ZoneEntityItem.h>
|
||||||
|
|
||||||
|
class RenderableZoneEntityItem : public ZoneEntityItem {
|
||||||
|
public:
|
||||||
|
static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
|
RenderableZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
|
ZoneEntityItem(entityItemID, properties)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual void render(RenderArgs* args);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // hifi_RenderableZoneEntityItem_h
|
122
libraries/entities/src/ZoneEntityItem.cpp
Normal file
122
libraries/entities/src/ZoneEntityItem.cpp
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
//
|
||||||
|
// ZoneEntityItem.cpp
|
||||||
|
// libraries/entities/src
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||||
|
// Copyright 2013 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 <QDebug>
|
||||||
|
|
||||||
|
#include <ByteCountCoding.h>
|
||||||
|
|
||||||
|
#include "ZoneEntityItem.h"
|
||||||
|
#include "EntityTree.h"
|
||||||
|
#include "EntitiesLogging.h"
|
||||||
|
#include "EntityTreeElement.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool ZoneEntityItem::_zonesArePickable = false;
|
||||||
|
|
||||||
|
const xColor ZoneEntityItem::DEFAULT_SUN_sunColor = { 255, 255, 255 };
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_INTENSITY = 0.1f;
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_AMBIENT_INTENSITY = 0.0f;
|
||||||
|
const bool ZoneEntityItem::DEFAULT_SUN_USE_EARTH_MODEL = true;
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LATITUDE = 37.777f;
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LONGITUDE = 122.407f;
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_APPARENT_ALTITUDE = 0.03f;
|
||||||
|
const quint16 ZoneEntityItem::DEFAULT_SUN_APPARENT_DAY = 60;
|
||||||
|
const float ZoneEntityItem::DEFAULT_SUN_APPARENT_HOUR = 12.0f;
|
||||||
|
const glm::vec3 ZoneEntityItem::DEFAULT_SUN_DIRECTION = { 0.0f, -1.0f, 0.0f };
|
||||||
|
*/
|
||||||
|
|
||||||
|
EntityItem* ZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
|
EntityItem* result = new ZoneEntityItem(entityID, properties);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
|
EntityItem(entityItemID)
|
||||||
|
{
|
||||||
|
_type = EntityTypes::Zone;
|
||||||
|
_created = properties.getCreated();
|
||||||
|
setProperties(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityItemProperties ZoneEntityItem::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 ZoneEntityItem::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) << "ZoneEntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
|
||||||
|
"now=" << now << " getLastEdited()=" << getLastEdited();
|
||||||
|
}
|
||||||
|
setLastEdited(properties._lastEdited);
|
||||||
|
}
|
||||||
|
return somethingChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZoneEntityItem::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, _sunColor);
|
||||||
|
|
||||||
|
return bytesRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
|
||||||
|
EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
||||||
|
EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params);
|
||||||
|
requestedProperties += PROP_COLOR;
|
||||||
|
return requestedProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoneEntityItem::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 ZoneEntityItem::debugDump() const {
|
||||||
|
quint64 now = usecTimestampNow();
|
||||||
|
qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------";
|
||||||
|
qCDebug(entities) << " color:" << _sunColor[0] << "," << _sunColor[1] << "," << _sunColor[2];
|
||||||
|
qCDebug(entities) << " position:" << debugTreeVector(_position);
|
||||||
|
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
|
||||||
|
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
|
||||||
|
}
|
||||||
|
|
62
libraries/entities/src/ZoneEntityItem.h
Normal file
62
libraries/entities/src/ZoneEntityItem.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//
|
||||||
|
// ZoneEntityItem.h
|
||||||
|
// libraries/entities/src
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||||
|
// Copyright 2013 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_ZoneEntityItem_h
|
||||||
|
#define hifi_ZoneEntityItem_h
|
||||||
|
|
||||||
|
#include "EntityItem.h"
|
||||||
|
|
||||||
|
class ZoneEntityItem : public EntityItem {
|
||||||
|
public:
|
||||||
|
static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
|
ZoneEntityItem(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 _sunColor; }
|
||||||
|
xColor getXColor() const { xColor color = { _sunColor[RED_INDEX], _sunColor[GREEN_INDEX], _sunColor[BLUE_INDEX] }; return color; }
|
||||||
|
|
||||||
|
void setColor(const rgbColor& value) { memcpy(_sunColor, value, sizeof(_sunColor)); }
|
||||||
|
void setColor(const xColor& value) {
|
||||||
|
_sunColor[RED_INDEX] = value.red;
|
||||||
|
_sunColor[GREEN_INDEX] = value.green;
|
||||||
|
_sunColor[BLUE_INDEX] = value.blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; }
|
||||||
|
|
||||||
|
virtual void debugDump() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
rgbColor _sunColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ZoneEntityItem_h
|
Loading…
Reference in a new issue