mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-18 13:43:17 +02:00
Support for Camera Entities.
- New entity type: camera, with just the basic properties of an entity (position, rotation, name etc.). - New CameraMode: CameraEntity - Example script using the new cameraEntity - Updated edit.js to use the CameraEntities (with button to preview the camera)
This commit is contained in:
parent
022a83528b
commit
d7279e4c88
10 changed files with 143 additions and 4 deletions
|
@ -155,6 +155,7 @@ var toolBar = (function() {
|
|||
newWebButton,
|
||||
newZoneButton,
|
||||
newPolyVoxButton,
|
||||
newCameraButton,
|
||||
browseMarketplaceButton;
|
||||
|
||||
function initialize() {
|
||||
|
@ -299,6 +300,20 @@ var toolBar = (function() {
|
|||
visible: false
|
||||
});
|
||||
|
||||
newCameraButton = toolBar.addTool({
|
||||
imageURL: toolIconUrl + "polyvox.svg",
|
||||
subImage: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 256,
|
||||
height: 256
|
||||
},
|
||||
width: toolWidth,
|
||||
height: toolHeight,
|
||||
alpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
that.setActive(false);
|
||||
}
|
||||
|
||||
|
@ -345,6 +360,7 @@ var toolBar = (function() {
|
|||
toolBar.showTool(newWebButton, doShow);
|
||||
toolBar.showTool(newZoneButton, doShow);
|
||||
toolBar.showTool(newPolyVoxButton, doShow);
|
||||
toolBar.showTool(newCameraButton, doShow);
|
||||
};
|
||||
|
||||
var RESIZE_INTERVAL = 50;
|
||||
|
@ -601,6 +617,13 @@ var toolBar = (function() {
|
|||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
if (newCameraButton === toolBar.clicked(clickedOverlay)) {
|
||||
createNewEntity({
|
||||
type: "Camera"
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1187,6 +1187,19 @@ void Application::paintGL() {
|
|||
glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
|
||||
}
|
||||
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
|
||||
} else if (_myCamera.getMode() == CAMERA_MODE_CAMERA_ENTITY) {
|
||||
EntityItemPointer cameraEntity = _myCamera.getCameraEntityPointer();
|
||||
if (cameraEntity != nullptr) {
|
||||
if (isHMDMode()) {
|
||||
glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix());
|
||||
_myCamera.setPosition(cameraEntity->getPosition() + hmdOffset);
|
||||
glm::quat hmdRotation = extractRotation(myAvatar->getHMDSensorMatrix());
|
||||
_myCamera.setRotation(cameraEntity->getRotation() * hmdRotation);
|
||||
} else {
|
||||
_myCamera.setPosition(cameraEntity->getPosition());
|
||||
_myCamera.setRotation(cameraEntity->getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Update camera position
|
||||
if (!isHMDMode()) {
|
||||
|
@ -2640,8 +2653,8 @@ void Application::cycleCamera() {
|
|||
menu->setIsOptionChecked(MenuOption::ThirdPerson, false);
|
||||
menu->setIsOptionChecked(MenuOption::FullscreenMirror, true);
|
||||
|
||||
} else if (menu->isOptionChecked(MenuOption::IndependentMode)) {
|
||||
// do nothing if in independe mode
|
||||
} else if (menu->isOptionChecked(MenuOption::IndependentMode) || menu->isOptionChecked(MenuOption::CameraEntityMode)) {
|
||||
// do nothing if in independent or camera entity modes
|
||||
return;
|
||||
}
|
||||
cameraMenuChanged(); // handle the menu change
|
||||
|
@ -2668,6 +2681,10 @@ void Application::cameraMenuChanged() {
|
|||
if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
|
||||
_myCamera.setMode(CAMERA_MODE_INDEPENDENT);
|
||||
}
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::CameraEntityMode)) {
|
||||
if (_myCamera.getMode() != CAMERA_MODE_CAMERA_ENTITY) {
|
||||
_myCamera.setMode(CAMERA_MODE_CAMERA_ENTITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ CameraMode stringToMode(const QString& mode) {
|
|||
return CAMERA_MODE_MIRROR;
|
||||
} else if (mode == "independent") {
|
||||
return CAMERA_MODE_INDEPENDENT;
|
||||
} else if (mode == "camera entity") {
|
||||
return CAMERA_MODE_CAMERA_ENTITY;
|
||||
}
|
||||
return CAMERA_MODE_NULL;
|
||||
}
|
||||
|
@ -41,6 +43,8 @@ QString modeToString(CameraMode mode) {
|
|||
return "mirror";
|
||||
} else if (mode == CAMERA_MODE_INDEPENDENT) {
|
||||
return "independent";
|
||||
} else if (mode == CAMERA_MODE_CAMERA_ENTITY) {
|
||||
return "camera entity";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
@ -94,6 +98,26 @@ void Camera::setMode(CameraMode mode) {
|
|||
emit modeUpdated(modeToString(mode));
|
||||
}
|
||||
|
||||
QUuid Camera::getCameraEntity() const {
|
||||
if (_cameraEntity != nullptr) {
|
||||
return _cameraEntity->getID();
|
||||
}
|
||||
return QUuid();
|
||||
};
|
||||
|
||||
void Camera::setCameraEntity(QUuid cameraEntityID) {
|
||||
EntityItemPointer entity = qApp->getEntities()->getTree()->findEntityByID(cameraEntityID);
|
||||
if (entity == nullptr) {
|
||||
qDebug() << "entity pointer not found";
|
||||
return;
|
||||
}
|
||||
if (entity->getType() != EntityTypes::Camera) {
|
||||
qDebug() << "entity type is not camera";
|
||||
return;
|
||||
}
|
||||
_cameraEntity = entity;
|
||||
}
|
||||
|
||||
void Camera::setProjection(const glm::mat4& projection) {
|
||||
_projection = projection;
|
||||
}
|
||||
|
@ -118,6 +142,9 @@ void Camera::setModeString(const QString& mode) {
|
|||
case CAMERA_MODE_INDEPENDENT:
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::IndependentMode, true);
|
||||
break;
|
||||
case CAMERA_MODE_CAMERA_ENTITY:
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::CameraEntityMode, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ enum CameraMode
|
|||
CAMERA_MODE_FIRST_PERSON,
|
||||
CAMERA_MODE_MIRROR,
|
||||
CAMERA_MODE_INDEPENDENT,
|
||||
CAMERA_MODE_CAMERA_ENTITY,
|
||||
NUM_CAMERA_MODES
|
||||
};
|
||||
|
||||
|
@ -36,6 +37,7 @@ class Camera : public QObject {
|
|||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||
Q_PROPERTY(glm::quat orientation READ getOrientation WRITE setOrientation)
|
||||
Q_PROPERTY(QString mode READ getModeString WRITE setModeString)
|
||||
Q_PROPERTY(QUuid cameraEntity READ getCameraEntity WRITE setCameraEntity)
|
||||
public:
|
||||
Camera();
|
||||
|
||||
|
@ -49,6 +51,8 @@ public:
|
|||
void loadViewFrustum(ViewFrustum& frustum) const;
|
||||
ViewFrustum toViewFrustum() const;
|
||||
|
||||
EntityItemPointer getCameraEntityPointer() const { return _cameraEntity; }
|
||||
|
||||
public slots:
|
||||
QString getModeString() const;
|
||||
void setModeString(const QString& mode);
|
||||
|
@ -68,6 +72,9 @@ public slots:
|
|||
const glm::mat4& getProjection() const { return _projection; }
|
||||
void setProjection(const glm::mat4& projection);
|
||||
|
||||
QUuid getCameraEntity() const;
|
||||
void setCameraEntity(QUuid cameraEntityID);
|
||||
|
||||
PickRay computePickRay(float x, float y);
|
||||
|
||||
// These only work on independent cameras
|
||||
|
@ -97,6 +104,7 @@ private:
|
|||
glm::quat _rotation;
|
||||
bool _isKeepLookingAt{ false };
|
||||
glm::vec3 _lookingAt;
|
||||
EntityItemPointer _cameraEntity;
|
||||
};
|
||||
|
||||
#endif // hifi_Camera_h
|
||||
|
|
|
@ -279,6 +279,9 @@ Menu::Menu() {
|
|||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(cameraModeMenu,
|
||||
MenuOption::IndependentMode, 0,
|
||||
false, qApp, SLOT(cameraMenuChanged())));
|
||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(cameraModeMenu,
|
||||
MenuOption::CameraEntityMode, 0,
|
||||
false, qApp, SLOT(cameraMenuChanged())));
|
||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(cameraModeMenu,
|
||||
MenuOption::FullscreenMirror, 0, // QML Qt::Key_H,
|
||||
false, qApp, SLOT(cameraMenuChanged())));
|
||||
|
|
|
@ -157,6 +157,7 @@ namespace MenuOption {
|
|||
const QString Bookmarks = "Bookmarks";
|
||||
const QString CachesSize = "RAM Caches Size";
|
||||
const QString CalibrateCamera = "Calibrate Camera";
|
||||
const QString CameraEntityMode = "Camera Entity";
|
||||
const QString CenterPlayerInView = "Center Player In View";
|
||||
const QString Chat = "Chat...";
|
||||
const QString Collisions = "Collisions";
|
||||
|
|
30
libraries/entities/src/CameraEntityItem.cpp
Normal file
30
libraries/entities/src/CameraEntityItem.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// CameraEntityItem.cpp
|
||||
// libraries/entities/src
|
||||
//
|
||||
// Created by Thijs Wenker on 11/4/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 "EntitiesLogging.h"
|
||||
#include "EntityItemID.h"
|
||||
#include "EntityItemProperties.h"
|
||||
#include "CameraEntityItem.h"
|
||||
|
||||
|
||||
EntityItemPointer CameraEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
EntityItemPointer result { new CameraEntityItem(entityID, properties) };
|
||||
return result;
|
||||
}
|
||||
|
||||
// our non-pure virtual subclass for now...
|
||||
CameraEntityItem::CameraEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
EntityItem(entityItemID)
|
||||
{
|
||||
_type = EntityTypes::Camera;
|
||||
|
||||
setProperties(properties);
|
||||
}
|
27
libraries/entities/src/CameraEntityItem.h
Normal file
27
libraries/entities/src/CameraEntityItem.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// CameraEntityItem.h
|
||||
// libraries/entities/src
|
||||
//
|
||||
// Created by Thijs Wenker on 11/4/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_CameraEntityItem_h
|
||||
#define hifi_CameraEntityItem_h
|
||||
|
||||
#include "EntityItem.h"
|
||||
|
||||
class CameraEntityItem : public EntityItem {
|
||||
public:
|
||||
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
CameraEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||
|
||||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
};
|
||||
|
||||
#endif // hifi_CameraEntityItem_h
|
|
@ -29,6 +29,7 @@
|
|||
#include "LineEntityItem.h"
|
||||
#include "PolyVoxEntityItem.h"
|
||||
#include "PolyLineEntityItem.h"
|
||||
#include "CameraEntityItem.h"
|
||||
|
||||
QMap<EntityTypes::EntityType, QString> EntityTypes::_typeToNameMap;
|
||||
QMap<QString, EntityTypes::EntityType> EntityTypes::_nameToTypeMap;
|
||||
|
@ -48,7 +49,8 @@ REGISTER_ENTITY_TYPE(ParticleEffect)
|
|||
REGISTER_ENTITY_TYPE(Zone)
|
||||
REGISTER_ENTITY_TYPE(Line)
|
||||
REGISTER_ENTITY_TYPE(PolyVox)
|
||||
REGISTER_ENTITY_TYPE(PolyLine);
|
||||
REGISTER_ENTITY_TYPE(PolyLine)
|
||||
REGISTER_ENTITY_TYPE(Camera);
|
||||
|
||||
const QString& EntityTypes::getEntityTypeName(EntityType entityType) {
|
||||
QMap<EntityType, QString>::iterator matchedTypeName = _typeToNameMap.find(entityType);
|
||||
|
|
|
@ -48,7 +48,8 @@ public:
|
|||
Line,
|
||||
PolyVox,
|
||||
PolyLine,
|
||||
LAST = PolyLine
|
||||
Camera,
|
||||
LAST = Camera
|
||||
} EntityType;
|
||||
|
||||
static const QString& getEntityTypeName(EntityType entityType);
|
||||
|
|
Loading…
Reference in a new issue