mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 09:33:45 +02:00
leverage Camera object for scripting, remove sep interface
This commit is contained in:
parent
957705998f
commit
790aa848ae
4 changed files with 46 additions and 81 deletions
|
@ -177,7 +177,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_packetsPerSecond(0),
|
||||
_bytesPerSecond(0),
|
||||
_nodeBoundsDisplay(this),
|
||||
_cameraScriptableObject(&_myCamera, &_viewFrustum),
|
||||
_previousScriptLocation(),
|
||||
_applicationOverlay(),
|
||||
_runningScriptsWidget(NULL),
|
||||
|
@ -1304,7 +1303,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
// nobody handled this - make it an action event on the _window object
|
||||
HFActionEvent actionEvent(HFActionEvent::startType(),
|
||||
_cameraScriptableObject.computePickRay(event->x(), event->y()));
|
||||
_myCamera.computePickRay(event->x(), event->y()));
|
||||
sendEvent(this, &actionEvent);
|
||||
|
||||
} else if (event->button() == Qt::RightButton) {
|
||||
|
@ -1339,7 +1338,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
// fire an action end event
|
||||
HFActionEvent actionEvent(HFActionEvent::endType(),
|
||||
_cameraScriptableObject.computePickRay(event->x(), event->y()));
|
||||
_myCamera.computePickRay(event->x(), event->y()));
|
||||
sendEvent(this, &actionEvent);
|
||||
}
|
||||
}
|
||||
|
@ -3850,7 +3849,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features
|
||||
scriptEngine->setAvatarHashMap(&_avatarManager, "AvatarList");
|
||||
|
||||
scriptEngine->registerGlobalObject("Camera", &_cameraScriptableObject);
|
||||
scriptEngine->registerGlobalObject("Camera", &_myCamera);
|
||||
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||
scriptEngine->registerGlobalObject("SpeechRecognizer", Menu::getInstance()->getSpeechRecognizer());
|
||||
|
|
|
@ -597,7 +597,6 @@ private:
|
|||
std::vector<VoxelFade> _voxelFades;
|
||||
QReadWriteLock _voxelFadesLock;
|
||||
ControllerScriptingInterface _controllerScriptingInterface;
|
||||
CameraScriptableObject _cameraScriptableObject;
|
||||
QPointer<LogDialog> _logDialog;
|
||||
QPointer<SnapshotShareDialog> _snapshotShareDialog;
|
||||
|
||||
|
|
|
@ -72,9 +72,9 @@ float Camera::getFarClip() const {
|
|||
: std::numeric_limits<int16_t>::max() - 1;
|
||||
}
|
||||
|
||||
void Camera::setMode(CameraMode m) {
|
||||
_mode = m;
|
||||
emit modeUpdated(m);
|
||||
void Camera::setMode(CameraMode mode) {
|
||||
_mode = mode;
|
||||
emit modeUpdated(modeToString(mode));
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,57 +94,45 @@ void Camera::setFarClip(float f) {
|
|||
_farClip = f;
|
||||
}
|
||||
|
||||
CameraScriptableObject::CameraScriptableObject(Camera* camera, ViewFrustum* viewFrustum) :
|
||||
_camera(camera), _viewFrustum(viewFrustum)
|
||||
{
|
||||
connect(_camera, &Camera::modeUpdated, this, &CameraScriptableObject::onModeUpdated);
|
||||
}
|
||||
|
||||
PickRay CameraScriptableObject::computePickRay(float x, float y) {
|
||||
PickRay Camera::computePickRay(float x, float y) {
|
||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||
PickRay result;
|
||||
if (OculusManager::isConnected()) {
|
||||
result.origin = _camera->getPosition();
|
||||
result.origin = getPosition();
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||
} else {
|
||||
_viewFrustum->computePickRay(x / screenWidth, y / screenHeight, result.origin, result.direction);
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(x / screenWidth, y / screenHeight,
|
||||
result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString CameraScriptableObject::getMode() const {
|
||||
return modeToString(_camera->getMode());
|
||||
}
|
||||
|
||||
void CameraScriptableObject::setMode(const QString& mode) {
|
||||
CameraMode currentMode = _camera->getMode();
|
||||
CameraMode targetMode = currentMode;
|
||||
if (mode == "third person") {
|
||||
targetMode = CAMERA_MODE_THIRD_PERSON;
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, false);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
} else if (mode == "first person") {
|
||||
targetMode = CAMERA_MODE_FIRST_PERSON;
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, false);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, true);
|
||||
} else if (mode == "mirror") {
|
||||
targetMode = CAMERA_MODE_MIRROR;
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, true);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
} else if (mode == "independent") {
|
||||
targetMode = CAMERA_MODE_INDEPENDENT;
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, false);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
void Camera::setModeString(const QString& mode) {
|
||||
CameraMode targetMode = stringToMode(mode);
|
||||
|
||||
switch (targetMode) {
|
||||
case CAMERA_MODE_THIRD_PERSON:
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, false);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
break;
|
||||
case CAMERA_MODE_MIRROR:
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, true);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
break;
|
||||
case CAMERA_MODE_INDEPENDENT:
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, false);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (currentMode != targetMode) {
|
||||
_camera->setMode(targetMode);
|
||||
|
||||
if (_mode != targetMode) {
|
||||
setMode(targetMode);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraScriptableObject::onModeUpdated(CameraMode m) {
|
||||
emit modeUpdated(modeToString(m));
|
||||
QString Camera::getModeString() const {
|
||||
return modeToString(_mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ public:
|
|||
|
||||
void update( float deltaTime );
|
||||
|
||||
void setPosition(const glm::vec3& p) { _position = p; }
|
||||
void setRotation(const glm::quat& rotation) { _rotation = rotation; };
|
||||
void setHmdPosition(const glm::vec3& hmdPosition) { _hmdPosition = hmdPosition; }
|
||||
void setHmdRotation(const glm::quat& hmdRotation) { _hmdRotation = hmdRotation; };
|
||||
|
@ -68,12 +67,20 @@ public:
|
|||
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
|
||||
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
|
||||
float getScale() const { return _scale; }
|
||||
|
||||
signals:
|
||||
void modeUpdated(CameraMode newMode);
|
||||
|
||||
private:
|
||||
public slots:
|
||||
QString getModeString() const;
|
||||
void setModeString(const QString& mode);
|
||||
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
|
||||
void setOrientation(const glm::quat& orientation) { setRotation(orientation); }
|
||||
glm::quat getOrientation() const { return getRotation(); }
|
||||
|
||||
PickRay computePickRay(float x, float y);
|
||||
signals:
|
||||
void modeUpdated(const QString& newMode);
|
||||
|
||||
private:
|
||||
CameraMode _mode;
|
||||
glm::vec3 _position;
|
||||
float _fieldOfView; // degrees
|
||||
|
@ -90,32 +97,4 @@ private:
|
|||
float _scale;
|
||||
};
|
||||
|
||||
|
||||
class CameraScriptableObject : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CameraScriptableObject(Camera* camera, ViewFrustum* viewFrustum);
|
||||
|
||||
public slots:
|
||||
QString getMode() const;
|
||||
void setMode(const QString& mode);
|
||||
void setPosition(const glm::vec3& value) { _camera->setPosition(value);}
|
||||
|
||||
glm::vec3 getPosition() const { return _camera->getPosition(); }
|
||||
|
||||
void setOrientation(const glm::quat& value) { _camera->setRotation(value); }
|
||||
glm::quat getOrientation() const { return _camera->getRotation(); }
|
||||
|
||||
PickRay computePickRay(float x, float y);
|
||||
|
||||
signals:
|
||||
void modeUpdated(const QString& newMode);
|
||||
|
||||
private slots:
|
||||
void onModeUpdated(CameraMode m);
|
||||
|
||||
private:
|
||||
Camera* _camera;
|
||||
ViewFrustum* _viewFrustum;
|
||||
};
|
||||
#endif // hifi_Camera_h
|
||||
|
|
Loading…
Reference in a new issue