1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Cache the `Matrix` produced by `Camera::mvp_matrix`
21 private var mvp_matrix_cache
: nullable Matrix = null
23 private var position_cache
= new Point3d[Float](0.0, 0.0, 0.0)
25 # Has `position` changed from `position_cache`? Update the cache at the same time
26 private fun check_position_changed
: Bool
28 if position
.x
!= position_cache
.x
or
29 position
.y
!= position_cache
.y
or
30 position
.z
!= position_cache
.z
then
31 position_cache
.x
= position
.x
32 position_cache
.y
= position
.y
33 position_cache
.z
= position
.z
40 redef class EulerCamera
41 # The returned matrix must not be modified as it is cached.
44 var m
= mvp_matrix_cache
45 if m
== null or check_position_changed
then
52 redef fun pitch
=(value
)
55 mvp_matrix_cache
= null
61 mvp_matrix_cache
= null
64 redef fun roll
=(value
)
67 mvp_matrix_cache
= null
70 redef fun field_of_view_y
=(value
)
73 mvp_matrix_cache
= null
76 redef fun near
=(value
)
79 mvp_matrix_cache
= null
85 mvp_matrix_cache
= null
90 # The returned matrix must not be modified as it is cached.
93 var m
= mvp_matrix_cache
94 if m
== null or check_position_changed
then
101 redef fun near
=(value
)
104 mvp_matrix_cache
= null
107 redef fun far
=(value
)
110 mvp_matrix_cache
= null
113 redef fun height
=(value
)
116 mvp_matrix_cache
= null