mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Added view sphere highlight.
This commit is contained in:
parent
19680a199b
commit
c8102034f9
4 changed files with 45 additions and 19 deletions
|
@ -48,13 +48,15 @@ lcContext::lcContext()
|
||||||
mViewMatrix = lcMatrix44Identity();
|
mViewMatrix = lcMatrix44Identity();
|
||||||
mProjectionMatrix = lcMatrix44Identity();
|
mProjectionMatrix = lcMatrix44Identity();
|
||||||
mViewProjectionMatrix = lcMatrix44Identity();
|
mViewProjectionMatrix = lcMatrix44Identity();
|
||||||
mHighlightColor = lcVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
mHighlightParams[0] = lcVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
mHighlightParams[1] = lcVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
mHighlightParams[2] = lcVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
mColorDirty = false;
|
mColorDirty = false;
|
||||||
mWorldMatrixDirty = false;
|
mWorldMatrixDirty = false;
|
||||||
mViewMatrixDirty = false;
|
mViewMatrixDirty = false;
|
||||||
mProjectionMatrixDirty = false;
|
mProjectionMatrixDirty = false;
|
||||||
mViewProjectionMatrixDirty = false;
|
mViewProjectionMatrixDirty = false;
|
||||||
mHighlightColorDirty = false;
|
mHighlightParamsDirty = false;
|
||||||
|
|
||||||
mMaterialType = LC_NUM_MATERIALS;
|
mMaterialType = LC_NUM_MATERIALS;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +206,7 @@ void lcContext::CreateShaderPrograms()
|
||||||
mPrograms[MaterialType].MaterialColorLocation = glGetUniformLocation(Program, "MaterialColor");
|
mPrograms[MaterialType].MaterialColorLocation = glGetUniformLocation(Program, "MaterialColor");
|
||||||
mPrograms[MaterialType].LightPositionLocation = glGetUniformLocation(Program, "LightPosition");
|
mPrograms[MaterialType].LightPositionLocation = glGetUniformLocation(Program, "LightPosition");
|
||||||
mPrograms[MaterialType].EyePositionLocation = glGetUniformLocation(Program, "EyePosition");
|
mPrograms[MaterialType].EyePositionLocation = glGetUniformLocation(Program, "EyePosition");
|
||||||
mPrograms[MaterialType].HighlightColorLocation = glGetUniformLocation(Program, "HighlightColor");
|
mPrograms[MaterialType].HighlightParamsLocation = glGetUniformLocation(Program, "HighlightParams");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +335,7 @@ void lcContext::SetMaterial(lcMaterialType MaterialType)
|
||||||
mColorDirty = true;
|
mColorDirty = true;
|
||||||
mWorldMatrixDirty = true; // todo: change dirty to a bitfield and set the lighting constants dirty here
|
mWorldMatrixDirty = true; // todo: change dirty to a bitfield and set the lighting constants dirty here
|
||||||
mViewMatrixDirty = true;
|
mViewMatrixDirty = true;
|
||||||
mHighlightColorDirty = true;
|
mHighlightParamsDirty = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1174,10 +1176,10 @@ void lcContext::FlushState()
|
||||||
mColorDirty = false;
|
mColorDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHighlightColorDirty && Program.HighlightColorLocation != -1)
|
if (mHighlightParamsDirty && Program.HighlightParamsLocation != -1)
|
||||||
{
|
{
|
||||||
glUniform4fv(Program.HighlightColorLocation, 1, mHighlightColor);
|
glUniform4fv(Program.HighlightParamsLocation, 2, mHighlightParams[0]);
|
||||||
mHighlightColorDirty = false;
|
mHighlightParamsDirty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -73,7 +73,7 @@ struct lcProgram
|
||||||
GLint MaterialColorLocation;
|
GLint MaterialColorLocation;
|
||||||
GLint LightPositionLocation;
|
GLint LightPositionLocation;
|
||||||
GLint EyePositionLocation;
|
GLint EyePositionLocation;
|
||||||
GLint HighlightColorLocation;
|
GLint HighlightParamsLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
class lcFramebuffer
|
class lcFramebuffer
|
||||||
|
@ -153,10 +153,11 @@ public:
|
||||||
mColorDirty = true;
|
mColorDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHighlightColor(const lcVector4& HighlightColor)
|
void SetHighlightParams(const lcVector4& HighlightMin, const lcVector4& HighlightMax)
|
||||||
{
|
{
|
||||||
mHighlightColor = HighlightColor;
|
mHighlightParams[0] = HighlightMin;
|
||||||
mHighlightColorDirty = true;
|
mHighlightParams[1] = HighlightMax;
|
||||||
|
mHighlightParamsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetColor(float Red, float Green, float Blue, float Alpha);
|
void SetColor(float Red, float Green, float Blue, float Alpha);
|
||||||
|
@ -226,13 +227,13 @@ protected:
|
||||||
lcMatrix44 mViewMatrix;
|
lcMatrix44 mViewMatrix;
|
||||||
lcMatrix44 mProjectionMatrix;
|
lcMatrix44 mProjectionMatrix;
|
||||||
lcMatrix44 mViewProjectionMatrix;
|
lcMatrix44 mViewProjectionMatrix;
|
||||||
lcVector4 mHighlightColor;
|
lcVector4 mHighlightParams[3];
|
||||||
bool mColorDirty;
|
bool mColorDirty;
|
||||||
bool mWorldMatrixDirty;
|
bool mWorldMatrixDirty;
|
||||||
bool mViewMatrixDirty;
|
bool mViewMatrixDirty;
|
||||||
bool mProjectionMatrixDirty;
|
bool mProjectionMatrixDirty;
|
||||||
bool mViewProjectionMatrixDirty;
|
bool mViewProjectionMatrixDirty;
|
||||||
bool mHighlightColorDirty;
|
bool mHighlightParamsDirty;
|
||||||
|
|
||||||
GLuint mFramebufferObject;
|
GLuint mFramebufferObject;
|
||||||
|
|
||||||
|
|
|
@ -179,13 +179,28 @@ void lcViewSphere::Draw()
|
||||||
Context->SetVertexFormatPosition(3);
|
Context->SetVertexFormatPosition(3);
|
||||||
Context->SetIndexBuffer(mIndexBuffer);
|
Context->SetIndexBuffer(mIndexBuffer);
|
||||||
|
|
||||||
Context->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
Context->SetHighlightParams(lcVector4(10.0f, 10.0f, 10.0f, 0.0f), lcVector4(-10.0f, -10.0f, -10.0f, 0.0f));
|
||||||
Context->SetHighlightColor(lcVector4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
||||||
Context->DrawIndexedPrimitives(GL_TRIANGLES, mSubdivisions * mSubdivisions * 6 * 6, GL_UNSIGNED_SHORT, 0);
|
Context->DrawIndexedPrimitives(GL_TRIANGLES, mSubdivisions * mSubdivisions * 6 * 6, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
if (mIntersectionFlags.any())
|
if (mIntersectionFlags.any())
|
||||||
{
|
{
|
||||||
Context->SetHighlightColor(lcVector4(1.0, 0, 0, 1.0));
|
lcVector4 HighlightMin(-10.0f, -10.0f, -10.0f, 0.0f), HighlightMax(10.0f, 10.0f, 10.0f, 0.0f);
|
||||||
|
|
||||||
|
for (int AxisIdx = 0; AxisIdx < 3; AxisIdx++)
|
||||||
|
{
|
||||||
|
if (mIntersectionFlags.test(2 * AxisIdx))
|
||||||
|
{
|
||||||
|
HighlightMin[AxisIdx] = 0.5f;
|
||||||
|
HighlightMax[AxisIdx] = 10.0f;
|
||||||
|
}
|
||||||
|
else if (mIntersectionFlags.test(2 * AxisIdx + 1))
|
||||||
|
{
|
||||||
|
HighlightMin[AxisIdx] = -10.0f;
|
||||||
|
HighlightMax[AxisIdx] = -0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context->SetHighlightParams(HighlightMin, HighlightMax);
|
||||||
|
|
||||||
for (int FlagIdx = 0; FlagIdx < 6; FlagIdx++)
|
for (int FlagIdx = 0; FlagIdx < 6; FlagIdx++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
LC_PIXEL_INPUT vec3 PixelNormal;
|
LC_PIXEL_INPUT vec3 PixelNormal;
|
||||||
LC_PIXEL_OUTPUT
|
LC_PIXEL_OUTPUT
|
||||||
|
|
||||||
uniform mediump vec4 MaterialColor;
|
uniform mediump vec4 HighlightParams[2];
|
||||||
uniform mediump vec4 HighlightColor;
|
|
||||||
uniform samplerCube Texture;
|
uniform samplerCube Texture;
|
||||||
|
|
||||||
|
const mediump vec4 TextColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
const mediump vec4 BackgroundColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
const mediump vec4 HighlightColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a;
|
LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a;
|
||||||
gl_FragColor = mix(MaterialColor, HighlightColor, TexelAlpha);
|
|
||||||
|
if (PixelNormal.x > HighlightParams[0].x && PixelNormal.y > HighlightParams[0].y && PixelNormal.z > HighlightParams[0].z &&
|
||||||
|
PixelNormal.x < HighlightParams[1].x && PixelNormal.y < HighlightParams[1].y && PixelNormal.z < HighlightParams[1].z)
|
||||||
|
gl_FragColor = mix(HighlightColor, TextColor, TexelAlpha);
|
||||||
|
else
|
||||||
|
gl_FragColor = mix(BackgroundColor, TextColor, TexelAlpha);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue