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 # More simple geometric meshes
21 # Simple flat mesh, sits on the axes X and Z, normal on Y
25 # TODO allow for complex rotation, either at creation or in Actor
27 # Modifier to `texture_coords` to repeat the texture on the X axis
29 # At 1.0, the texture is stretched to cover the whole plane.
30 # If greater than 1.0, the texture is repeated.
32 # This value must be set before using `texture_coords` or drawing this plane.
33 var repeat_x
= 1.0 is writable
35 # Modifier to `texture_coords` to repeat the texture on the Y axis
37 # At 1.0, the texture is stretched to cover the whole plane.
38 # If greater than 1.0, the texture is repeated.
40 # This value must be set before using `texture_coords` or drawing this plane.
41 var repeat_y
= 1.0 is writable
43 redef var vertices
is lazy
do
44 var a
= [-0.5, 0.0, -0.5]
45 var b
= [ 0.5, 0.0, -0.5]
46 var c
= [-0.5, 0.0, 0.5]
47 var d
= [ 0.5, 0.0, 0.5]
49 var vertices
= new Array[Float]
50 for v
in [c
, d
, a
, b
] do vertices
.add_all v
54 redef var normals
: Array[Float] is lazy
do
55 var normals
= new Array[Float]
56 for i
in 4.times
do normals
.add_all
([0.0, 1.0, 0.0])
60 redef var texture_coords
: Array[Float] is lazy
do
63 var offset_right
= 1.0*repeat_x
64 var offset_bottom
= 1.0*repeat_y
65 var a
= [offset_left
, offset_bottom
]
66 var b
= [offset_right
, offset_bottom
]
67 var c
= [offset_left
, offset_top
]
68 var d
= [offset_right
, offset_top
]
70 var texture_coords
= new Array[Float]
71 for v
in [c
, d
, a
, b
] do texture_coords
.add_all v
75 redef var center
= new Point3d[Float](0.0, 0.0, 0.0) is lazy
77 init do indices
.add_all
([0, 1, 2, 2, 1, 3])
78 # TODO use gl_TRIANGLE_FAN instead
85 redef var vertices
is lazy
do
86 var a
= [-0.5, -0.5, -0.5]
87 var b
= [ 0.5, -0.5, -0.5]
88 var c
= [-0.5, 0.5, -0.5]
89 var d
= [ 0.5, 0.5, -0.5]
91 var e
= [-0.5, -0.5, 0.5]
92 var f
= [ 0.5, -0.5, 0.5]
93 var g
= [-0.5, 0.5, 0.5]
94 var h
= [ 0.5, 0.5, 0.5]
96 var vertices
= new Array[Float]
97 for v
in [a
, c
, d
, a
, d
, b
, # front
98 f
, h
, g
, f
, g
, e
, # back
99 b
, d
, h
, b
, h
, f
, # right
100 e
, g
, c
, e
, c
, a
, # left
101 e
, a
, b
, e
, b
, f
, # bottom
102 c
, g
, h
, c
, h
, d
# top
103 ] do vertices
.add_all v
107 redef var normals
is lazy
do
108 var normals
= new Array[Float]
109 var faces_normals
= [
116 for f
in faces_normals
do for i
in 6.times
do normals
.add_all f
120 redef var texture_coords
: Array[Float] is lazy
do
126 var texture_coords
= new Array[Float]
127 for v
in [c
, d
, a
, a
, d
, b
] do for i
in 6.times
do texture_coords
.add_all v
128 return texture_coords
131 redef var center
= new Point3d[Float](0.0, 0.0, 0.0) is lazy