diff --git a/common/camera.cpp b/common/camera.cpp index f77d06b8..e5dbdc37 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -472,136 +472,144 @@ void lcCamera::CopyPosition(const lcCamera* camera) 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); - lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld); + lcMatrix44 CameraViewMatrix = lcMul(ViewWorldMatrix, lcMul(lcMatrix44Translation(mPosition), ViewMatrix)); + Context->SetWorldViewMatrix(CameraViewMatrix); - float PositionEdge = LC_CAMERA_POSITION_EDGE; - float PositionLens = LC_CAMERA_POSITION_EDGE * 2; - float TargetEdge = LC_CAMERA_TARGET_EDGE; + float Verts[(12 + 8 + 8 + 3 + 4) * 3]; + float* CurVert = Verts; - 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 }, - { -PositionEdge, PositionEdge, PositionEdge }, { -PositionEdge, -PositionEdge, PositionEdge }, - { -PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, -PositionEdge, PositionEdge }, - { PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, PositionEdge, PositionEdge }, - { PositionEdge, PositionEdge, -PositionEdge }, { -PositionEdge, PositionEdge, -PositionEdge }, - { -PositionEdge, PositionEdge, -PositionEdge }, { -PositionEdge, -PositionEdge, -PositionEdge }, - { -PositionEdge, -PositionEdge, -PositionEdge }, { PositionEdge, -PositionEdge, -PositionEdge }, - { PositionEdge, -PositionEdge, -PositionEdge }, { PositionEdge, PositionEdge, -PositionEdge }, - { PositionEdge, PositionEdge, PositionEdge }, { PositionEdge, PositionEdge, -PositionEdge }, - { -PositionEdge, PositionEdge, PositionEdge }, { -PositionEdge, PositionEdge, -PositionEdge }, - { -PositionEdge, -PositionEdge, PositionEdge }, { -PositionEdge, -PositionEdge, -PositionEdge }, - { PositionEdge, -PositionEdge, PositionEdge }, { PositionEdge, -PositionEdge, -PositionEdge }, - { -PositionEdge, -PositionEdge, -PositionLens }, { -PositionEdge, PositionEdge, -PositionLens }, - { 0.0f, 0.0f, -PositionEdge }, { -PositionEdge, -PositionEdge, -PositionLens }, - { 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 }, + 0, 1, 1, 2, 2, 3, 3, 0, + 4, 5, 5, 6, 6, 7, 7, 4, + 0, 4, 1, 5, 2, 6, 3, 7, + 8, 9, 9, 10, 10, 11, 11, 8, + 8, 28, 9, 28, 10, 28, 11, 28, + 12, 13, 13, 14, 14, 15, 15, 12, + 16, 17, 17, 18, 18, 19, 19, 16, + 12, 16, 13, 17, 14, 18, 15, 19, + 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, 28, 30, + 31, 32, 32, 33, 33, 34, 34, 31, + 28, 31, 28, 32, 28, 33, 28, 34 }; - Context->SetWorldViewMatrix(lcMul(ViewWorld, ViewMatrix)); + Context->SetVertexBufferPointer(Verts); + Context->SetVertexFormat(0, 3, 0, 0); - if (IsSelected(LC_CAMERA_SECTION_POSITION)) - { - Context->SetLineWidth(2.0f * LineWidth); - if (IsFocused(LC_CAMERA_SECTION_POSITION)) - lcSetColorFocused(); - else - lcSetColorSelected(); - } - else + float LineWidth = lcGetPreferences().mLineWidth; + + if (!IsSelected()) { Context->SetLineWidth(LineWidth); lcSetColorCamera(); - } - glVertexPointer(3, GL_FLOAT, 0, Verts); - 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(); + glDrawElements(GL_LINES, 40 + 24 + 24 + 4, GL_UNSIGNED_SHORT, Indices); } else { - Context->SetLineWidth(LineWidth); - lcSetColorCamera(); - } - - glDrawArrays(GL_LINES, 34, 24); - - lcMatrix44 UpVectorMat = ViewWorld; - 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(); + if (IsSelected(LC_CAMERA_SECTION_POSITION)) + { + Context->SetLineWidth(2.0f * LineWidth); + if (IsFocused(LC_CAMERA_SECTION_POSITION)) + lcSetColorFocused(); + else + lcSetColorSelected(); + } else - lcSetColorSelected(); - } - else - { - Context->SetLineWidth(LineWidth); + { + Context->SetLineWidth(LineWidth); + lcSetColorCamera(); + } + + 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(); - } + 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(); - 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); + glDrawElements(GL_LINES, 4 + 16, GL_UNSIGNED_SHORT, Indices + 40 + 24 + 24); } } diff --git a/common/light.cpp b/common/light.cpp index fefeb3f3..8987a3d0 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -288,129 +288,16 @@ void lcLight::UpdatePosition(lcStep Step) void lcLight::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const { - float LineWidth = lcGetPreferences().mLineWidth; - if (IsPointLight()) - { - Context->SetWorldViewMatrix(lcMul(lcMatrix44Translation(mPosition), ViewMatrix)); - - if (IsSelected(LC_LIGHT_SECTION_POSITION)) - { - if (IsFocused(LC_LIGHT_SECTION_POSITION)) - lcSetColorFocused(); - else - lcSetColorSelected(); - } - else - lcSetColorLight(); - - RenderSphere(); - } + DrawPointLight(Context, ViewMatrix); 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(); - } - - 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); - } - } + DrawSpotLight(Context, ViewMatrix); } -void lcLight::RenderCone(lcContext* Context, const lcMatrix44& ViewMatrix) const +void lcLight::DrawSpotLight(lcContext* Context, const lcMatrix44& ViewMatrix) const { lcVector3 FrontVector(mTargetPosition - mPosition); lcVector3 UpVector(1, 1, 1); - float Length = FrontVector.Length(); 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)); Context->SetWorldViewMatrix(LightViewMatrix); - float Edge = LC_LIGHT_POSITION_EDGE; - float verts[16*3]; - for (int i = 0; i < 8; i++) + float Verts[(20 + 8 + 2 + 16) * 3]; + float* CurVert = Verts; + + for (int EdgeIdx = 0; EdgeIdx < 8; EdgeIdx++) { - verts[i*6] = verts[i*6+3] = (float)cos((float)i/4 * LC_PI) * Edge; - verts[i*6+1] = verts[i*6+4] = (float)sin((float)i/4 * LC_PI) * Edge; - verts[i*6+2] = Edge; - verts[i*6+5] = -Edge; + float c = cosf((float)EdgeIdx / 4 * LC_PI) * LC_LIGHT_POSITION_EDGE; + float s = sinf((float)EdgeIdx / 4 * LC_PI) * LC_LIGHT_POSITION_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); - glDrawArrays(GL_LINES, 0, 16); - glVertexPointer(3, GL_FLOAT, 6*sizeof(float), verts); - glDrawArrays(GL_LINE_LOOP, 0, 8); - glVertexPointer(3, GL_FLOAT, 6*sizeof(float), &verts[3]); - glDrawArrays(GL_LINE_LOOP, 0, 8); + *CurVert++ = -12.5f; *CurVert++ = -12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE; + *CurVert++ = 12.5f; *CurVert++ = -12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE; + *CurVert++ = 12.5f; *CurVert++ = 12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE; + *CurVert++ = -12.5f; *CurVert++ = 12.5f; *CurVert++ = -LC_LIGHT_POSITION_EDGE; - 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 }, - { 12.5f, -12.5f, -Edge }, - { 12.5f, 12.5f, -Edge }, - { -12.5f, 12.5f, -Edge } + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 0, + 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 1, + 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); - glDrawArrays(GL_LINE_LOOP, 0, 4); + Context->SetVertexBufferPointer(Verts); + Context->SetVertexFormat(0, 3, 0, 0); - Context->SetWorldViewMatrix(lcMul(lcMatrix44Translation(lcVector3(0, 0, -Length)), LightViewMatrix)); -} + float LineWidth = lcGetPreferences().mLineWidth; -void lcLight::RenderTarget() const -{ - float Edge = LC_LIGHT_TARGET_EDGE; - - float Box[24][3] = + if (!IsSelected()) { - { 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 }, - { -Edge, -Edge, Edge }, { -Edge, -Edge, -Edge }, - { Edge, -Edge, Edge }, { Edge, -Edge, -Edge } - }; + Context->SetLineWidth(LineWidth); + lcSetColorLight(); - glVertexPointer(3, GL_FLOAT, 0, Box); - glDrawArrays(GL_LINES, 0, 24); + glDrawElements(GL_LINES, 56 + 24 + 2, GL_UNSIGNED_SHORT, Indices); + } + 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 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); - 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); } diff --git a/common/light.h b/common/light.h index b93b1794..a471a694 100644 --- a/common/light.h +++ b/common/light.h @@ -186,10 +186,6 @@ public: const char* GetName() const { return m_strName; } - void RenderCone(lcContext* Context, const lcMatrix44& ViewMatrix) const; - void RenderTarget() const; - void RenderSphere() const; - void CompareBoundingBox(float box[6]); void UpdatePosition(lcStep Step); void Move(lcStep Step, bool AddKey, const lcVector3& Distance); @@ -219,7 +215,9 @@ protected: 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; char m_strName[81]; }; diff --git a/common/piece.cpp b/common/piece.cpp index 9a077f9e..be215fab 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -459,8 +459,10 @@ void lcPiece::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) co else lcSetColorSelected(); - glVertexPointer(3, GL_FLOAT, 0, Verts); - glDrawArrays(GL_LINES, 0, 48); + Context->SetVertexBufferPointer(Verts); + Context->SetVertexFormat(0, 3, 0, 0); + + Context->DrawPrimitives(GL_LINES, 0, 48); } void lcPiece::Move(lcStep Step, bool AddKey, const lcVector3& Distance) diff --git a/common/view.cpp b/common/view.cpp index 5616a420..cad97f44 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -1599,7 +1599,7 @@ void View::UpdateTrackTool() 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 };