Camera.vue 737 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <script setup lang="ts">
  2. import { onMounted, ref } from 'vue'
  3. import { Camera } from '../lmm/core/Camera'
  4. defineProps({
  5. size: {
  6. type: Object,
  7. default: {
  8. width: 1000,
  9. height: 500,
  10. },
  11. },
  12. })
  13. const canvasRef = ref<HTMLCanvasElement>()
  14. /* 相机 */
  15. const camera = new Camera(-100, -20, 0.5)
  16. /* 矩阵测试 */
  17. function matrixTest(ctx: CanvasRenderingContext2D) {
  18. ctx.save()
  19. camera.transformInvert(ctx)
  20. ctx.fillRect(0, 0, 200, 100)
  21. ctx.restore()
  22. }
  23. onMounted(() => {
  24. const canvas = canvasRef.value
  25. const ctx = canvas?.getContext('2d')
  26. ctx && matrixTest(ctx)
  27. })
  28. </script>
  29. <template>
  30. <canvas ref="canvasRef" :width="size.width" :height="size.height"></canvas>
  31. </template>
  32. <style scoped></style>