| 1454 | } |
| 1455 | |
| 1456 | Matrix Renderer::GetWorldMatrixForSprite(const RendererSpriteToDraw& sprite, RenderView& view) |
| 1457 | { |
| 1458 | auto spriteMatrix = Matrix::Identity; |
| 1459 | auto scaleMatrix = Matrix::CreateScale(sprite.Width * sprite.Scale, sprite.Height * sprite.Scale, sprite.Scale); |
| 1460 | |
| 1461 | auto spritePos = sprite.pos; |
| 1462 | |
| 1463 | if (sprite.Type == SpriteType::ThreeD) |
| 1464 | { |
| 1465 | ReflectMatrixOptionally(spriteMatrix); |
| 1466 | } |
| 1467 | else |
| 1468 | { |
| 1469 | ReflectVectorOptionally(spritePos); |
| 1470 | } |
| 1471 | |
| 1472 | switch (sprite.Type) |
| 1473 | { |
| 1474 | case SpriteType::Billboard: |
| 1475 | { |
| 1476 | auto cameraUp = Vector3(view.Camera.View._12, view.Camera.View._22, view.Camera.View._32); |
| 1477 | spriteMatrix = scaleMatrix * Matrix::CreateRotationZ(sprite.Rotation) * Matrix::CreateBillboard(spritePos, Camera.pos.ToVector3(), cameraUp); |
| 1478 | } |
| 1479 | break; |
| 1480 | |
| 1481 | case SpriteType::CustomBillboard: |
| 1482 | { |
| 1483 | auto rotMatrix = Matrix::CreateRotationY(sprite.Rotation); |
| 1484 | auto quadForward = Vector3(0.0f, 0.0f, 1.0f); |
| 1485 | spriteMatrix = scaleMatrix * Matrix::CreateConstrainedBillboard( |
| 1486 | spritePos, |
| 1487 | Camera.pos.ToVector3(), |
| 1488 | sprite.ConstrainAxis, |
| 1489 | nullptr, |
| 1490 | &quadForward); |
| 1491 | } |
| 1492 | break; |
| 1493 | |
| 1494 | case SpriteType::LookAtBillboard: |
| 1495 | { |
| 1496 | auto translationMatrix = Matrix::CreateTranslation(spritePos); |
| 1497 | auto rotMatrix = Matrix::CreateRotationZ(sprite.Rotation) * Matrix::CreateLookAt(Vector3::Zero, sprite.LookAtAxis, Vector3::UnitZ); |
| 1498 | spriteMatrix = scaleMatrix * rotMatrix * translationMatrix; |
| 1499 | } |
| 1500 | break; |
| 1501 | |
| 1502 | case SpriteType::ThreeD: |
| 1503 | default: |
| 1504 | break; |
| 1505 | } |
| 1506 | |
| 1507 | return spriteMatrix; |
| 1508 | } |
| 1509 | |
| 1510 | void Renderer::DrawEffect(RenderView& view, RendererEffect* effect, RendererPass rendererPass) |
| 1511 | { |