Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
ec856073
Commit
ec856073
authored
Aug 24, 2011
by
Robert Menzel
Browse files
Merge branch 'master' of
file:///data/git-repository/acgl/libraries/acgl
parents
d3706471
419c57e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/Scene/Camera.hh
View file @
ec856073
...
...
@@ -38,26 +38,26 @@ public:
updateOrientationByLocalCoordinateSystem
();
}
Camera
(
int_t
width
,
int_t
height
,
float
fov
,
float
near
,
float
far
,
const
glm
::
vec3
&
position
,
const
glm
::
vec3
&
target
)
int_t
_
width
,
int_t
_
height
,
float
_
fov
,
float
_
near
,
float
_
far
,
const
glm
::
vec3
&
_
position
,
const
glm
::
vec3
&
_
target
)
:
mRight
(),
mUp
(),
mForward
(),
mWidth
(
width
),
mHeight
(
height
),
mFOV
(
fov
),
mNear
(
near
),
mFar
(
far
),
mWidth
(
_
width
),
mHeight
(
_
height
),
mFOV
(
_
fov
),
mNear
(
_
near
),
mFar
(
_
far
),
mPitch
(
0.0
f
),
mYaw
(
0.0
f
),
mRoll
(
0.0
f
),
mPosition
(
position
),
mTarget
(
target
)
mPosition
(
_
position
),
mTarget
(
_
target
)
{
updateLocalCoordinateSystemByTarget
();
updateOrientationByLocalCoordinateSystem
();
...
...
@@ -80,32 +80,76 @@ public:
}
~
Camera
(
void
)
{}
inline
float
getAspectRatio
()
const
{
return
(
float
)
mWidth
/
(
float
)
mHeight
;
}
inline
const
glm
::
vec3
&
getUpDirection
()
const
{
return
mUp
;
}
inline
const
glm
::
vec3
&
getRightDirection
()
const
{
return
mRight
;
}
inline
const
glm
::
vec3
&
getForwardDirection
()
const
{
return
mForward
;
}
inline
int_t
getWidth
()
const
{
return
mWidth
;
}
inline
int_t
getHeight
()
const
{
return
mHeight
;
}
inline
float
getFOV
()
const
{
return
mFOV
;
}
inline
float
getNear
()
const
{
return
mNear
;
}
inline
float
getFar
()
const
{
return
mFar
;
}
inline
float
getPitch
()
const
{
return
mPitch
;
}
inline
float
getYaw
()
const
{
return
mYaw
;
}
inline
float
getRoll
()
const
{
return
mRoll
;
}
inline
const
glm
::
vec3
&
getPosition
()
const
{
return
mPosition
;
}
inline
const
glm
::
vec3
&
getTarget
()
const
{
return
mTarget
;
}
inline
float
getAspectRatio
(
void
)
const
{
return
(
float
)
mWidth
/
(
float
)
mHeight
;
}
inline
const
glm
::
vec3
&
getUpDirection
(
void
)
const
{
return
mUp
;
}
inline
const
glm
::
vec3
&
getRightDirection
(
void
)
const
{
return
mRight
;
}
inline
const
glm
::
vec3
&
getForwardDirection
(
void
)
const
{
return
mForward
;
}
inline
int_t
getWidth
(
void
)
const
{
return
mWidth
;
}
inline
int_t
getHeight
(
void
)
const
{
return
mHeight
;
}
inline
float
getFOV
(
void
)
const
{
return
mFOV
;
}
inline
float
getNear
(
void
)
const
{
return
mNear
;
}
inline
float
getFar
(
void
)
const
{
return
mFar
;
}
inline
float
getPitch
(
void
)
const
{
return
mPitch
;
}
inline
float
getYaw
(
void
)
const
{
return
mYaw
;
}
inline
float
getRoll
(
void
)
const
{
return
mRoll
;
}
inline
const
glm
::
vec3
&
getPosition
(
void
)
const
{
return
mPosition
;
}
inline
const
glm
::
vec3
&
getTarget
(
void
)
const
{
return
mTarget
;
}
inline
void
setWidth
(
int_t
width
)
{
mWidth
=
width
;
}
inline
void
setHeight
(
int_t
height
)
{
mHeight
=
height
;
}
inline
void
setFOV
(
float
fov
)
{
mFOV
=
fov
;
}
inline
void
setNear
(
float
near
)
{
mNear
=
near
;
}
inline
void
setFar
(
float
far
)
{
mFar
=
far
;
}
inline
void
setPitch
(
float
pitch
)
{
mPitch
=
pitch
;
}
inline
void
setYaw
(
float
yaw
)
{
mYaw
=
yaw
;
}
inline
void
setRoll
(
float
roll
)
{
mRoll
=
roll
;
}
inline
void
setPosition
(
const
glm
::
vec3
&
position
,
bool
moveTarget
=
true
)
{
if
(
moveTarget
)
{
mTarget
+=
position
-
mPosition
;
}
mPosition
=
position
;
}
inline
void
setTarget
(
const
glm
::
vec3
&
target
,
bool
movePosition
=
true
)
{
if
(
movePosition
)
{
mPosition
+=
target
-
mTarget
;
}
mTarget
=
target
;
}
inline
void
setWidth
(
int_t
_width
)
{
mWidth
=
_width
;
}
inline
void
setHeight
(
int_t
_height
)
{
mHeight
=
_height
;
}
inline
void
setFOV
(
float
_fov
)
{
mFOV
=
_fov
;
}
inline
void
setNear
(
float
_near
)
{
mNear
=
_near
;
}
inline
void
setFar
(
float
_far
)
{
mFar
=
_far
;
}
inline
void
setPosition
(
const
glm
::
vec3
&
_position
,
bool
_moveTarget
=
true
)
{
if
(
_moveTarget
)
mTarget
+=
_position
-
mPosition
;
mPosition
=
_position
;
if
(
!
_moveTarget
)
updateLocalCoordinateSystemByTarget
(
mUp
);
}
inline
void
setPosition
(
const
glm
::
vec3
&
_position
,
const
glm
::
vec3
&
_up
,
bool
_moveTarget
=
true
)
{
if
(
_moveTarget
)
mTarget
+=
_position
-
mPosition
;
mPosition
=
_position
;
updateLocalCoordinateSystemByTarget
(
_up
);
}
inline
void
setTarget
(
const
glm
::
vec3
&
_target
,
bool
_movePosition
=
true
)
{
if
(
_movePosition
)
mPosition
+=
_target
-
mTarget
;
mTarget
=
_target
;
if
(
!
_movePosition
)
updateLocalCoordinateSystemByTarget
(
mUp
);
}
inline
void
setPitch
(
float
_pitch
)
{
mPitch
=
_pitch
;
updateLocalCoordinateSystemByOrientation
();
mTarget
=
mPosition
+
glm
::
length
(
mTarget
-
mPosition
)
*
mForward
;
}
inline
void
setYaw
(
float
_yaw
)
{
mYaw
=
_yaw
;
updateLocalCoordinateSystemByOrientation
();
mTarget
=
mPosition
+
glm
::
length
(
mTarget
-
mPosition
)
*
mForward
;
}
inline
void
setRoll
(
float
_roll
)
{
mRoll
=
_roll
;
}
inline
void
setPitchAroundTarget
(
float
pitch
)
{
...
...
@@ -119,16 +163,25 @@ public:
updateLocalCoordinateSystemByOrientation
();
mPosition
=
mTarget
-
glm
::
length
(
mTarget
-
mPosition
)
*
mForward
;
}
inline
void
setOrientation
(
float
_pitch
,
float
_yaw
,
float
_roll
)
{
mPitch
=
_pitch
;
mYaw
=
_yaw
;
mRoll
=
_roll
;
updateLocalCoordinateSystemByOrientation
();
}
glm
::
mat4
getProjectionMatrix
()
const
;
glm
::
mat4
getViewMatrix
()
const
;
glm
::
mat4
getInverseViewMatrix
()
const
;
void
updateLocalCoordinateSystemByTarget
(
const
glm
::
vec3
&
up
=
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
void
updateLocalCoordinateSystemByOrientation
(
bool
moveTarget
=
true
);
void
updateOrientationByLocalCoordinateSystem
();
private:
void
updateLocalCoordinateSystemByTarget
(
const
glm
::
vec3
&
_up
=
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
void
updateLocalCoordinateSystemByOrientation
(
void
);
void
updateOrientationByLocalCoordinateSystem
(
void
);
glm
::
vec3
mRight
;
glm
::
vec3
mUp
;
glm
::
vec3
mForward
;
...
...
src/ACGL/Scene/Camera.cc
View file @
ec856073
...
...
@@ -50,15 +50,15 @@ glm::mat4 Camera::getInverseViewMatrix(void) const
return
mView
;
}
void
Camera
::
updateLocalCoordinateSystemByTarget
(
const
glm
::
vec3
&
up
)
void
Camera
::
updateLocalCoordinateSystemByTarget
(
const
glm
::
vec3
&
_
up
)
{
mForward
=
glm
::
normalize
(
mTarget
-
mPosition
);
mRight
=
glm
::
normalize
(
glm
::
cross
(
mForward
,
up
)
);
mRight
=
glm
::
normalize
(
glm
::
cross
(
mForward
,
_
up
)
);
mUp
=
glm
::
normalize
(
glm
::
cross
(
mRight
,
mForward
)
);
}
void
Camera
::
updateLocalCoordinateSystemByOrientation
(
bool
moveTarget
)
void
Camera
::
updateLocalCoordinateSystemByOrientation
(
void
)
{
//Calculate the full rotation in the right order:
//rot => 1. mYaw (y) -> 2. mPitch (x) -> 3. mRoll (z)
...
...
@@ -71,11 +71,6 @@ void Camera::updateLocalCoordinateSystemByOrientation(bool moveTarget)
mRight
=
rotation
*
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
);
mUp
=
rotation
*
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
);
mForward
=
rotation
*
glm
::
vec3
(
0.0
f
,
0.0
f
,
-
1.0
f
);
if
(
moveTarget
)
{
mTarget
=
mPosition
+
(
rotation
*
(
mTarget
-
mPosition
));
}
}
void
Camera
::
updateOrientationByLocalCoordinateSystem
(
void
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment