-
Notifications
You must be signed in to change notification settings - Fork 9
/
projection.dart
49 lines (43 loc) · 1.23 KB
/
projection.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'package:flutter/material.dart';
import 'package:flutter_3d_raycast_engine/configurations.dart';
import 'package:flutter_3d_raycast_engine/helpers.dart';
class Projection {
const Projection({
required this.materialIndex,
required this.depth,
required this.wallHeight,
required this.textureOffset,
required this.isVertical,
});
final int materialIndex;
final double depth;
final double wallHeight;
final double textureOffset;
final bool isVertical;
void draw(
Canvas canvas,
double offset, {
required bool enableTexture,
}) {
const maxDepth = mapScale * mapSize + epsilon;
final shadedColor = getColorBasedOnDepth(
color: Colors.grey[isVertical ? 100 : 400]!,
depth: depth,
maxDepth: maxDepth,
);
final sourceRect =
Rect.fromLTWH(textureOffset % textureScale, 0, 1, textureScale);
final destinationRect =
Rect.fromLTWH(offset, (height - wallHeight) / 2, 1, wallHeight);
canvas.drawImageRect(
materials[materialIndex].image!,
sourceRect,
destinationRect,
Paint()
..colorFilter = ColorFilter.mode(
shadedColor,
enableTexture ? BlendMode.modulate : BlendMode.src,
),
);
}
}