Rewrote camera and light drawing.

This commit is contained in:
leo 2015-04-19 01:10:01 +00:00
parent ba86509804
commit d59dfe9444
5 changed files with 243 additions and 279 deletions

View file

@ -472,136 +472,144 @@ void lcCamera::CopyPosition(const lcCamera* camera)
void lcCamera::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const void lcCamera::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const
{ {
float LineWidth = lcGetPreferences().mLineWidth; lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView);
ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0));
lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView); lcMatrix44 CameraViewMatrix = lcMul(ViewWorldMatrix, lcMul(lcMatrix44Translation(mPosition), ViewMatrix));
lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld); Context->SetWorldViewMatrix(CameraViewMatrix);
float PositionEdge = LC_CAMERA_POSITION_EDGE; float Verts[(12 + 8 + 8 + 3 + 4) * 3];
float PositionLens = LC_CAMERA_POSITION_EDGE * 2; float* CurVert = Verts;
float TargetEdge = LC_CAMERA_TARGET_EDGE;
float Verts[34 + 24 + 4 + 16][3] = float Length = lcLength(mPosition - mTargetPosition);
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE;
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE;
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE;
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE;
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE * 2;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE * 2;
*CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE * 2;
*CurVert++ = LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE; *CurVert++ = -LC_CAMERA_POSITION_EDGE * 2;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE - Length;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = LC_CAMERA_TARGET_EDGE;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = LC_CAMERA_TARGET_EDGE;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = LC_CAMERA_TARGET_EDGE;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = LC_CAMERA_TARGET_EDGE;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = -LC_CAMERA_TARGET_EDGE;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = -LC_CAMERA_TARGET_EDGE;
*CurVert++ = -LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = -LC_CAMERA_TARGET_EDGE;
*CurVert++ = LC_CAMERA_TARGET_EDGE; *CurVert++ = -LC_CAMERA_TARGET_EDGE + 25.0f; *CurVert++ = -LC_CAMERA_TARGET_EDGE;
*CurVert++ = 0.0f; *CurVert++ = 0.0f; *CurVert++ = 0.0f;
*CurVert++ = 0.0f; *CurVert++ = 0.0f; *CurVert++ = -Length;
*CurVert++ = 0.0f; *CurVert++ = 25.0f; *CurVert++ = 0.0f;
const GLushort Indices[40 + 24 + 24 + 4 + 16] =
{ {
{ PositionEdge, PositionEdge, PositionEdge }, { -PositionEdge, PositionEdge, PositionEdge }, 0, 1, 1, 2, 2, 3, 3, 0,
{ -PositionEdge, PositionEdge, PositionEdge }, { -PositionEdge, -PositionEdge, PositionEdge }, 4, 5, 5, 6, 6, 7, 7, 4,
{ -PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, -PositionEdge, PositionEdge }, 0, 4, 1, 5, 2, 6, 3, 7,
{ PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, PositionEdge, PositionEdge }, 8, 9, 9, 10, 10, 11, 11, 8,
{ PositionEdge, PositionEdge, -PositionEdge }, { -PositionEdge, PositionEdge, -PositionEdge }, 8, 28, 9, 28, 10, 28, 11, 28,
{ -PositionEdge, PositionEdge, -PositionEdge }, { -PositionEdge, -PositionEdge, -PositionEdge }, 12, 13, 13, 14, 14, 15, 15, 12,
{ -PositionEdge, -PositionEdge, -PositionEdge }, { PositionEdge, -PositionEdge, -PositionEdge }, 16, 17, 17, 18, 18, 19, 19, 16,
{ PositionEdge, -PositionEdge, -PositionEdge }, { PositionEdge, PositionEdge, -PositionEdge }, 12, 16, 13, 17, 14, 18, 15, 19,
{ PositionEdge, PositionEdge, PositionEdge }, { PositionEdge, PositionEdge, -PositionEdge }, 20, 21, 21, 22, 22, 23, 23, 20,
{ -PositionEdge, PositionEdge, PositionEdge }, { -PositionEdge, PositionEdge, -PositionEdge }, 24, 25, 25, 26, 26, 27, 27, 24,
{ -PositionEdge, -PositionEdge, PositionEdge }, { -PositionEdge, -PositionEdge, -PositionEdge }, 20, 24, 21, 25, 22, 26, 23, 27,
{ PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, -PositionEdge, -PositionEdge }, 28, 29, 28, 30,
{ -PositionEdge, -PositionEdge, -PositionLens }, { -PositionEdge, PositionEdge, -PositionLens }, 31, 32, 32, 33, 33, 34, 34, 31,
{ 0.0f, 0.0f, -PositionEdge }, { -PositionEdge, -PositionEdge, -PositionLens }, 28, 31, 28, 32, 28, 33, 28, 34
{ PositionEdge, -PositionEdge, -PositionLens }, { 0.0f, 0.0f, -PositionEdge },
{ PositionEdge, PositionEdge, -PositionLens }, { PositionEdge, -PositionEdge, -PositionLens },
{ PositionEdge, PositionEdge, -PositionLens }, { -PositionEdge, PositionEdge, -PositionLens },
{ TargetEdge, TargetEdge, TargetEdge }, { -TargetEdge, TargetEdge, TargetEdge },
{ -TargetEdge, TargetEdge, TargetEdge }, { -TargetEdge, -TargetEdge, TargetEdge },
{ -TargetEdge, -TargetEdge, TargetEdge }, { TargetEdge, -TargetEdge, TargetEdge },
{ TargetEdge, -TargetEdge, TargetEdge }, { TargetEdge, TargetEdge, TargetEdge },
{ TargetEdge, TargetEdge, -TargetEdge }, { -TargetEdge, TargetEdge, -TargetEdge },
{ -TargetEdge, TargetEdge, -TargetEdge }, { -TargetEdge, -TargetEdge, -TargetEdge },
{ -TargetEdge, -TargetEdge, -TargetEdge }, { TargetEdge, -TargetEdge, -TargetEdge },
{ TargetEdge, -TargetEdge, -TargetEdge }, { TargetEdge, TargetEdge, -TargetEdge },
{ TargetEdge, TargetEdge, TargetEdge }, { TargetEdge, TargetEdge, -TargetEdge },
{ -TargetEdge, TargetEdge, TargetEdge }, { -TargetEdge, TargetEdge, -TargetEdge },
{ -TargetEdge, -TargetEdge, TargetEdge }, { -TargetEdge, -TargetEdge, -TargetEdge },
{ TargetEdge, -TargetEdge, TargetEdge }, { TargetEdge, -TargetEdge, -TargetEdge },
{ mPosition[0], mPosition[1], mPosition[2] }, { mTargetPosition[0], mTargetPosition[1], mTargetPosition[2] },
{ mPosition[0], mPosition[1], mPosition[2] }, { UpVectorPosition[0], UpVectorPosition[1], UpVectorPosition[2] },
{ 1, 1, 1 }, { -1, 1, 1 },
{ -1, 1, 1 }, { -1, -1, 1 },
{ -1, -1, 1 }, { 1, -1, 1 },
{ 1, -1, 1 }, { 1, 1, 1 },
{ 1, 1, -1 }, { 1, 1, 1 },
{ -1, 1, -1 }, { -1, 1, 1 },
{ -1, -1, -1 }, { -1, -1, 1 },
{ 1, -1, -1 }, { 1, -1, 1 },
}; };
Context->SetWorldViewMatrix(lcMul(ViewWorld, ViewMatrix)); Context->SetVertexBufferPointer(Verts);
Context->SetVertexFormat(0, 3, 0, 0);
if (IsSelected(LC_CAMERA_SECTION_POSITION)) float LineWidth = lcGetPreferences().mLineWidth;
{
Context->SetLineWidth(2.0f * LineWidth); if (!IsSelected())
if (IsFocused(LC_CAMERA_SECTION_POSITION))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{ {
Context->SetLineWidth(LineWidth); Context->SetLineWidth(LineWidth);
lcSetColorCamera(); lcSetColorCamera();
}
glVertexPointer(3, GL_FLOAT, 0, Verts); glDrawElements(GL_LINES, 40 + 24 + 24 + 4, GL_UNSIGNED_SHORT, Indices);
glDrawArrays(GL_LINES, 0, 24);
glDrawArrays(GL_LINE_STRIP, 24, 10);
lcMatrix44 TargetMat = ViewWorld;
TargetMat.SetTranslation(mTargetPosition);
Context->SetWorldViewMatrix(lcMul(TargetMat, ViewMatrix));
if (IsSelected(LC_CAMERA_SECTION_TARGET))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_CAMERA_SECTION_TARGET))
lcSetColorFocused();
else
lcSetColorSelected();
} }
else else
{ {
Context->SetLineWidth(LineWidth); if (IsSelected(LC_CAMERA_SECTION_POSITION))
lcSetColorCamera(); {
} Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_CAMERA_SECTION_POSITION))
glDrawArrays(GL_LINES, 34, 24); lcSetColorFocused();
else
lcMatrix44 UpVectorMat = ViewWorld; lcSetColorSelected();
UpVectorMat.SetTranslation(UpVectorPosition); }
Context->SetWorldViewMatrix(lcMul(UpVectorMat, ViewMatrix));
if (IsSelected(LC_CAMERA_SECTION_UPVECTOR))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_CAMERA_SECTION_UPVECTOR))
lcSetColorFocused();
else else
lcSetColorSelected(); {
} Context->SetLineWidth(LineWidth);
else lcSetColorCamera();
{ }
Context->SetLineWidth(LineWidth);
glDrawElements(GL_LINES, 40, GL_UNSIGNED_SHORT, Indices);
if (IsSelected(LC_CAMERA_SECTION_TARGET))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_CAMERA_SECTION_TARGET))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorCamera();
}
glDrawElements(GL_LINES, 24, GL_UNSIGNED_SHORT, Indices + 40);
if (IsSelected(LC_CAMERA_SECTION_UPVECTOR))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_CAMERA_SECTION_UPVECTOR))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorCamera();
}
glDrawElements(GL_LINES, 24, GL_UNSIGNED_SHORT, Indices + 40 + 24);
lcSetColorCamera(); lcSetColorCamera();
} Context->SetLineWidth(LineWidth);
glDrawArrays(GL_LINES, 34, 24); float SizeY = tanf(LC_DTOR * m_fovy / 2) * Length;
float SizeX = SizeY * 1.333f;
Context->SetWorldViewMatrix(ViewMatrix); *CurVert++ = SizeX; *CurVert++ = SizeY; *CurVert++ = -Length;
*CurVert++ = -SizeX; *CurVert++ = SizeY; *CurVert++ = -Length;
*CurVert++ = -SizeX; *CurVert++ = -SizeY; *CurVert++ = -Length;
*CurVert++ = SizeX; *CurVert++ = -SizeY; *CurVert++ = -Length;
lcSetColorCamera(); glDrawElements(GL_LINES, 4 + 16, GL_UNSIGNED_SHORT, Indices + 40 + 24 + 24);
Context->SetLineWidth(LineWidth);
glDrawArrays(GL_LINES, 34 + 24, 4);
if (IsSelected())
{
float Dist = lcLength(mTargetPosition - mPosition);
lcMatrix44 Projection = lcMatrix44Perspective(m_fovy, 1.33f, 0.01f, Dist);
Projection = lcMatrix44Inverse(Projection);
Context->SetWorldViewMatrix(lcMul(Projection, lcMul(ViewWorld, ViewMatrix)));
glDrawArrays(GL_LINES, 34 + 24 + 4, 16);
} }
} }

View file

@ -288,129 +288,16 @@ void lcLight::UpdatePosition(lcStep Step)
void lcLight::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const void lcLight::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const
{ {
float LineWidth = lcGetPreferences().mLineWidth;
if (IsPointLight()) if (IsPointLight())
{ DrawPointLight(Context, ViewMatrix);
Context->SetWorldViewMatrix(lcMul(lcMatrix44Translation(mPosition), ViewMatrix));
if (IsSelected(LC_LIGHT_SECTION_POSITION))
{
if (IsFocused(LC_LIGHT_SECTION_POSITION))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
lcSetColorLight();
RenderSphere();
}
else else
{ DrawSpotLight(Context, ViewMatrix);
if (IsSelected(LC_LIGHT_SECTION_POSITION))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_LIGHT_SECTION_POSITION))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorLight();
}
RenderCone(Context, ViewMatrix);
if (IsSelected(LC_LIGHT_SECTION_TARGET))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_LIGHT_SECTION_TARGET))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorLight();
}
RenderTarget();
Context->SetWorldViewMatrix(ViewMatrix);
Context->SetLineWidth(LineWidth);
lcSetColorLight();
lcVector3 Line[2] = { mPosition, mTargetPosition };
glVertexPointer(3, GL_FLOAT, 0, Line);
glDrawArrays(GL_LINES, 0, 2);
if (IsSelected())
{
lcMatrix44 ProjectionMatrix, LightMatrix;
lcVector3 FrontVector(mTargetPosition - mPosition);
lcVector3 UpVector(1, 1, 1);
float Length = FrontVector.Length();
if (fabs(FrontVector[0]) < fabs(FrontVector[1]))
{
if (fabs(FrontVector[0]) < fabs(FrontVector[2]))
UpVector[0] = -(UpVector[1] * FrontVector[1] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
else
{
if (fabs(FrontVector[1]) < fabs(FrontVector[2]))
UpVector[1] = -(UpVector[0] * FrontVector[0] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
LightMatrix = lcMatrix44LookAt(mPosition, mTargetPosition, UpVector);
LightMatrix = lcMatrix44AffineInverse(LightMatrix);
ProjectionMatrix = lcMatrix44Perspective(2 * mSpotCutoff, 1.0f, 0.01f, Length);
ProjectionMatrix = lcMatrix44Inverse(ProjectionMatrix);
Context->SetWorldViewMatrix(lcMul(ProjectionMatrix, lcMul(LightMatrix, ViewMatrix)));
// Draw the light cone.
float Verts[16][3] =
{
{ 0.5f, 1.0f, 1.0f },
{ 1.0f, 0.5f, 1.0f },
{ 1.0f, -0.5f, 1.0f },
{ 0.5f, -1.0f, 1.0f },
{ -0.5f, -1.0f, 1.0f },
{ -1.0f, -0.5f, 1.0f },
{ -1.0f, 0.5f, 1.0f },
{ -0.5f, 1.0f, 1.0f },
{ 1.0f, 1.0f, -1.0f },
{ 0.75f, 0.75f, 1.0f },
{ -1.0f, 1.0f, -1.0f },
{ -0.75f, 0.75f, 1.0f },
{ -1.0f, -1.0f, -1.0f },
{ -0.75f, -0.75f, 1.0f },
{ 1.0f, -1.0f, -1.0f },
{ 0.75f, -0.75f, 1.0f }
};
glVertexPointer(3, GL_FLOAT, 0, Verts);
glDrawArrays(GL_LINE_LOOP, 0, 8);
glDrawArrays(GL_LINES, 8, 8);
}
}
} }
void lcLight::RenderCone(lcContext* Context, const lcMatrix44& ViewMatrix) const void lcLight::DrawSpotLight(lcContext* Context, const lcMatrix44& ViewMatrix) const
{ {
lcVector3 FrontVector(mTargetPosition - mPosition); lcVector3 FrontVector(mTargetPosition - mPosition);
lcVector3 UpVector(1, 1, 1); lcVector3 UpVector(1, 1, 1);
float Length = FrontVector.Length();
if (fabs(FrontVector[0]) < fabs(FrontVector[1])) if (fabs(FrontVector[0]) < fabs(FrontVector[1]))
{ {
@ -434,62 +321,121 @@ void lcLight::RenderCone(lcContext* Context, const lcMatrix44& ViewMatrix) const
lcMatrix44 LightViewMatrix = lcMul(LightMatrix, lcMul(lcMatrix44Translation(mPosition), ViewMatrix)); lcMatrix44 LightViewMatrix = lcMul(LightMatrix, lcMul(lcMatrix44Translation(mPosition), ViewMatrix));
Context->SetWorldViewMatrix(LightViewMatrix); Context->SetWorldViewMatrix(LightViewMatrix);
float Edge = LC_LIGHT_POSITION_EDGE; float Verts[(20 + 8 + 2 + 16) * 3];
float verts[16*3]; float* CurVert = Verts;
for (int i = 0; i < 8; i++)
for (int EdgeIdx = 0; EdgeIdx < 8; EdgeIdx++)
{ {
verts[i*6] = verts[i*6+3] = (float)cos((float)i/4 * LC_PI) * Edge; float c = cosf((float)EdgeIdx / 4 * LC_PI) * LC_LIGHT_POSITION_EDGE;
verts[i*6+1] = verts[i*6+4] = (float)sin((float)i/4 * LC_PI) * Edge; float s = sinf((float)EdgeIdx / 4 * LC_PI) * LC_LIGHT_POSITION_EDGE;
verts[i*6+2] = Edge;
verts[i*6+5] = -Edge; *CurVert++ = c;
*CurVert++ = s;
*CurVert++ = LC_LIGHT_POSITION_EDGE;
*CurVert++ = c;
*CurVert++ = s;
*CurVert++ = -LC_LIGHT_POSITION_EDGE;
} }
glVertexPointer(3, GL_FLOAT, 0, verts); *CurVert++ = -12.5f; *CurVert++ = -12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE;
glDrawArrays(GL_LINES, 0, 16); *CurVert++ = 12.5f; *CurVert++ = -12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE;
glVertexPointer(3, GL_FLOAT, 6*sizeof(float), verts); *CurVert++ = 12.5f; *CurVert++ = 12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE;
glDrawArrays(GL_LINE_LOOP, 0, 8); *CurVert++ = -12.5f; *CurVert++ = 12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE;
glVertexPointer(3, GL_FLOAT, 6*sizeof(float), &verts[3]);
glDrawArrays(GL_LINE_LOOP, 0, 8);
float Lines[4][3] = float Length = FrontVector.Length();
*CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE; *CurVert++ = -LC_LIGHT_TARGET_EDGE - Length;
*CurVert++ = 0.0f; *CurVert++ = 0.0f; *CurVert++ = 0.0f;
*CurVert++ = 0.0f; *CurVert++ = 0.0f; *CurVert++ = -Length;
const GLushort Indices[56 + 24 + 2 + 40] =
{ {
{ -12.5f, -12.5f, -Edge }, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
{ 12.5f, -12.5f, -Edge }, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 0,
{ 12.5f, 12.5f, -Edge }, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 1,
{ -12.5f, 12.5f, -Edge } 16, 17, 17, 18, 18, 19, 19, 16,
20, 21, 21, 22, 22, 23, 23, 20,
24, 25, 25, 26, 26, 27, 27, 24,
20, 24, 21, 25, 22, 26, 23, 27,
28, 29,
30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38,
38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 30,
28, 30, 28, 34, 28, 38, 28, 42
}; };
glVertexPointer(3, GL_FLOAT, 0, Lines); Context->SetVertexBufferPointer(Verts);
glDrawArrays(GL_LINE_LOOP, 0, 4); Context->SetVertexFormat(0, 3, 0, 0);
Context->SetWorldViewMatrix(lcMul(lcMatrix44Translation(lcVector3(0, 0, -Length)), LightViewMatrix)); float LineWidth = lcGetPreferences().mLineWidth;
}
void lcLight::RenderTarget() const if (!IsSelected())
{
float Edge = LC_LIGHT_TARGET_EDGE;
float Box[24][3] =
{ {
{ Edge, Edge, Edge }, { -Edge, Edge, Edge }, Context->SetLineWidth(LineWidth);
{ -Edge, Edge, Edge }, { -Edge, -Edge, Edge }, lcSetColorLight();
{ -Edge, -Edge, Edge }, { Edge, -Edge, Edge },
{ Edge, -Edge, Edge }, { Edge, Edge, Edge },
{ Edge, Edge, -Edge }, { -Edge, Edge, -Edge },
{ -Edge, Edge, -Edge }, { -Edge, -Edge, -Edge },
{ -Edge, -Edge, -Edge }, { Edge, -Edge, -Edge },
{ Edge, -Edge, -Edge }, { Edge, Edge, -Edge },
{ Edge, Edge, Edge }, { Edge, Edge, -Edge },
{ -Edge, Edge, Edge }, { -Edge, Edge, -Edge },
{ -Edge, -Edge, Edge }, { -Edge, -Edge, -Edge },
{ Edge, -Edge, Edge }, { Edge, -Edge, -Edge }
};
glVertexPointer(3, GL_FLOAT, 0, Box); glDrawElements(GL_LINES, 56 + 24 + 2, GL_UNSIGNED_SHORT, Indices);
glDrawArrays(GL_LINES, 0, 24); }
else
{
if (IsSelected(LC_LIGHT_SECTION_POSITION))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_LIGHT_SECTION_POSITION))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorLight();
}
glDrawElements(GL_LINES, 56, GL_UNSIGNED_SHORT, Indices);
if (IsSelected(LC_LIGHT_SECTION_TARGET))
{
Context->SetLineWidth(2.0f * LineWidth);
if (IsFocused(LC_LIGHT_SECTION_TARGET))
lcSetColorFocused();
else
lcSetColorSelected();
}
else
{
Context->SetLineWidth(LineWidth);
lcSetColorLight();
}
glDrawElements(GL_LINES, 24, GL_UNSIGNED_SHORT, Indices + 56);
Context->SetLineWidth(LineWidth);
lcSetColorLight();
float Radius = tanf(LC_DTOR * mSpotCutoff) * Length;
for (int EdgeIdx = 0; EdgeIdx < 16; EdgeIdx++)
{
*CurVert++ = cosf((float)EdgeIdx / 16 * LC_2PI) * Radius;
*CurVert++ = sinf((float)EdgeIdx / 16 * LC_2PI) * Radius;
*CurVert++ = -Length;
}
glDrawElements(GL_LINES, 2 + 40, GL_UNSIGNED_SHORT, Indices + 56 + 24);
}
Context->ClearVertexBuffer(); // context remove
} }
void lcLight::RenderSphere() const void lcLight::DrawPointLight(lcContext* Context, const lcMatrix44& ViewMatrix) const
{ {
const int Slices = 6; const int Slices = 6;
const int NumIndices = 3 * Slices + 6 * Slices * (Slices - 2) + 3 * Slices; const int NumIndices = 3 * Slices + 6 * Slices * (Slices - 2) + 3 * Slices;
@ -566,7 +512,17 @@ void lcLight::RenderSphere() const
*Index++ = (Slices - 1) * (Slices - 1) + (Slices - 2) + 1; *Index++ = (Slices - 1) * (Slices - 1) + (Slices - 2) + 1;
*Index++ = (Slices - 1) * (Slices - 1); *Index++ = (Slices - 1) * (Slices - 1);
glVertexPointer(3, GL_FLOAT, 0, Vertices); Context->SetWorldViewMatrix(lcMul(lcMatrix44Translation(mPosition), ViewMatrix));
if (IsFocused(LC_LIGHT_SECTION_POSITION))
lcSetColorFocused();
else if (IsSelected(LC_LIGHT_SECTION_POSITION))
lcSetColorSelected();
else
lcSetColorLight();
Context->SetVertexBufferPointer(Vertices);
Context->SetVertexFormat(0, 3, 0, 0);
glDrawElements(GL_TRIANGLES, NumIndices, GL_UNSIGNED_SHORT, Indices); glDrawElements(GL_TRIANGLES, NumIndices, GL_UNSIGNED_SHORT, Indices);
} }

View file

@ -186,10 +186,6 @@ public:
const char* GetName() const const char* GetName() const
{ return m_strName; } { return m_strName; }
void RenderCone(lcContext* Context, const lcMatrix44& ViewMatrix) const;
void RenderTarget() const;
void RenderSphere() const;
void CompareBoundingBox(float box[6]); void CompareBoundingBox(float box[6]);
void UpdatePosition(lcStep Step); void UpdatePosition(lcStep Step);
void Move(lcStep Step, bool AddKey, const lcVector3& Distance); void Move(lcStep Step, bool AddKey, const lcVector3& Distance);
@ -219,7 +215,9 @@ protected:
void Initialize(const lcVector3& Position, const lcVector3& TargetPosition); void Initialize(const lcVector3& Position, const lcVector3& TargetPosition);
float m_fCone; void DrawPointLight(lcContext* Context, const lcMatrix44& ViewMatrix) const;
void DrawSpotLight(lcContext* Context, const lcMatrix44& ViewMatrix) const;
lcuint32 mState; lcuint32 mState;
char m_strName[81]; char m_strName[81];
}; };

View file

@ -459,8 +459,10 @@ void lcPiece::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) co
else else
lcSetColorSelected(); lcSetColorSelected();
glVertexPointer(3, GL_FLOAT, 0, Verts); Context->SetVertexBufferPointer(Verts);
glDrawArrays(GL_LINES, 0, 48); Context->SetVertexFormat(0, 3, 0, 0);
Context->DrawPrimitives(GL_LINES, 0, 48);
} }
void lcPiece::Move(lcStep Step, bool AddKey, const lcVector3& Distance) void lcPiece::Move(lcStep Step, bool AddKey, const lcVector3& Distance)

View file

@ -1599,7 +1599,7 @@ void View::UpdateTrackTool()
ClosestIntersectionDistance = IntersectionDistance; ClosestIntersectionDistance = IntersectionDistance;
} }
if (CurrentTool == LC_TOOL_SELECT && Proj1 > OverlayRotateArrowStart && Proj1 < OverlayRotateArrowEnd && Proj2 > OverlayRotateArrowStart && Proj2 < OverlayRotateArrowEnd) if (CurrentTool == LC_TOOL_SELECT && Proj1 > OverlayRotateArrowStart && Proj1 < OverlayRotateArrowEnd && Proj2 > OverlayRotateArrowStart && Proj2 < OverlayRotateArrowEnd && mModel->AnyPiecesSelected())
{ {
lcTrackTool PlaneModes[] = { LC_TRACKTOOL_ROTATE_X, LC_TRACKTOOL_ROTATE_Y, LC_TRACKTOOL_ROTATE_Z }; lcTrackTool PlaneModes[] = { LC_TRACKTOOL_ROTATE_X, LC_TRACKTOOL_ROTATE_Y, LC_TRACKTOOL_ROTATE_Z };