mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
Merge pull request #5924 from jherico/marge
Support for accessing IPD in scripts
This commit is contained in:
commit
00c32fc7cd
9 changed files with 73 additions and 1 deletions
10
examples/example/hmd/colorCube.fs
Normal file
10
examples/example/hmd/colorCube.fs
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
|
||||
|
||||
specular = _modelNormal.rgb;
|
||||
if (any(lessThan(specular, vec3(0.0)))) {
|
||||
specular = vec3(1.0) + specular;
|
||||
}
|
||||
diffuse = vec3(1.0, 1.0, 1.0);
|
||||
return 1.0;
|
||||
}
|
42
examples/example/hmd/colorCube.js
Normal file
42
examples/example/hmd/colorCube.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
function avatarRelativePosition(position) {
|
||||
return Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, position));
|
||||
}
|
||||
|
||||
ColorCube = function() {};
|
||||
ColorCube.prototype.NAME = "ColorCube";
|
||||
ColorCube.prototype.POSITION = { x: 0, y: 0.5, z: -0.5 };
|
||||
ColorCube.prototype.USER_DATA = { ProceduralEntity: {
|
||||
version: 2, shaderUrl: Script.resolvePath("colorCube.fs"),
|
||||
} };
|
||||
|
||||
// Clear any previous entities within 50 meters
|
||||
ColorCube.prototype.clear = function() {
|
||||
var ids = Entities.findEntities(MyAvatar.position, 50);
|
||||
var that = this;
|
||||
ids.forEach(function(id) {
|
||||
var properties = Entities.getEntityProperties(id);
|
||||
if (properties.name == that.NAME) {
|
||||
Entities.deleteEntity(id);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
ColorCube.prototype.create = function() {
|
||||
var that = this;
|
||||
var size = HMD.ipd;
|
||||
var id = Entities.addEntity({
|
||||
type: "Box",
|
||||
position: avatarRelativePosition(that.POSITION),
|
||||
name: that.NAME,
|
||||
color: that.COLOR,
|
||||
ignoreCollisions: true,
|
||||
collisionsWillMove: false,
|
||||
dimensions: { x: size, y: size, z: size },
|
||||
lifetime: 3600,
|
||||
userData: JSON.stringify(that.USER_DATA)
|
||||
});
|
||||
}
|
||||
|
||||
var colorCube = new ColorCube();
|
||||
colorCube.clear();
|
||||
colorCube.create();
|
|
@ -10,7 +10,7 @@
|
|||
//
|
||||
|
||||
#include "HMDScriptingInterface.h"
|
||||
|
||||
#include "display-plugins/DisplayPlugin.h"
|
||||
#include <avatar/AvatarManager.h>
|
||||
|
||||
HMDScriptingInterface& HMDScriptingInterface::getInstance() {
|
||||
|
@ -53,3 +53,7 @@ QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* conte
|
|||
}
|
||||
return QScriptValue::NullValue;
|
||||
}
|
||||
|
||||
float HMDScriptingInterface::getIPD() const {
|
||||
return Application::getInstance()->getActiveDisplayPlugin()->getIPD();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class HMDScriptingInterface : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(bool magnifier READ getMagnifier)
|
||||
Q_PROPERTY(bool active READ isHMDMode)
|
||||
Q_PROPERTY(float ipd READ getIPD)
|
||||
public:
|
||||
static HMDScriptingInterface& getInstance();
|
||||
|
||||
|
@ -33,6 +34,7 @@ private:
|
|||
HMDScriptingInterface() {};
|
||||
bool getMagnifier() const { return Application::getInstance()->getApplicationCompositor().hasMagnifier(); };
|
||||
bool isHMDMode() const { return Application::getInstance()->isHMDMode(); }
|
||||
float getIPD() const;
|
||||
|
||||
bool getHUDLookAtPosition3D(glm::vec3& result) const;
|
||||
|
||||
|
|
|
@ -121,6 +121,8 @@ public:
|
|||
static const glm::mat4 pose; return pose;
|
||||
}
|
||||
|
||||
virtual float getIPD() const { return 0.0f; }
|
||||
|
||||
virtual void abandonCalibration() {}
|
||||
virtual void resetSensors() {}
|
||||
virtual float devicePixelRatio() { return 1.0; }
|
||||
|
|
|
@ -149,3 +149,11 @@ void OculusBaseDisplayPlugin::deactivate() {
|
|||
void OculusBaseDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
|
||||
++_frameIndex;
|
||||
}
|
||||
|
||||
float OculusBaseDisplayPlugin::getIPD() const {
|
||||
float result = 0.0f;
|
||||
#if (OVR_MAJOR_VERSION >= 6)
|
||||
result = ovr_GetFloat(_hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD);
|
||||
#endif
|
||||
return result;
|
||||
}
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual void resetSensors() override final;
|
||||
virtual glm::mat4 getEyePose(Eye eye) const override final;
|
||||
virtual glm::mat4 getHeadPose() const override final;
|
||||
virtual float getIPD() const override final;
|
||||
|
||||
protected:
|
||||
virtual void preRender() override final;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _modelNormal;
|
||||
in vec3 _color;
|
||||
in vec2 _texCoord0;
|
||||
in vec4 _position;
|
||||
|
|
|
@ -22,6 +22,7 @@ uniform bool Instanced = false;
|
|||
// the interpolated normal
|
||||
|
||||
out vec3 _normal;
|
||||
out vec3 _modelNormal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
out vec4 _position;
|
||||
|
@ -30,6 +31,7 @@ void main(void) {
|
|||
_color = inColor.rgb;
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
_position = inPosition;
|
||||
_modelNormal = inNormal.xyz;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
|
|
Loading…
Reference in a new issue