Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KennethVanhoey
CGoGN
Commits
9e41c46e
Commit
9e41c46e
authored
Aug 12, 2011
by
Maire Nicolas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rajout de 2 presets animés. Quelques améliorations dans l'appli clipping
parent
0994bb89
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
388 additions
and
87 deletions
+388
-87
Apps/Examples/clipping.cpp
Apps/Examples/clipping.cpp
+146
-63
Apps/Examples/clipping.h
Apps/Examples/clipping.h
+2
-0
include/Utils/clippingPresetsAnimated.h
include/Utils/clippingPresetsAnimated.h
+70
-0
src/Utils/clippingPresets.cpp
src/Utils/clippingPresets.cpp
+10
-8
src/Utils/clippingPresetsAnimated.cpp
src/Utils/clippingPresetsAnimated.cpp
+158
-14
src/Utils/clippingShader.cpp
src/Utils/clippingShader.cpp
+2
-2
No files found.
Apps/Examples/clipping.cpp
View file @
9e41c46e
...
...
@@ -78,12 +78,31 @@ void Clipping::updatePickables()
transfoMat[2][j] = vec1[j];
transfoMat[3][j] = pos[j];
}
transfoMat[0][3] = 0.0;
transfoMat[1][3] = 0.0;
transfoMat[2][3] = 0.0;
transfoMat[3][3] = 1.0;
}
for (size_t i = 0; i < m_pickableSpheres.size(); i++)
{
unsigned int id = m_pickableSpheres[i]->id();
m_pickableSpheres[i]->translate(m_shader->getClipSphereParamsCenter(id));
m_pickableSpheres[i]->scale(m_shader->getClipSphereParamsRadius(id));
Geom::Vec3f pos = m_shader->getClipSphereParamsCenter(id);
float radius = m_shader->getClipSphereParamsRadius(id);
Geom::Vec3f vec1 (radius, 0.0, 0.0);
Geom::Vec3f vec2 (0.0, radius, 0.0);
Geom::Vec3f vec3 (0.0, 0.0, radius);
glm::mat4& transfoMat = m_pickableSpheres[i]->transfo();
for (int j = 0; j < 3; j++)
{
transfoMat[0][j] = vec2[j];
transfoMat[1][j] = vec3[j];
transfoMat[2][j] = vec1[j];
transfoMat[3][j] = pos[j];
}
transfoMat[0][3] = 0.0;
transfoMat[1][3] = 0.0;
transfoMat[2][3] = 0.0;
transfoMat[3][3] = 1.0;
}
}
...
...
@@ -317,20 +336,20 @@ void Clipping::slot_pushButton_applyStaticClippingPreset()
{
using namespace CGoGN::Utils::QT;
double centerX = (double)
m_bb.center()[0];
double centerY = (double)
m_bb.center()[1];
double centerZ = (double)
m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75
;
float centerX =
m_bb.center()[0];
float centerY =
m_bb.center()[1];
float centerZ =
m_bb.center()[2];
float size = m_bb.maxSize()*0.75f
;
int axis = 0;
bool facing = false;
if (inputValues(Var
Dbl(centerX - 100.0, centerX + 100.0
, centerX, "Center X",
Var
Dbl(centerY - 100.0, centerY + 100.0
, centerY, "Center Y",
Var
Dbl(centerZ - 100.0, centerZ + 100.0
, centerZ, "Center Z",
Var
Dbl(size - 100.0, size + 100.0
, size, "Size",
if (inputValues(Var
Float(centerX - 100.0f, centerX + 100.0f
, centerX, "Center X",
Var
Float(centerY - 100.0f, centerY + 100.0f
, centerY, "Center Y",
Var
Float(centerZ - 100.0f, centerZ + 100.0f
, centerZ, "Center Z",
Var
Float(size - 100.0f, size + 100.0f
, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarBool(facing, "Facing"
)))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f(
(float)centerX, (float)centerY, (float)centerZ), (float)
size, axis, facing);
preset = Utils::ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f(
centerX, centerY, centerZ),
size, axis, facing);
}
break;
...
...
@@ -338,18 +357,18 @@ void Clipping::slot_pushButton_applyStaticClippingPreset()
{
using namespace CGoGN::Utils::QT;
double centerX = (double)
m_bb.center()[0];
double centerY = (double)
m_bb.center()[1];
double centerZ = (double)
m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75
;
float centerX =
m_bb.center()[0];
float centerY =
m_bb.center()[1];
float centerZ =
m_bb.center()[2];
float size = m_bb.maxSize()*0.75f
;
bool facing = false;
if (inputValues(Var
Dbl(centerX - 100.0, centerX + 100.0
, centerX, "Center X",
Var
Dbl(centerY - 100.0, centerY + 100.0
, centerY, "Center Y",
Var
Dbl(centerZ - 100.0, centerZ + 100.0
, centerZ, "Center Z",
Var
Dbl(size - 100.0, size + 100.0
, size, "Size",
if (inputValues(Var
Float(centerX - 100.0f, centerX + 100.0f
, centerX, "Center X",
Var
Float(centerY - 100.0f, centerY + 100.0f
, centerY, "Center Y",
Var
Float(centerZ - 100.0f, centerZ + 100.0f
, centerZ, "Center Z",
Var
Float(size - 100.0f, size + 100.0f
, size, "Size",
VarBool(facing, "Facing"
))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f(
(float)centerX, (float)centerY, (float)centerZ), (float)
size, facing);
preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f(
centerX, centerY, centerZ),
size, facing);
}
break;
...
...
@@ -357,22 +376,22 @@ void Clipping::slot_pushButton_applyStaticClippingPreset()
{
using namespace CGoGN::Utils::QT;
double centerX = (double)
m_bb.center()[0];
double centerY = (double)
m_bb.center()[1];
double centerZ = (double)
m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75
;
float centerX =
m_bb.center()[0];
float centerY =
m_bb.center()[1];
float centerZ =
m_bb.center()[2];
float size = m_bb.maxSize()*0.75f
;
int axis = 0;
int precision = 1;
bool facing = false;
if (inputValues(Var
Dbl(centerX - 100.0, centerX + 100.0
, centerX, "Center X",
Var
Dbl(centerY - 100.0, centerY + 100.0
, centerY, "Center Y",
Var
Dbl(centerZ - 100.0, centerZ + 100.0
, centerZ, "Center Z",
Var
Dbl(size - 100.0, size + 100.0
, size, "Size",
if (inputValues(Var
Float(centerX - 100.0f, centerX + 100.0f
, centerX, "Center X",
Var
Float(centerY - 100.0f, centerY + 100.0f
, centerY, "Center Y",
Var
Float(centerZ - 100.0f, centerZ + 100.0f
, centerZ, "Center Z",
Var
Float(size - 100.0f, size + 100.0f
, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarSlider(1, 30, precision, "Precision",
VarBool(facing, "Facing"
))))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateTubePreset(Geom::Vec3f(
(float)centerX, (float)centerY, (float)centerZ), (float)
size, axis, precision, facing);
preset = Utils::ClippingPreset::CreateTubePreset(Geom::Vec3f(
centerX, centerY, centerZ),
size, axis, precision, facing);
}
break;
...
...
@@ -380,20 +399,20 @@ void Clipping::slot_pushButton_applyStaticClippingPreset()
{
using namespace CGoGN::Utils::QT;
double centerX = (double)
m_bb.center()[0];
double centerY = (double)
m_bb.center()[1];
double centerZ = (double)
m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75
;
double atomsRadiuses = (double)m_bb.maxSize()*0.25
;
float centerX =
m_bb.center()[0];
float centerY =
m_bb.center()[1];
float centerZ =
m_bb.center()[2];
float size = m_bb.maxSize()*0.75f
;
float atomsRadiuses = m_bb.maxSize()*0.25f
;
bool orClipping = true;
if (inputValues(Var
Dbl(centerX - 100.0, centerX + 100.0
, centerX, "Center X",
Var
Dbl(centerY - 100.0, centerY + 100.0
, centerY, "Center Y",
Var
Dbl(centerZ - 100.0, centerZ + 100.0
, centerZ, "Center Z",
Var
Dbl(size - 100.0, size + 100.0
, size, "Size",
Var
Dbl(atomsRadiuses - 100.0, atomsRadiuses + 100.0
, atomsRadiuses, "Atoms radiuses",
if (inputValues(Var
Float(centerX - 100.0f, centerX + 100.0f
, centerX, "Center X",
Var
Float(centerY - 100.0f, centerY + 100.0f
, centerY, "Center Y",
Var
Float(centerZ - 100.0f, centerZ + 100.0f
, centerZ, "Center Z",
Var
Float(size - 100.0f, size + 100.0f
, size, "Size",
Var
Float(atomsRadiuses - 100.0f, atomsRadiuses + 100.0f
, atomsRadiuses, "Atoms radiuses",
VarBool(orClipping, "OR clipping mode"
)))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateMoleculePreset(Geom::Vec3f(
(float)centerX, (float)centerY, (float)centerZ), (float)
size, atomsRadiuses, orClipping);
preset = Utils::ClippingPreset::CreateMoleculePreset(Geom::Vec3f(
centerX, centerY, centerZ),
size, atomsRadiuses, orClipping);
}
break;
}
...
...
@@ -458,30 +477,30 @@ void Clipping::slot_pushButton_applyAnimatedClippingPreset()
Utils::ClippingPresetAnimatedDualPlanes *preset = NULL;
using namespace CGoGN::Utils::QT;
double centerStartX = (double)m_bb.center()[0] - (double)m_bb.size(0)*0.25
;
double centerStartY = (double)
m_bb.center()[1];
double centerStartZ = (double)
m_bb.center()[2];
double centerEndX = (double)m_bb.center()[0] + (double)m_bb.size(0)*0.25
;
double centerEndY = (double)
m_bb.center()[1];
double centerEndZ = (double)
m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.1
;
float centerStartX = m_bb.center()[0] - m_bb.size(0)*0.25f
;
float centerStartY =
m_bb.center()[1];
float centerStartZ =
m_bb.center()[2];
float centerEndX = m_bb.center()[0] + m_bb.size(0)*0.25f
;
float centerEndY =
m_bb.center()[1];
float centerEndZ =
m_bb.center()[2];
float size = m_bb.maxSize()*0.1f
;
int axis = 0;
bool facing = false;
bool zigzag = false;
if (inputValues(Var
Dbl(centerStartX - 100.0, centerStartX + 100.0
, centerStartX, "Center Start X",
Var
Dbl(centerStartY - 100.0, centerStartY + 100.0
, centerStartY, "Center Start Y",
Var
Dbl(centerStartZ - 100.0, centerStartZ + 100.0
, centerStartZ, "Center Start Z",
Var
Dbl(centerEndX - 100.0, centerEndX + 100.0
, centerEndX, "Center End X",
Var
Dbl(centerEndY - 100.0, centerEndY + 100.0
, centerEndY, "Center End Y",
Var
Dbl(centerEndZ - 100.0, centerEndZ + 100.0
, centerEndZ, "Center End Z",
Var
Dbl(size - 100.0, size + 100.0
, size, "Size",
if (inputValues(Var
Float(centerStartX - 100.0f, centerStartX + 100.0f
, centerStartX, "Center Start X",
Var
Float(centerStartY - 100.0f, centerStartY + 100.0f
, centerStartY, "Center Start Y",
Var
Float(centerStartZ - 100.0f, centerStartZ + 100.0f
, centerStartZ, "Center Start Z",
Var
Float(centerEndX - 100.0f, centerEndX + 100.0f
, centerEndX, "Center End X",
Var
Float(centerEndY - 100.0f, centerEndY + 100.0f
, centerEndY, "Center End Y",
Var
Float(centerEndZ - 100.0f, centerEndZ + 100.0f
, centerEndZ, "Center End Z",
Var
Float(size - 100.0f, size + 100.0f
, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarBool(facing, "Facing",
VarBool(zigzag, "Zigzag"
)))))))))), "Preset Setup"))
preset = new Utils::ClippingPresetAnimatedDualPlanes(
Geom::Vec3f(
(float)centerStartX, (float)centerStartY, (float)centerStartZ), Geom::Vec3f((float)centerEndX, (float)centerEndY, (float)
centerEndZ),
(float)
size, axis, facing, zigzag);
Geom::Vec3f(
centerStartX, centerStartY, centerStartZ), Geom::Vec3f(centerEndX, centerEndY,
centerEndZ),
size, axis, facing, zigzag);
animatedPreset = preset;
}
...
...
@@ -492,22 +511,73 @@ void Clipping::slot_pushButton_applyAnimatedClippingPreset()
Utils::ClippingPresetAnimatedRotatingPlane *preset = NULL;
using namespace CGoGN::Utils::QT;
double centerX = (double)
m_bb.center()[0];
double centerY = (double)
m_bb.center()[1];
double centerZ = (double)
m_bb.center()[2];
float centerX =
m_bb.center()[0];
float centerY =
m_bb.center()[1];
float centerZ =
m_bb.center()[2];
int axis = 0;
if (inputValues(Var
Dbl(centerX - 100.0, centerX + 100.0
, centerX, "Center X",
Var
Dbl(centerY - 100.0, centerY + 100.0
, centerY, "Center Y",
Var
Dbl(centerZ - 100.0, centerZ + 100.0
, centerZ, "Center Z",
if (inputValues(Var
Float(centerX - 100.0f, centerX + 100.0f
, centerX, "Center X",
Var
Float(centerY - 100.0f, centerY + 100.0f
, centerY, "Center Y",
Var
Float(centerZ - 100.0f, centerZ + 100.0f
, centerZ, "Center Z",
VarSlider(0, 2, axis, "Axis"
)))), "Preset Setup"))
preset = new Utils::ClippingPresetAnimatedRotatingPlane(
Geom::Vec3f(
(float)centerX, (float)centerY, (float)
centerZ), axis);
Geom::Vec3f(
centerX, centerY,
centerZ), axis);
animatedPreset = preset;
}
break;
case 2 : // Scaled Sphere
{
Utils::ClippingPresetAnimatedScaledSphere *preset = NULL;
using namespace CGoGN::Utils::QT;
float centerX = m_bb.center()[0];
float centerY = m_bb.center()[1];
float centerZ = m_bb.center()[2];
float radiusStart = m_bb.maxSize()*0.1f;
float radiusEnd = m_bb.maxSize()*1.0f;
bool zigzag = false;
if (inputValues(VarFloat(centerX - 100.0f, centerX + 100.0f, centerX, "Center X",
VarFloat(centerY - 100.0f, centerY + 100.0f, centerY, "Center Y",
VarFloat(centerZ - 100.0f, centerZ + 100.0f, centerZ, "Center Z",
VarFloat(-radiusEnd*4.0f, radiusEnd*4.0f, radiusStart, "Radius Start",
VarFloat(-radiusEnd*4.0f, radiusEnd*4.0f, radiusEnd, "Radius End",
VarBool(zigzag, "Zigzag"
)))))), "Preset Setup"))
preset = new Utils::ClippingPresetAnimatedScaledSphere(
Geom::Vec3f(centerX, centerY, centerZ), radiusStart, radiusEnd, zigzag);
animatedPreset = preset;
}
break;
case 3 : // Spheres Cube Collision
{
Utils::ClippingPresetAnimatedSpheresCubeCollision *preset = NULL;
using namespace CGoGN::Utils::QT;
float centerX = m_bb.center()[0];
float centerY = m_bb.center()[1];
float centerZ = m_bb.center()[2];
float size = m_bb.maxSize()*1.0f;
int spheresCount = 5;
float radius = m_bb.maxSize()*0.2f;
if (inputValues(VarFloat(centerX - 100.0f, centerX + 100.0f, centerX, "Center X",
VarFloat(centerY - 100.0f, centerY + 100.0f, centerY, "Center Y",
VarFloat(centerZ - 100.0f, centerZ + 100.0f, centerZ, "Center Z",
VarFloat(-size*4.0f, size*4.0f, size, "Cube Size",
VarSlider(1, 20, spheresCount, "Spheres Count",
VarFloat(-radius*4.0f, radius*4.0f, radius, "Spheres Radius"
)))))), "Preset Setup"))
{
preset = new Utils::ClippingPresetAnimatedSpheresCubeCollision(
Geom::Vec3f(centerX, centerY, centerZ), size, spheresCount, radius);
}
animatedPreset = preset;
}
break;
}
if (animatedPreset == NULL)
...
...
@@ -553,6 +623,8 @@ void Clipping::slot_pushButton_applyAnimatedClippingPreset()
// Set on animated mode
m_lastAnimatedClippingPreset = animatedPreset;
m_timer->start(1000.0f/60.0f);
m_lastAnimatedClippingPreset->setAnimationSpeedFactor((float)dock.doubleSpinBox_AnimatedClippingPresetSpeed->value());
slot_setAnimationState(true);
updateGLMatrices();
...
...
@@ -565,6 +637,7 @@ void Clipping::slot_pushButton_StopAnimation()
delete m_lastAnimatedClippingPreset;
m_lastAnimatedClippingPreset = NULL;
}
slot_setAnimationState(false);
}
void Clipping::slot_doubleSpinBox_AnimatedClippingPresetSpeed(double c)
...
...
@@ -573,6 +646,14 @@ void Clipping::slot_doubleSpinBox_AnimatedClippingPresetSpeed(double c)
m_lastAnimatedClippingPreset->setAnimationSpeedFactor((float)c);
}
void Clipping::slot_setAnimationState(bool state)
{
dock.pushButton_addPlane->setEnabled(!state);
dock.pushButton_addSphere->setEnabled(!state);
dock.PushButton_ApplyStaticClippingPreset->setEnabled(!state);
dock.PushButton_ApplyAnimatedClippingPreset->setEnabled(!state);
}
void Clipping::slot_animationTimer()
{
if (m_lastAnimatedClippingPreset == NULL)
...
...
@@ -692,6 +773,8 @@ void Clipping::initGUI()
dock.comboBox_AnimatedClippingPresets->addItem("Moving Dual Planes");
dock.comboBox_AnimatedClippingPresets->addItem("Rotating Plane");
dock.comboBox_AnimatedClippingPresets->addItem("Scaled Sphere");
dock.comboBox_AnimatedClippingPresets->addItem("Spheres Cube Collision");
setCallBack(dock.pushButton_StopAnimation, SIGNAL(clicked()), SLOT(slot_pushButton_StopAnimation()));
setCallBack(dock.doubleSpinBox_AnimatedClippingPresetSpeed, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_AnimatedClippingPresetSpeed(double)));
...
...
Apps/Examples/clipping.h
View file @
9e41c46e
...
...
@@ -168,6 +168,8 @@ public slots:
void
slot_pushButton_StopAnimation
();
void
slot_doubleSpinBox_AnimatedClippingPresetSpeed
(
double
c
);
void
slot_setAnimationState
(
bool
state
);
void
slot_animationTimer
();
void
button_compile
();
...
...
include/Utils/clippingPresetsAnimated.h
View file @
9e41c46e
...
...
@@ -29,6 +29,9 @@
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include <cmath>
#include <vector>
#include <cstdlib>
#include <time.h>
namespace
CGoGN
{
...
...
@@ -180,6 +183,73 @@ private :
};
class
ClippingPresetAnimatedScaledSphere
:
public
ClippingPresetAnimated
{
public
:
/**
* constructor
* @param center center of sphere
* @param radiusStart radius of the sphere at the beginning of the animation
* @param radiusEnd radius of the sphere at the end of the animation
* @param zigzag true to enable zigzag mode
*/
ClippingPresetAnimatedScaledSphere
(
Geom
::
Vec3f
center
,
float
radiusStart
,
float
radiusEnd
,
bool
zigzag
);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void
step
(
unsigned
int
amount
);
private
:
/// start radius of the animation
float
m_startRadius
;
/// end radius of the animation
float
m_endRadius
;
/// zigzag mode ?
bool
m_zigzag
;
};
class
ClippingPresetAnimatedSpheresCubeCollision
:
public
ClippingPresetAnimated
{
public
:
/**
* constructor
* @param center center of cube
* @param size size of cube
* @param spheresCount spheres count
* @param radius radius of spheres
*/
ClippingPresetAnimatedSpheresCubeCollision
(
Geom
::
Vec3f
center
,
float
size
,
int
spheresCount
,
float
radius
);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void
step
(
unsigned
int
amount
);
private
:
/// center of cube
Geom
::
Vec3f
m_cubeCenter
;
/// size of cube
float
m_cubeSize
;
/// direction vector of spheres
std
::
vector
<
Geom
::
Vec3f
>
m_spheresDirections
;
};
}
// namespace Utils
...
...
src/Utils/clippingPresets.cpp
View file @
9e41c46e
...
...
@@ -50,14 +50,15 @@ ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float
ClippingPreset
*
preset
=
new
ClippingPreset
;
// Correct axis if necessary
if
((
axis
<
0
)
||
(
axis
>
2
))
axis
=
0
;
int
usedAxis
=
axis
;
if
((
usedAxis
<
0
)
||
(
usedAxis
>
2
))
usedAxis
=
0
;
// Axis on which planes will be aligned
Geom
::
Vec3f
positDir
(
0.0
f
,
0.0
f
,
0.0
f
);
positDir
[
a
xis
]
=
1.0
f
;
positDir
[
usedA
xis
]
=
1.0
f
;
Geom
::
Vec3f
negDir
(
0.0
f
,
0.0
f
,
0.0
f
);
negDir
[
a
xis
]
=
-
1.0
f
;
negDir
[
usedA
xis
]
=
-
1.0
f
;
// Facing of planes
float
side
=
1.0
f
;
...
...
@@ -116,8 +117,9 @@ ClippingPreset* ClippingPreset::CreateTubePreset(Geom::Vec3f center, float size,
ClippingPreset
*
preset
=
new
ClippingPreset
;
// Correct axis if necessary
if
((
axis
<
0
)
||
(
axis
>
2
))
axis
=
0
;
int
usedAxis
=
axis
;
if
((
usedAxis
<
0
)
||
(
usedAxis
>
2
))
usedAxis
=
0
;
// Correct precision if necessary
if
(
precision
<
1
)
...
...
@@ -133,8 +135,8 @@ ClippingPreset* ClippingPreset::CreateTubePreset(Geom::Vec3f center, float size,
float
dAngle
=
2.0
f
*
M_PI
/
precision
;
for
(
int
i
=
0
;
i
<
precision
;
i
++
)
{
direction
[(
a
xis
+
1
)
%
3
]
=
cos
(
i
*
dAngle
);
direction
[(
a
xis
+
2
)
%
3
]
=
sin
(
i
*
dAngle
);
direction
[(
usedA
xis
+
1
)
%
3
]
=
cos
(
i
*
dAngle
);
direction
[(
usedA
xis
+
2
)
%
3
]
=
sin
(
i
*
dAngle
);
preset
->
addClipPlane
(
direction
,
center
+
direction
*
(
size
/
2.0
f
)
*
(
side
));
}
...
...
src/Utils/clippingPresetsAnimated.cpp
View file @
9e41c46e
...
...
@@ -67,22 +67,21 @@ void ClippingPresetAnimated::apply(ClippingShader* clipShader, std::vector<unsig
ClippingPresetAnimatedDualPlanes
::
ClippingPresetAnimatedDualPlanes
(
Geom
::
Vec3f
centerStart
,
Geom
::
Vec3f
centerEnd
,
float
size
,
int
axis
,
bool
facing
,
bool
zigzag
)
{
// Store
the
animation settings
// Store animation settings
m_dirVec
=
centerEnd
-
centerStart
;
m_dirVec
.
normalize
();
m_startPoint
=
centerStart
;
m_endPoint
=
centerEnd
;
m_zigzag
=
zigzag
;
// Correct axis if necessary
if
((
axis
<
0
)
||
(
axis
>
2
))
axis
=
0
;
int
usedAxis
=
axis
;
if
((
usedAxis
<
0
)
||
(
usedAxis
>
2
))
usedAxis
=
0
;
// Axis on which planes will be aligned
Geom
::
Vec3f
positDir
(
0.0
f
,
0.0
f
,
0.0
f
);
positDir
[
a
xis
]
=
1.0
f
;
positDir
[
usedA
xis
]
=
1.0
f
;
Geom
::
Vec3f
negDir
(
0.0
f
,
0.0
f
,
0.0
f
);
negDir
[
a
xis
]
=
-
1.0
f
;
negDir
[
usedA
xis
]
=
-
1.0
f
;
// Facing of planes
float
side
=
1.0
f
;
...
...
@@ -113,7 +112,7 @@ void ClippingPresetAnimatedDualPlanes::step(unsigned int amount)
CGoGNerr
<<
"ERROR -"
<<
"ClippingPresetAnimatedDualPlanes::step"
<<
" - Some planes or spheres ids are not valid anymore - Animation
stopp
ed"
<<
" - Some planes or spheres ids are not valid anymore - Animation
paus
ed"
<<
CGoGNendl
;
m_animationSpeedFactor
=
0.0
f
;
return
;
...
...
@@ -161,14 +160,14 @@ void ClippingPresetAnimatedDualPlanes::step(unsigned int amount)
ClippingPresetAnimatedRotatingPlane
::
ClippingPresetAnimatedRotatingPlane
(
Geom
::
Vec3f
center
,
int
axis
)
{
// Correct axis if necessary and store it
if
((
axis
<
0
)
||
(
axis
>
2
))
axis
=
0
;
// Store animation settings
m_axis
=
axis
;
if
((
m_axis
<
0
)
||
(
m_axis
))
m_axis
=
0
;
// Axis on which planes will be aligned
Geom
::
Vec3f
normal
(
0.0
f
,
0.0
f
,
0.0
f
);
normal
[(
axis
+
1
)
%
3
]
=
1.0
f
;
normal
[(
m_
axis
+
1
)
%
3
]
=
1.0
f
;
// Add plane to preset
addClipPlane
(
normal
,
center
);
...
...
@@ -188,8 +187,8 @@ void ClippingPresetAnimatedRotatingPlane::step(unsigned int amount)
{
CGoGNerr
<<
"ERROR -"
<<
"ClippingPresetAnimated
DualPlanes
::step"
<<
" - Some planes or spheres ids are not valid anymore - Animation
stopp
ed"
<<
"ClippingPresetAnimated
RotatingPlane
::step"
<<
" - Some planes or spheres ids are not valid anymore - Animation
paus
ed"
<<
CGoGNendl
;
m_animationSpeedFactor
=
0.0
f
;
return
;
...
...
@@ -208,8 +207,153 @@ void ClippingPresetAnimatedRotatingPlane::step(unsigned int amount)
planeNormal
[(
m_axis
+
1
)
%
3
]
=
cos
(
angle
);
planeNormal
[(
m_axis
+
2
)
%
3
]
=
sin
(
angle
);
m_attachedClippingShader
->
setClipPlaneParamsNormal
(
m_planesIds
[
0
],
planeNormal
);
}
ClippingPresetAnimatedScaledSphere
::
ClippingPresetAnimatedScaledSphere
(
Geom
::
Vec3f
center
,
float
radiusStart
,
float
radiusEnd
,
bool
zigzag
)
{
// Store animation settings
m_startRadius
=
radiusStart
;
m_endRadius
=
radiusEnd
;
std
::
cout
<<
"Given Start Radius : "
<<
radiusStart
<<
std
::
endl
;
std
::
cout
<<
"Actual Start Radius : "
<<
m_startRadius
<<
std
::
endl
;
std
::
cout
<<
"Given End Radius : "
<<
radiusEnd
<<
std
::
endl
;
std
::
cout
<<
"Actual End Radius : "
<<
m_endRadius
<<
std
::
endl
;
m_zigzag
=
zigzag
;
// Add sphere to preset
addClipSphere
(
center
,
m_startRadius
);
// Set clipping mode
setClippingMode
(
ClippingShader
::
CLIPPING_MODE_AND
);
}
void
ClippingPresetAnimatedScaledSphere
::
step
(
unsigned
int
amount
)
{
// Check if the animation has been stopped
if
(
m_animationSpeedFactor
==
0.0
f
)
return
;
// Check the validity of planes or spheres ids
if
(
!
m_attachedClippingShader
->
isClipSphereIdValid
(
m_spheresIds
[
0
]))
{
CGoGNerr
<<
"ERROR -"
<<
"ClippingPresetAnimatedScaledSphere::step"
<<
" - Some planes or spheres ids are not valid anymore - Animation paused"
<<
CGoGNendl
;
m_animationSpeedFactor
=
0.0
f
;
return
;
}
// Update animation parameter value
m_animParam
+=
(
float
)
amount
*
m_animationOneStepIncrement
*
m_animationSpeedFactor
;
if
(
!
m_zigzag
)
{
while
(
m_animParam
<
0.0
f
)
m_animParam
+=
1.0
f
;
while
(
m_animParam
>
1.0
f
)
m_animParam
-=
1.0
f
;
}
else
{
while
(
(
m_animParam
<
0.0
f
)
||
(
m_animParam
>
1.0
f
)
)
{
if
(
m_animParam
<
0.0
f
)
{
m_animParam
=
-
m_animParam
;
m_animationOneStepIncrement
=
-
m_animationOneStepIncrement
;
}
else
if
(
m_animParam
>
1.0
f
)
{
m_animParam
=
1.0
f
-
(
m_animParam
-
1.0
f
);
m_animationOneStepIncrement
=
-
m_animationOneStepIncrement
;
}
}
}
// Calculate new radius
float
radius
=
(
1.0
f
-
m_animParam
)
*
m_startRadius
+
m_animParam
*
m_endRadius
;
m_attachedClippingShader
->
setClipSphereParamsRadius
(
m_spheresIds
[
0
],
radius
);
}
ClippingPresetAnimatedSpheresCubeCollision
::
ClippingPresetAnimatedSpheresCubeCollision
(
Geom
::
Vec3f
center
,
float
size
,
int
spheresCount
,
float
radius
)
{
// Store animation settings
m_cubeCenter
=
center
;
m_cubeSize
=
size
;
int
usedSpheresCount
=
spheresCount
;
if
(
usedSpheresCount
<
1
)
usedSpheresCount
=
1
;
// Add spheres to preset
for
(
int
i
=
0
;
i
<
usedSpheresCount
;
i
++
)
addClipSphere
(
m_cubeCenter
,
radius
);
// Store spheres random directions
m_spheresDirections
.
resize
(
usedSpheresCount
);
srand
(
time
(
NULL
));
for
(
size_t
i
=
0
;
i
<
m_spheresDirections
.
size
();
i
++
)
{
Geom
::
Vec3f
dir
((
rand
()
%
1000
)
-
500
,
(
rand
()
%
1000
)
-
500
,
(
rand
()
%
1000
)
-
500
);
dir
.
normalize
();
m_spheresDirections
[
i
]
=
dir
;
}
// Set clipping mode
setClippingMode
(
ClippingShader
::
CLIPPING_MODE_AND
);
}
void
ClippingPresetAnimatedSpheresCubeCollision
::
step
(
unsigned
int
amount
)
{
// Check if the animation has been stopped
if
(
m_animationSpeedFactor
==
0.0
f
)
return
;
// Check the validity of planes or spheres ids
for
(
size_t
i
=
0
;
i
<
m_spheresIds
.
size
();
i
++
)
{
if
(
!
m_attachedClippingShader
->
isClipSphereIdValid
(
m_spheresIds
[
i
]))
{
CGoGNerr
<<
"ERROR -"
<<
"ClippingPresetAnimatedSpheresCubeCollision::step"
<<
" - Some planes or spheres ids are not valid anymore - Animation paused"
<<
CGoGNendl
;
m_animationSpeedFactor
=
0.0
f
;
return
;
}
}
// Update animation parameter value
float
dParam
=
(
float
)
amount
*
m_animationOneStepIncrement
*
m_animationSpeedFactor
;
m_animParam
+=
dParam
;
while
(
m_animParam
<
0.0
f
)
m_animParam
+=
1.0
f
;
while
(
m_animParam
>
1.0
f
)
m_animParam
-=
1.0
f
;
// Calculate new center and detect collisions with cube faces
for
(
size_t
i
=
0
;
i
<
m_spheresIds
.
size
();
i
++
)
{
Geom
::
Vec3f
oldCenter
=
m_attachedClippingShader
->
getClipSphereParamsCenter
(
m_spheresIds
[
i
]);