fe3f9df821da2c67db5d57130b6a0bfcb221b896
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 redef var vertices
is lazy
do
28 var a
= [-0.5, 0.0, -0.5]
29 var b
= [ 0.5, 0.0, -0.5]
30 var c
= [-0.5, 0.0, 0.5]
31 var d
= [ 0.5, 0.0, 0.5]
33 var vertices
= new Array[Float]
34 for v
in [c
, d
, a
, b
] do vertices
.add_all v
38 redef var normals
: Array[Float] is lazy
do
39 var normals
= new Array[Float]
40 for i
in 4.times
do normals
.add_all
([0.0, 1.0, 0.0])
44 redef var texture_coords
: Array[Float] is lazy
do
47 var offset_right
= 1.0
48 var offset_bottom
= 1.0
49 var a
= [offset_left
, offset_bottom
]
50 var b
= [offset_right
, offset_bottom
]
51 var c
= [offset_left
, offset_top
]
52 var d
= [offset_right
, offset_top
]
54 var texture_coords
= new Array[Float]
55 for v
in [c
, d
, a
, b
] do texture_coords
.add_all v
59 redef var center
= new Point3d[Float](0.0, 0.0, 0.0) is lazy
61 init do indices
.add_all
([0, 1, 2, 2, 1, 3])
62 # TODO use gl_TRIANGLE_FAN instead
69 redef var vertices
is lazy
do
70 var a
= [-0.5, -0.5, -0.5]
71 var b
= [ 0.5, -0.5, -0.5]
72 var c
= [-0.5, 0.5, -0.5]
73 var d
= [ 0.5, 0.5, -0.5]
75 var e
= [-0.5, -0.5, 0.5]
76 var f
= [ 0.5, -0.5, 0.5]
77 var g
= [-0.5, 0.5, 0.5]
78 var h
= [ 0.5, 0.5, 0.5]
80 var vertices
= new Array[Float]
81 for v
in [a
, c
, d
, a
, d
, b
, # front
82 f
, h
, g
, f
, g
, e
, # back
83 b
, d
, h
, b
, h
, f
, # right
84 e
, g
, c
, e
, c
, a
, # left
85 e
, a
, b
, e
, b
, f
, # bottom
86 c
, g
, h
, c
, h
, d
# top
87 ] do vertices
.add_all v
91 redef var normals
is lazy
do
92 var normals
= new Array[Float]
100 for f
in faces_normals
do for i
in 6.times
do normals
.add_all f
104 redef var texture_coords
: Array[Float] is lazy
do
110 var texture_coords
= new Array[Float]
111 for v
in [c
, d
, a
, a
, d
, b
] do for i
in 6.times
do texture_coords
.add_all v
112 return texture_coords
115 redef var center
= new Point3d[Float](0.0, 0.0, 0.0) is lazy