protected override void Draw(GameTime gameTime)
{
PuzzleState currentState;
bool solved;
lock (_lockObject)
{
if (_showSolverProgress && !_solved && _solverState != null)
{
_puzzleState = _solverState;
}
currentState = _puzzleState;
solved = _solved;
}
if (solved)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
}
else
{
graphics.GraphicsDevice.Clear(Color.Black);
}
//_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone);
//int buttonTop = GraphicsDevice.Viewport.Width - 80;
//_spriteBatch.DrawString(_spriteFont, "Prev", new Vector2(buttonTop, 0), Color.Black, -MathHelper.PiOver2, Vector2.Zero, 1f, SpriteEffects.None, 0);
//_spriteBatch.End();
GraphicsDevice.SetVertexBuffer(boxVB);
GraphicsDevice.Indices = boxIB;
//var min = ToVector(currentState.MinBounds);
//var max = ToVector(currentState.MaxBounds);
//var center = (max + min) / 2;
//modelPosition = -center;
foreach (var piece in currentState.Pieces)
{
if (!_pieceVisibility[piece.Piece.Name])
{
continue;
}
Vector3 pieceColor = new Vector3(0, 0, 0);
if (piece.Piece.Name == "Orange")
{
pieceColor = RGB(255, 140, 0);
}
else if (piece.Piece.Name == "Blue")
{
pieceColor = RGB(0, 0, 255);
}
else if (piece.Piece.Name == "Yellow")
{
pieceColor = RGB(255, 255, 0);
}
else if (piece.Piece.Name == "Red")
{
pieceColor = RGB(255, 0, 0);
}
else if (piece.Piece.Name == "Green")
{
pieceColor = RGB(0, 255, 0);
}
else if (piece.Piece.Name == "Purple")
{
pieceColor = RGB(160, 32, 240);
}
foreach (var point in piece.CurrentPoints)
{
Vector3 pointPosition = ToVector(point);
if (_puzzlePiecesMoving.Contains(piece.Piece))
{
pointPosition += ToVector(_puzzleAnimationDirection) * _animationPercent;
}
//effect.World = Matrix.CreateFromYawPitchRoll(rectangleAngle,
// rectangleAngle, rectangleAngle) * rectangleTransform;
effect.World = Matrix.CreateTranslation(pointPosition) *
Matrix.CreateTranslation(modelPosition) *
rotationMatrix;
#if WINDOWS_PHONE || ANDROID || IOS
Vector3 upViewVector = Vector3.Right;
#else
Vector3 upViewVector = Vector3.Up;
#endif
effect.View = Matrix.CreateLookAt(cameraPosition,
Vector3.Zero, upViewVector);
//effect.View = Matrix.CreateLookAt(cameraPosition,
// modelPosition, Vector3.Up);
//effect.Projection = Matrix.CreatePerspectiveFieldOfView(
// MathHelper.ToRadians(45.0f), aspectRatio,
// 1.0f, 10000.0f);
effect.AmbientLightColor = pieceColor * 0.2f;
//effect.DiffuseColor = new Vector3(.5f, 0, 0);
effect.LightingEnabled = true;
//if (solved)
{
effect.DirectionalLight0.Enabled = true;
effect.DirectionalLight1.Enabled = true;
effect.DirectionalLight2.Enabled = true;
}
//effect.DirectionalLight0.DiffuseColor = pieceColor * 0.8f;
//effect.DirectionalLight1.DiffuseColor = pieceColor * new Vector3(0.8f, 0.6f, 0.6f);
//effect.DirectionalLight2.DiffuseColor = pieceColor * new Vector3(0.6f, 0.8f, 0.8f);
effect.DirectionalLight0.DiffuseColor = pieceColor * 0.8f;
effect.DirectionalLight1.DiffuseColor = pieceColor * 0.8f;
effect.DirectionalLight2.DiffuseColor = pieceColor * 0.8f;
//effect.DirectionalLight0.Direction = Vector3.Down;
//effect.DirectionalLight1.Direction = Vector3.Normalize(Vector3.Right + Vector3.Up + Vector3.Forward);
//effect.DirectionalLight2.Direction = Vector3.Normalize(Vector3.Left + Vector3.Up + Vector3.Forward);
effect.DirectionalLight0.Direction = Vector3.Normalize(Vector3.Forward + Vector3.Left + Vector3.Down);
effect.DirectionalLight1.Direction = Vector3.Normalize(Vector3.Right + Vector3.Up);
effect.DirectionalLight2.Direction = Vector3.Normalize(Vector3.Left + Vector3.Down);
effect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 24, 0, 12);
}
}
base.Draw(gameTime);
}