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
3f055220
Commit
3f055220
authored
Aug 23, 2011
by
Andreas Neu
Browse files
-Camera class modified, so that no explicit update calls have to be made.
parent
0a74bba2
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/Scene/Camera.hh
View file @
3f055220
...
...
@@ -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,74 @@ 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
()
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
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
();
}
inline
void
setYaw
(
float
_yaw
)
{
mYaw
=
_yaw
;
updateLocalCoordinateSystemByOrientation
();
}
inline
void
setRoll
(
float
_roll
)
{
mRoll
=
_roll
;
}
inline
void
setPitchAroundTarget
(
float
pitch
)
{
...
...
@@ -119,16 +161,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
);
private:
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:
glm
::
vec3
mRight
;
glm
::
vec3
mUp
;
glm
::
vec3
mForward
;
...
...
src/ACGL/Scene/Camera.cc
View file @
3f055220
...
...
@@ -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
(
bool
_
moveTarget
)
{
//Calculate the full rotation in the right order:
//rot => 1. mYaw (y) -> 2. mPitch (x) -> 3. mRoll (z)
...
...
@@ -72,7 +72,7 @@ void Camera::updateLocalCoordinateSystemByOrientation(bool moveTarget)
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
)
if
(
_
moveTarget
)
{
mTarget
=
mPosition
+
(
rotation
*
(
mTarget
-
mPosition
));
}
...
...
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