Commit 7798f434 authored by Maire Nicolas's avatar Maire Nicolas

clippingShader : remplacement des firstVector et secondVector de plan par une...

clippingShader : remplacement des firstVector et secondVector de plan par une normale, c'est plus simple à utiliser.
parent 68f0b374
...@@ -83,25 +83,17 @@ public: ...@@ -83,25 +83,17 @@ public:
/** /**
* sets all parameters for one clip plane * sets all parameters for one clip plane
* @param id clip plane id * @param id clip plane id
* @param vec1 first basis vector * @param normal normal
* @param vec2 second basis vector
* @param origin origin * @param origin origin
*/ */
void setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin); void setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal, Geom::Vec3f origin);
/** /**
* sets first vector for one clip plane * sets first vector for one clip plane
* @param id clip plane id * @param id clip plane id
* @param vec1 first basis vector * @param normal normal
*/ */
void setClipPlaneParamsFirstVec(unsigned int id, Geom::Vec3f vec1); void setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal);
/**
* sets second vector for one clip plane
* @param id clip plane id
* @param vec2 second basis vector
*/
void setClipPlaneParamsSecondVec(unsigned int id, Geom::Vec3f vec2);
/** /**
* sets origin for one clip plane * sets origin for one clip plane
...@@ -111,16 +103,10 @@ public: ...@@ -111,16 +103,10 @@ public:
void setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin); void setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin);
/** /**
* gets first vector for one clip plane * gets normal vector for one clip plane
* @param id clip plane id
*/
Geom::Vec3f getClipPlaneParamsFirstVec(unsigned int id);
/**
* gets second vector for one clip plane
* @param id clip plane id * @param id clip plane id
*/ */
Geom::Vec3f getClipPlaneParamsSecondVec(unsigned int id); Geom::Vec3f getClipPlaneParamsNormal(unsigned int id);
/** /**
* gets origin for one clip plane * gets origin for one clip plane
...@@ -142,7 +128,7 @@ private: ...@@ -142,7 +128,7 @@ private:
/// clip planes structure /// clip planes structure
struct clipPlane struct clipPlane
{ {
Geom::Vec3f firstVec, secondVec, origin; Geom::Vec3f normal, origin;
}; };
/// clip planes array /// clip planes array
......
...@@ -99,10 +99,9 @@ int ClippingShader::addClipPlane() ...@@ -99,10 +99,9 @@ int ClippingShader::addClipPlane()
m_clipPlanesIds[newPlaneId].index = previousPlanesCount; m_clipPlanesIds[newPlaneId].index = previousPlanesCount;
// Set default parameters values for the new plane // Set default parameters values for the new plane
Geom::Vec3f defaultFirstVec (1.0, 0.0, 0.0); Geom::Vec3f defaultNormal (0.0, 0.0, 1.0);
Geom::Vec3f defaultSecondVec (0.0, 1.0, 0.0);
Geom::Vec3f defaultOrigin (0.0, 0.0, 0.0); Geom::Vec3f defaultOrigin (0.0, 0.0, 0.0);
setClipPlaneParamsAll(newPlaneId, defaultFirstVec, defaultSecondVec, defaultOrigin); setClipPlaneParamsAll(newPlaneId, defaultNormal, defaultOrigin);
// Recompile shaders (automatically calls updateClippingUniforms) // Recompile shaders (automatically calls updateClippingUniforms)
recompile(); recompile();
...@@ -163,7 +162,7 @@ int ClippingShader::getClipPlanesCount() ...@@ -163,7 +162,7 @@ int ClippingShader::getClipPlanesCount()
return (int)m_clipPlanes.size(); return (int)m_clipPlanes.size();
} }
void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin) void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal, Geom::Vec3f origin)
{ {
// Check if the given id is valid // Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsAll")) if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsAll"))
...@@ -175,18 +174,14 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Ge ...@@ -175,18 +174,14 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Ge
int planeIndex = m_clipPlanesIds[id].index; int planeIndex = m_clipPlanesIds[id].index;
// Normalize // Normalize
Geom::Vec3f vec1Normalized = vec1; Geom::Vec3f normalNormalized = normal;
vec1Normalized.normalize(); normalNormalized.normalize();
Geom::Vec3f vec2Normalized = vec2;
vec2Normalized.normalize();
if ((vec1Normalized != m_clipPlanes[planeIndex].firstVec) if ((normalNormalized != m_clipPlanes[planeIndex].normal)
|| (vec2Normalized != m_clipPlanes[planeIndex].secondVec)
|| (origin != m_clipPlanes[planeIndex].origin)) || (origin != m_clipPlanes[planeIndex].origin))
{ {
// Copy the given clipping plane parameters // Copy the given clipping plane parameters
m_clipPlanes[planeIndex].firstVec = vec1Normalized; m_clipPlanes[planeIndex].normal = normalNormalized;
m_clipPlanes[planeIndex].secondVec = vec2Normalized;
m_clipPlanes[planeIndex].origin = origin; m_clipPlanes[planeIndex].origin = origin;
// Update the plane arrays // Update the plane arrays
...@@ -197,7 +192,7 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Ge ...@@ -197,7 +192,7 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Ge
} }
} }
void ClippingShader::setClipPlaneParamsFirstVec(unsigned int id, Geom::Vec3f vec1) void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal)
{ {
// Check if the given id is valid // Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsFirstVec")) if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsFirstVec"))
...@@ -209,41 +204,13 @@ void ClippingShader::setClipPlaneParamsFirstVec(unsigned int id, Geom::Vec3f vec ...@@ -209,41 +204,13 @@ void ClippingShader::setClipPlaneParamsFirstVec(unsigned int id, Geom::Vec3f vec
int planeIndex = m_clipPlanesIds[id].index; int planeIndex = m_clipPlanesIds[id].index;
// Normalize // Normalize
Geom::Vec3f vec1Normalized = vec1; Geom::Vec3f normalNormalized = normal;
vec1Normalized.normalize(); normalNormalized.normalize();
if (vec1Normalized != m_clipPlanes[planeIndex].firstVec) if (normalNormalized != m_clipPlanes[planeIndex].normal)
{ {
// Copy the given clipping plane parameter // Copy the given clipping plane parameter
m_clipPlanes[planeIndex].firstVec = vec1Normalized; m_clipPlanes[planeIndex].normal = normalNormalized;
// Update the plane arrays
updateClipPlaneUniformsArray(id);
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform();
}
}
void ClippingShader::setClipPlaneParamsSecondVec(unsigned int id, Geom::Vec3f vec2)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsSecondVec"))
return;
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsSecondVec"))
return;
// Get the corresponding plane index
int planeIndex = m_clipPlanesIds[id].index;
// Normalize
Geom::Vec3f vec2Normalized = vec2;
vec2Normalized.normalize();
if (vec2Normalized != m_clipPlanes[planeIndex].secondVec)
{
// Copy the given clipping plane parameter
m_clipPlanes[planeIndex].secondVec = vec2Normalized;
// Update the plane arrays // Update the plane arrays
updateClipPlaneUniformsArray(id); updateClipPlaneUniformsArray(id);
...@@ -277,7 +244,7 @@ void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origi ...@@ -277,7 +244,7 @@ void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origi
} }
} }
Geom::Vec3f ClippingShader::getClipPlaneParamsFirstVec(unsigned int id) Geom::Vec3f ClippingShader::getClipPlaneParamsNormal(unsigned int id)
{ {
// Check if the given id is valid // Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsFirstVec")) if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsFirstVec"))
...@@ -289,22 +256,7 @@ Geom::Vec3f ClippingShader::getClipPlaneParamsFirstVec(unsigned int id) ...@@ -289,22 +256,7 @@ Geom::Vec3f ClippingShader::getClipPlaneParamsFirstVec(unsigned int id)
int planeIndex = m_clipPlanesIds[id].index; int planeIndex = m_clipPlanesIds[id].index;
// Return the parameter // Return the parameter
return m_clipPlanes[planeIndex].firstVec; return m_clipPlanes[planeIndex].normal;
}
Geom::Vec3f ClippingShader::getClipPlaneParamsSecondVec(unsigned int id)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsSecondVec"))
return Geom::Vec3f(0.0, 0.0, 0.0);
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsSecondVec"))
return Geom::Vec3f(0.0, 0.0, 0.0);
// Get the corresponding plane index
int planeIndex = m_clipPlanesIds[id].index;
// Return the parameter
return m_clipPlanes[planeIndex].secondVec;
} }
Geom::Vec3f ClippingShader::getClipPlaneParamsOrigin(unsigned int id) Geom::Vec3f ClippingShader::getClipPlaneParamsOrigin(unsigned int id)
...@@ -350,11 +302,10 @@ void ClippingShader::updateClipPlaneUniformsArray(unsigned int id) ...@@ -350,11 +302,10 @@ void ClippingShader::updateClipPlaneUniformsArray(unsigned int id)
int planeIndex = m_clipPlanesIds[id].index; int planeIndex = m_clipPlanesIds[id].index;
// Update the planes equations array // Update the planes equations array
Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec; float d = -(m_clipPlanes[planeIndex].normal * m_clipPlanes[planeIndex].origin);
float d = -(planeNormal * m_clipPlanes[planeIndex].origin); m_clipPlanesEquations[4*planeIndex + 0] = m_clipPlanes[planeIndex].normal[0];
m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0]; m_clipPlanesEquations[4*planeIndex + 1] = m_clipPlanes[planeIndex].normal[1];
m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1]; m_clipPlanesEquations[4*planeIndex + 2] = m_clipPlanes[planeIndex].normal[2];
m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
m_clipPlanesEquations[4*planeIndex + 3] = d; m_clipPlanesEquations[4*planeIndex + 3] = d;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment