Commit 9e41c46e authored by Maire Nicolas's avatar Maire Nicolas

Rajout de 2 presets animés. Quelques améliorations dans l'appli clipping

parent 0994bb89
......@@ -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(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
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 - 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(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
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 - 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(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
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 - 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(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarDbl(atomsRadiuses - 100.0, atomsRadiuses + 100.0, atomsRadiuses, "Atoms radiuses",
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 - 100.0f, size + 100.0f, size, "Size",
VarFloat(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(VarDbl(centerStartX - 100.0, centerStartX + 100.0, centerStartX, "Center Start X",
VarDbl(centerStartY - 100.0, centerStartY + 100.0, centerStartY, "Center Start Y",
VarDbl(centerStartZ - 100.0, centerStartZ + 100.0, centerStartZ, "Center Start Z",
VarDbl(centerEndX - 100.0, centerEndX + 100.0, centerEndX, "Center End X",
VarDbl(centerEndY - 100.0, centerEndY + 100.0, centerEndY, "Center End Y",
VarDbl(centerEndZ - 100.0, centerEndZ + 100.0, centerEndZ, "Center End Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
if (inputValues(VarFloat(centerStartX - 100.0f, centerStartX + 100.0f, centerStartX, "Center Start X",
VarFloat(centerStartY - 100.0f, centerStartY + 100.0f, centerStartY, "Center Start Y",
VarFloat(centerStartZ - 100.0f, centerStartZ + 100.0f, centerStartZ, "Center Start Z",
VarFloat(centerEndX - 100.0f, centerEndX + 100.0f, centerEndX, "Center End X",
VarFloat(centerEndY - 100.0f, centerEndY + 100.0f, centerEndY, "Center End Y",
VarFloat(centerEndZ - 100.0f, centerEndZ + 100.0f, centerEndZ, "Center End Z",
VarFloat(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(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
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",
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)));
......
......@@ -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();
......
......@@ -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
......
......@@ -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.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f;
positDir[usedAxis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f;
negDir[usedAxis] = -1.0f;
// Facing of planes
float side = 1.0f;
......@@ -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.0f * M_PI / precision;
for (int i = 0; i < precision; i++)
{
direction[(axis + 1) % 3] = cos(i*dAngle);
direction[(axis + 2) % 3] = sin(i*dAngle);
direction[(usedAxis + 1) % 3] = cos(i*dAngle);
direction[(usedAxis + 2) % 3] = sin(i*dAngle);
preset->addClipPlane(direction, center + direction*(size / 2.0f)*(side));
}
......
......@@ -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.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f;
positDir[usedAxis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f;
negDir[usedAxis] = -1.0f;
// Facing of planes
float side = 1.0f;
......@@ -113,7 +112,7 @@ void ClippingPresetAnimatedDualPlanes::step(unsigned int amount)
CGoGNerr
<< "ERROR -"
<< "ClippingPresetAnimatedDualPlanes::step"
<< " - Some planes or spheres ids are not valid anymore - Animation stopped"
<< " - Some planes or spheres ids are not valid anymore - Animation paused"
<< CGoGNendl;
m_animationSpeedFactor = 0.0f;
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.0f, 0.0f, 0.0f);
normal[(axis + 1) % 3] = 1.0f;
normal[(m_axis + 1) % 3] = 1.0f;
// Add plane to preset
addClipPlane(normal, center);
......@@ -188,8 +187,8 @@ void ClippingPresetAnimatedRotatingPlane::step(unsigned int amount)
{
CGoGNerr
<< "ERROR -"
<< "ClippingPresetAnimatedDualPlanes::step"
<< " - Some planes or spheres ids are not valid anymore - Animation stopped"
<< "ClippingPresetAnimatedRotatingPlane::step"
<< " - Some planes or spheres ids are not valid anymore - Animation paused"
<< CGoGNendl;
m_animationSpeedFactor = 0.0f;
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.0f)
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.0f;
return;
}
// Update animation parameter value
m_animParam += (float)amount * m_animationOneStepIncrement * m_animationSpeedFactor;
if (!m_zigzag)
{
while (m_animParam < 0.0f)
m_animParam += 1.0f;
while (m_animParam > 1.0f)
m_animParam -= 1.0f;
}
else
{
while ( (m_animParam < 0.0f) || (m_animParam > 1.0f) )
{
if (m_animParam < 0.0f)
{
m_animParam = -m_animParam;
m_animationOneStepIncrement = -m_animationOneStepIncrement;
}
else if (m_animParam > 1.0f)
{
m_animParam = 1.0f - (m_animParam - 1.0f);
m_animationOneStepIncrement = -m_animationOneStepIncrement;
}
}
}