35 _movedLastFrame(false),
41 _velocity(0.0f, 0.0f, 0.0f),
42 _acceleration(0, 0, 0),
52 _fogColorIsBack(true),
53 _viewport(0, 0, 640, 480),
56 _onCamUpdateCB(nullptr)
123 SLfloat dtS = elapsedTimeMS * 0.001f;
193 SLVec3f farRT, farRB, farLT, farLB;
204 SLfloat c = std::min(l, r) * 0.05f;
275 SLfloat cP = std::min(lP, rP) * 0.05f;
376 minV.
set(FLT_MAX, FLT_MAX, FLT_MAX);
377 maxV.
set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
382 if (i.x < minV.
x) minV.
x = i.x;
383 if (i.x > maxV.
x) maxV.
x = i.x;
384 if (i.y < minV.
y) minV.
y = i.y;
385 if (i.y > maxV.
y) maxV.
y = i.y;
386 if (i.z < minV.
z) minV.
z = i.z;
387 if (i.z > maxV.
z) maxV.
z = i.z;
412 frustumSize.
y = 2.f * distance * std::tan(
_fovV * 0.5f *
DEG2RAD);
436 default:
return "Unknown";
474 SLint fbW2 = fbW >> 1;
475 SLint fbH2 = fbH >> 1;
476 SLint fbH4 = fbH2 >> 1;
483 stateGL->
viewport(0, 0, fbOcW2, fbOcH);
485 stateGL->
viewport(fbOcW2, 0, fbOcW2, fbOcH);
492 stateGL->
viewport(fbW2, 0, fbW2, fbH);
497 stateGL->
viewport(0, fbH4, fbW2, fbH2);
499 stateGL->
viewport(fbW2, fbH4, fbW2, fbH2);
502 stateGL->
viewport(fbX, fbY, fbW, fbH);
525 SLfloat top, bottom, left, right, d;
659 enuHorizon.
cross(normalEnuXYPlane, normalCamXYPlane);
665 SLVec3f cHorizon = cRenu * enuHorizon;
669 float horizAngDEG = atan2f((
float)cHorizon.
y, (
float)cHorizon.
x) *
RAD2DEG;
673 SLMat3f rot(horizAngDEG, 0, 0, 1);
674 enuOffsetPix = rot * cOffsetPix;
684 float yawOffsetRAD = atanf((
float)enuOffsetPix.
x / f);
685 float pitchOffsetRAD = atanf((
float)enuOffsetPix.
y / f);
702 float yawOffsetRAD = atanf((
float)enuOffsetPix.
x / f);
760 if (rotYawOffsetDEG > 180)
761 rotYawOffsetDEG -= 360;
762 wyRenucorr.
rotation(rotYawOffsetDEG, 0, 0, 1);
933 SLfloat rotX = 0.0f, rotY = 0.0f, rotZ = 0.0f;
934 rotation.toMat4().toEulerAnglesZYX(rotZ, rotY, rotX);
947 rotation.inverted().toMat4() * trackingPos * vm);
960 vm.
lookAt(&EYE, &LA, &LU, &LR);
979 this->
lookAt(lookAt, upDir);
993 default:
return "unknown";
1069 rot.
rotate(-dY, rightVS);
1104 if (lastAxisVS !=
SLVec3f::ZERO) axisVS = (axisVS + lastAxisVS) / 2.0f;
1114 if (angle > dMouseLenght) angle = dMouseLenght * 0.2f;
1129 lastAxisVS = axisVS;
1140 rot.
rotate(-dY, rightVS);
1143 lookAt(positionVS + forwardVS);
1153 rot.
rotate(-dY, rightVS);
1309 d1[cnt % 4] = delta1;
1310 d2[cnt % 4] = delta2;
1311 SLVec2f avgDelta1(d1[0].x + d1[1].x + d1[2].x + d1[3].x,
1312 d1[0].y + d1[1].y + d1[2].y + d1[3].y);
1313 SLVec2f avgDelta2(d2[0].x + d2[1].x + d2[2].x + d2[3].x,
1314 d2[0].y + d2[1].y + d2[2].y + d2[3].y);
1331 SLVec2f nowCenter((now1 + now2) * 0.5f);
1337 SLVec2f delta(nowCenter - oldCenter);
1367 offsetENU.
y += delta.
y;
1389 delta *= spaceH * 2;
1463 default:
return false;
1534 SLVec3f TL = EYE - hw * LR + hh * LU + pixel / 2 * LR - pixel / 2 * LU;
1538 ray->
origin.
set(TL + pixel * (x * LR - y * LU));
1556 SLVec3f TL = C - hw * LR + hh * LU + pixel * 0.5f * (LR - LU);
1557 SLVec3f dir = TL + pixel * (x * LR - y * LU);
1607 SLVec4f eyePos = viewMatrix * worldPos;
1608 SLVec4f clipPos = projectionMatrix * eyePos;
1610 SLVec4f ndcPos = clipPos / clipPos.
w;
1631 if (distance < -aabb->radiusWS())
1649 std::ostringstream ss;
1651 ss <<
"FOV: " <<
_fovV << endl;
1652 ss <<
"ClipNear: " <<
_clipNear << endl;
1653 ss <<
"ClipFar: " <<
_clipFar << endl;
1678 vec.
z = sqrt(1.0f - d * d);
1690 assert(program &&
"SLCamera::passToUniforms: No shader program set!");
#define SL_WARN_MSG(message)
#define SL_EXIT_MSG(message)
Mobile device location class declaration.
Mobile device rotation class declaration.
SLCamAnim
Enumeration for available camera animation types.
@ CA_turntableYUp
Orbiting around central object w. turntable rotation around y & right axis.
@ CA_walkingYUp
Walk translation with AWSD and look around rotation around y & right axis.
@ CA_off
No camera animation.
@ CA_deviceRotLocYUp
The device rotation controls the camera rotation and the GPS controls the Camera Translation.
@ CA_trackball
Orbiting around central object w. one rotation around one axis.
@ CA_deviceRotYUp
The device rotation controls the camera rotation.
@ CA_turntableZUp
Orbiting around central object w. turntable rotation around z & right axis.
@ CA_walkingZUp
Walk translation with AWSD and look around rotation around z & right axis.
SLProjType
Enumeration for different camera projections.
@ P_monoPerspective
standard mono pinhole perspective projection
@ P_stereoSideBySideP
side-by-side proportional for mirror stereoscopes
@ P_monoIntrinsic
standard mono pinhole perspective projection from intrinsic calibration
@ P_stereoPixelByPixel
checkerboard pattern (DLP3D)
@ P_stereoColumnByColumn
column-by-column
@ P_stereoColorRG
color masking for red-green anaglyphs
@ P_stereoSideBySideD
side-by-side distorted for Oculus Rift like glasses
@ P_stereoSideBySide
side-by-side
@ P_stereoColorYB
color masking for yellow-blue anaglyphs (ColorCode 3D)
@ P_stereoLineByLine
line-by-line
@ P_stereoColorRB
color masking for red-blue anaglyphs
@ P_stereoColorRC
color masking for red-cyan anaglyphs
@ P_monoOrthographic
standard mono orthographic projection
SLMouseButton
Mouse button codes.
SLEyeType
Enumeration for stereo eye type used for camera projection.
SLKey
Keyboard key codes enumeration.
SLMat4< SLfloat > SLMat4f
SLVec2< SLfloat > SLVec2f
vector< SLVec3f > SLVVec3f
SLVec3< SLfloat > SLVec3f
SLVec4< SLfloat > SLCol4f
Defines an axis aligned bounding box.
void fromOStoWS(const SLVec3f &minOS, const SLVec3f &maxOS, const SLMat4f &wm)
Recalculate min and max after transformation in world coords.
void isVisible(SLbool visible)
void sqrViewDist(SLfloat sqrVD)
const SLRectf & rect() const
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
void renderInScene(const SLMat4f &wm, const SLVec3f <, const SLVec3f &LB, const SLVec3f &RT, const SLVec3f &RB)
Draws the background as a quad on the far clipping plane.
SLfloat _drag
simple constant drag that affects velocity
SLRaySamples2D _lensSamples
sample points for lens sampling (DOF)
SLFogMode _fogMode
0=LINEAR, 1=EXP, 2=EXP2
SLbool onTouch2Down(SLint x1, SLint y1, SLint x2, SLint y2) override
SLDeviceLocation * _devLoc
SLfloat _fx
horizontal focal length
SLBackground _background
Colors or texture displayed in the background.
SLbool onKeyRelease(SLKey key, SLKey mod) override
SLfloat _unitScaling
indicate what the current unit scale is
SLfloat _stereoEyeSeparation
eye separation for stereo mode
SLfloat _cy
sensor center in y direction
void buildAABB(SLAABBox &aabb, const SLMat4f &wmNode)
void setViewport(SLSceneView *sv, SLEyeType eye)
Sets the viewport transform depending on the projection.
SLfloat _cx
sensor center in x direction
static SLProjType currentProjection
SLstring toString() const
SLCamera::to_string returns important camera parameter as a string.
static SLint currentDevRotation
SLfloat _fovV
Current vertical field of view (view angle) in degrees.
SLbool onMouseUp(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever the mouse button is released.
SLRecti _viewport
framebuffer rectangle
SLfloat fovV() const
Vertical field of view.
SLfloat fovH() const
Horizontal field of view.
SLchar _keyStates[256]
Stores for all movement keys whether they are pressed.
SLfloat _clipNear
Dist. to the near clipping plane.
SLVec2f projectWorldToNDC(const SLVec4f &worldPos) const
Project a world position into screen coordinates.
SLstring projTypeStr() const
SLVec3f trackballVec(SLint x, SLint y) const
Returns a vector from the window center to a virtual trackball at [x,y].
SLCamera(const SLstring &name="Camera")
Construct a new SLCamera::SLCamera object.
SLfloat _lensDiameter
Lens diameter.
SLfloat _maxSpeed
maximum speed in m/s, with high drag values this speed might not be achievable at all
SLfloat _fovInit
Initial vertical field of view (view angle) in degrees.
void passToUniforms(SLGLProgram *program)
Pass camera parameters to the uniform variables.
SLbool _fogIsOn
Flag if fog blending is enabled.
SLbool onMouseMove(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever the mouse is moved.
SLfloat _fogDensity
Fog density for exponential modes.
SLVec3f focalPointWS() const
SLGLVertexArrayExt _vao
OpenGL Vertex array for rendering.
SLfloat _clipFar
Dist. to the far clipping plane.
void setView(SLSceneView *sv, SLEyeType eye)
SLVec2f _oldTouchPos1
Old mouse/touch position in pixels.
SLPlane _plane[6]
6 frustum planes (l, r, t, b, n, f)
SLfloat _fogStart
Fog start distance for linear mode.
SLfloat focalDistScrH() const
void eyeToPixelRay(SLfloat x, SLfloat y, SLRay *ray)
eyeToPixelRay returns the a ray from the eye to the center of a pixel.
SLfloat _focalDist
distance to lookAt point on the focal plane from lens
SLfloat _trackballSize
Size of trackball (0.8 = 80% of window size)
SLDeviceRotation * _devRot
static SLstring projTypeToStr(SLProjType pt)
Returns the projection type as string.
SLVec3f _acceleration
current acceleration vector
SLRectf _deselectRect
Mouse deselection rectangle. See SLMesh::handleRectangleSelection.
SLVec2f _oldTouchPos2
Old 2nd finger touch position in pixels.
SLfloat _moveAccel
move acceleration
SLstring animationStr() const
SLCamera::animationStr() returns the animation enum as string.
void statsRec(SLNodeStats &stats) override
SLCamera::statsRec updates the statistic parameters.
SLVec2f frustumSizeAtDistance(SLfloat distance)
Calculate and return frustum size at distance to camera center.
SLCamAnim _camAnim
did the camera updateRec in the last frame?
SLint _xOffsetPix
parameter for manual finger rotation and translation
SLbool _fogColorIsBack
fog color blended to the final color
SLVec3f _trackballStartVec
Trackball vector at mouse down.
virtual SLbool camUpdate(SLSceneView *sv, SLfloat timeMS)
void setFrustumPlanes()
SLCamera::setFrustumPlanes set the 6 plane from the view frustum.
SLfloat focalDistScrW() const
SLfloat _viewportRatio
viewport.width / viewport.height = screen ratio
function< void(SLSceneView *sv)> _onCamUpdateCB
SLbool isInFrustum(SLAABBox *aabb)
SLCamera::isInFrustum does a simple and fast frustum culling test for AABBs.
SLCol4f _fogColor
fog color blended to the final color
SLbool onTouch2Up(SLint x1, SLint y1, SLint x2, SLint y2) override
void updateEnuCorrRenu(SLSceneView *sv, const SLMat3f &enuRc, float &f, SLVec3f &enuOffsetPix)
Calculate and apply correction from finger x-y-rotation.
SLint _stereoEye
-1=left, 0=center, 1=right
void drawMesh(SLSceneView *sv) override
SLCamera::drawMeshes draws the cameras frustum lines.
SLbool onMouseDown(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever a mouse button gets pressed.
void lookFrom(const SLVec3f &fromDir, const SLVec3f &upDir=SLVec3f::AXISY)
Sets the view to look from a direction towards the current focal point.
void setProjection(SLSceneView *sv, SLEyeType eye)
SLMat3f _stereoColorFilter
color filter matrix for anaglyphling is to adjust movement and stereo rendering correctly
static SLfloat currentFOV
SLfloat _brakeAccel
brake acceleration
SLbool onTouch2Move(SLint x1, SLint y1, SLint x2, SLint y2) override
SLfloat _fy
vertical focal length
static SLCamAnim currentAnimation
SLbool onKeyPress(SLKey key, SLKey mod) override
const SLMat4f & updateAndGetVM() const
SLVec3f _velocity
current velocity vector
SLProjType _projType
Projection type.
void UVWFrame(SLVec3f &EYE, SLVec3f &U, SLVec3f &V, SLVec3f &W)
SLbool onMouseWheel(SLint delta, SLKey mod) override
SLRectf _selectRect
Mouse selection rectangle. See SLMesh::handleRectangleSelection.
void calcMinMax(SLVec3f &minV, SLVec3f &maxV) const
SLfloat _fogEnd
Fog end distance for linear mode.
SLVec3d defaultENU() const
void offsetENU(SLVec3d offsetENU)
void isUsed(SLbool isUsed)
Setter that turns on the device rotation sensor.
SLVec3d originENU() const
void locMaxDistanceM(SLfloat maxDist)
void offsetMode(SLLocOffsetMode lom)
void hasOrigin(SLbool hasOL)
void offsetMode(SLRotOffsetMode rom)
SLMat3f rotationAveraged()
void zeroYawAtStart(SLbool zeroYaw)
void isUsed(SLbool isUsed)
Setter that turns on the device rotation sensor.
SLfloat startYawRAD() const
SLfloat _keyboardDeltaPos
Delta dist. for keyboard translation.
SLfloat _mouseRotationFactor
Mouse rotation sensibility.
static void viewToFrustumPlanes(SLPlane *planes, const SLMat4f &projectionMat, const SLMat4f &viewMat)
const SLVec3f & viewAdjust(SLEyeType eye)
const SLQuat4f & orientation(SLEyeType eye)
const SLVec3f & position(SLEyeType eye)
const SLMat4f & projection(SLEyeType eye)
Encapsulation of an OpenGL shader program object.
SLint uniform4fv(const SLchar *name, SLsizei count, const SLfloat *value) const
Passes 4 float values py pointer to the uniform variable "name".
SLint uniformMatrix3fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 3x3 float matrix values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Static container for standard shader programs.
Singleton class holding all OpenGL states.
void viewport(SLint x, SLint y, SLsizei width, SLsizei height)
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLMat4f viewMatrix
matrix for the active cameras view transform
void colorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
SLMat4f projectionMatrix
matrix for projection transform
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
void rotation(const T angleDEG, const SLVec3< T > &axis)
Sets the rotation components
SLMat3< T > transposed() const
Returns the transposed of the matrix and leaves the itself unchanged.
void setMatrix(const SLMat3 &A)
SLVec3< T > translation() const
void lookAt(T EyeX, T EyeY, T EyeZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
Defines the a view matrix as the corresponding gluLookAt function.
void setTranslation(const SLVec3< T > &translation)
Set vector as submatrix describing the translational part.
void setRotation(const SLMat3< T > &rotation)
Set 3x3 submatrix describing the rotational part.
void perspectiveCenteredPP(T w, T h, T fx, T fy, T cx, T cy, T n, T f)
Defines a projection matrix for a calibrated camera, the principle point has to be centered (from int...
void setMatrix(const SLMat4 &A)
Set matrix by other 4x4 matrix.
void ortho(T l, T r, T b, T t, T n, T f)
Defines a orthographic projection matrix with a field of view angle.
void rotate(T degAng, T axisx, T axisy, T axisz)
SLstring toString() const
SLVec3< T > multVec(SLVec3< T > v) const
void perspective(T fov, T aspect, T n, T f)
Defines a perspective projection matrix with a field of view angle.
void frustum(T l, T r, T b, T t, T n, T f)
Defines a view frustum projection matrix equivalent to glFrustum.
void translate(T tx, T ty, T tz=0)
SLNode represents a node in a hierarchical scene graph.
void rotation(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
SLVec3f forwardOS() const
virtual void needUpdate()
const SLMat4f & updateAndGetWM() const
SLMat4f _om
object matrix for local transforms
SLVec3f translationOS() const
bool _castsShadows
flag if meshes of node should cast shadows
virtual void statsRec(SLNodeStats &stats)
const SLMat4f & updateAndGetWMI() const
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
SLMat4f _wm
world matrix for world transform
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Ray class with ray and intersection properties.
SLint hitTriangle
Points to the intersected triangle.
SLVec3f origin
Vector to the origin of ray in WS.
SLRayType type
PRIMARY, REFLECTED, REFRACTED, SHADOW.
SLint srcTriangle
Points to the triangle at ray origin.
SLMesh * hitMesh
Points to the intersected mesh.
SLint depth
Recursion depth for ray tracing.
SLfloat length
length from origin to an intersection
SLNode * hitNode
Points to the intersected node.
SLfloat contrib
Current contribution of ray to color.
SLVec3f hitPoint
Point of intersection.
void setDir(const SLVec3f &Dir)
Setter for the rays direction in world space also setting the inverse direction.
SLfloat y
Pixel position for primary rays.
SLVec3f hitNormal
Surface normal at intersection point.
void samples(SLuint x, SLuint y, SLbool evenlyDistributed=true)
Resets the sample point array by the sqrt of the no. of samples.
void tl(V v)
top-left corner
void set(const T X, const T Y, const T WIDTH, const T HEIGHT)
void skybox(SLSkybox *skybox)
SLNode * singleNodeSelected()
Returns the node if only one is selected. See also SLMesh::selectNodeMesh.
SceneView class represents a dynamic real time 3D view onto the scene.
SLRecti viewportRect() const
void camera(SLCamera *camera)
SLGLOculusFB * oculusFB()
void toPolar(T &r, T &phiRAD)
Calculates polar coords with radius & angle phi in radians (-pi < phi < pi)
void set(const T X, const T Y)
SLVec3 normalized() const
void cross(const SLVec3 &a, const SLVec3 &b)
void set(const T X, const T Y, const T Z)
T dot(const SLVec3 &v) const
std::vector< char > & get(std::string path)
static const float DEG2RAD
static const float RAD2DEG
Struct for scene graph statistics.
SLuint numTriangles
NO. of triangles in mesh.
SLuint numBytes
NO. of bytes allocated.