Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labs_ihm_2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
julien.dasilva
labs_ihm_2020
Commits
08efe0b9
Commit
08efe0b9
authored
4 years ago
by
julien.dasilva
Browse files
Options
Downloads
Patches
Plain Diff
modif normals lab3
parent
b71bb1dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab3/src/lab3.js
+73
-46
73 additions, 46 deletions
lab3/src/lab3.js
with
73 additions
and
46 deletions
lab3/src/lab3.js
+
73
−
46
View file @
08efe0b9
...
@@ -158,6 +158,31 @@ function getStorageLocation(gl, name) {
...
@@ -158,6 +158,31 @@ function getStorageLocation(gl, name) {
return
storageLocation
return
storageLocation
}
}
function
subtractArrays
(
array1
,
array2
)
{
result
=
[]
for
(
let
i
=
0
;
i
<
array1
.
length
;
i
++
){
result
.
push
(
array1
[
i
]
-
array2
[
i
]);
}
return
result
;
}
function
calcNormal
(
vertices
,
normals
,
indices
)
{
for
(
let
i
=
0
;
i
<
indices
.
length
;
i
+=
3
)
{
let
A
=
[
vertices
[
indices
[
i
]
*
3
],
vertices
[
indices
[
i
]
*
3
+
1
],
vertices
[
indices
[
i
]
*
3
+
2
]];
let
B
=
[
vertices
[
indices
[
i
+
1
]
*
3
],
vertices
[
indices
[
i
+
1
]
*
3
+
1
],
vertices
[
indices
[
i
+
1
]
*
3
+
2
]];
let
C
=
[
vertices
[
indices
[
i
+
2
]
*
3
],
vertices
[
indices
[
i
+
2
]
*
3
+
1
],
vertices
[
indices
[
i
+
2
]
*
3
+
2
]];
let
U
=
subtractArrays
(
B
,
A
);
let
V
=
subtractArrays
(
C
,
A
);
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
normals
[
indices
[
i
+
j
]
*
3
]
=
(
U
[
1
]
*
V
[
2
]
-
U
[
2
]
*
V
[
1
]);
normals
[
indices
[
i
+
j
]
*
3
+
1
]
=
(
U
[
2
]
*
V
[
0
]
-
U
[
0
]
*
V
[
2
]);
normals
[
indices
[
i
+
j
]
*
3
+
2
]
=
(
U
[
0
]
*
V
[
1
]
-
U
[
1
]
*
V
[
0
]);
}
}
}
function
initVertexBuffers
(
gl
)
{
function
initVertexBuffers
(
gl
)
{
// This is the model
// This is the model
let
vertices
=
new
Float32Array
([
let
vertices
=
new
Float32Array
([
...
@@ -258,79 +283,81 @@ function initVertexBuffers(gl) {
...
@@ -258,79 +283,81 @@ function initVertexBuffers(gl) {
let
normals
=
new
Float32Array
([
let
normals
=
new
Float32Array
([
//Grande base
//Grande base
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
//Petite base
//Petite base
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
//Face arrière
//Face arrière
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
//Face gauche
//Face gauche
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
//Face droite
//Face droite
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
//Face avant
//Face avant
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
-
1
.0
,
0.0
,
0.0
,
0
.0
,
//Plain
//Plain
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
,
0.0
,
0
.0
,
0.0
,
0.0
,
1
.0
,
0.0
0.0
,
0
.0
,
0.0
]);
]);
let
indices
=
new
Uint8Array
([
let
indices
=
new
Uint8Array
([
0
,
1
,
2
,
//Grande base
0
,
2
,
1
,
//Grande base
1
,
2
,
3
,
2
,
3
,
1
,
4
,
5
,
6
,
//Petite base
4
,
5
,
6
,
//Petite base
5
,
6
,
7
,
5
,
7
,
6
,
8
,
9
,
10
,
//Face arrière
8
,
10
,
9
,
//Face arrière
9
,
10
,
11
,
10
,
11
,
9
,
10
,
1
1
,
1
2
,
10
,
1
2
,
1
1
,
13
,
14
,
15
,
//Face gauche
13
,
14
,
15
,
//Face gauche
14
,
1
5
,
1
6
,
14
,
1
6
,
1
5
,
15
,
16
,
17
,
16
,
17
,
15
,
18
,
19
,
20
,
//Face droite
18
,
19
,
20
,
//Face droite
19
,
2
0
,
2
1
,
19
,
2
1
,
2
0
,
20
,
21
,
22
,
21
,
22
,
20
,
23
,
24
,
25
,
//Face avant
23
,
24
,
25
,
//Face avant
24
,
2
5
,
2
6
,
24
,
2
6
,
2
5
,
25
,
26
,
27
,
26
,
27
,
25
,
28
,
29
,
30
,
//Plain
28
,
29
,
30
,
//Plain
29
,
3
0
,
3
1
29
,
3
1
,
3
0
]);
]);
calcNormal
(
vertices
,
normals
,
indices
);
// Create a buffer object
// Create a buffer object
const
vertexBuffer
=
gl
.
createBuffer
();
const
vertexBuffer
=
gl
.
createBuffer
();
if
(
!
vertexBuffer
)
{
if
(
!
vertexBuffer
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment