Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F8725460
FROG_Primitives.cpp
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
FROG_Primitives.cpp
View Options
#include
"FROG_Primitives.h"
#ifdef FROG_OPENGL
void
SetNormalArray
(
GLfloat
*
VerticesArray
,
GLfloat
*
NormalsArray
,
unsigned
int
FirstVertex
,
unsigned
int
NVertices
,
unsigned
int
PolygonSideCount
){
for
(
unsigned
int
i
=
0
;
i
<
NVertices
/
PolygonSideCount
;
i
++
){
unsigned
int
offset
=
(
FirstVertex
+
i
*
PolygonSideCount
)
*
3
;
//unsigned int offset = FirstVertex + i*PolygonSideCount*3;
float
NX
=
0
,
NY
=
0
,
NZ
=
0
;
if
(
PolygonSideCount
>=
3
){
float
&
C1X
=
VerticesArray
[
offset
+
0
];
float
&
C1Y
=
VerticesArray
[
offset
+
1
];
float
&
C1Z
=
VerticesArray
[
offset
+
2
];
float
&
C2X
=
VerticesArray
[
offset
+
3
];
float
&
C2Y
=
VerticesArray
[
offset
+
4
];
float
&
C2Z
=
VerticesArray
[
offset
+
5
];
float
&
C3X
=
VerticesArray
[
offset
+
6
];
float
&
C3Y
=
VerticesArray
[
offset
+
7
];
float
&
C3Z
=
VerticesArray
[
offset
+
8
];
NX
=
(
C1Y
-
C2Y
)
*
(
C2Z
-
C3Z
)
-
(
C1Z
-
C2Z
)
*
(
C2Y
-
C3Y
);
NY
=
(
C1Z
-
C2Z
)
*
(
C2X
-
C3X
)
-
(
C1X
-
C2X
)
*
(
C2Z
-
C3Z
);
NZ
=
(
C1X
-
C2X
)
*
(
C2Y
-
C3Y
)
-
(
C1Y
-
C2Y
)
*
(
C2X
-
C3X
);
float
N
=
sqrt
(
NX
*
NX
+
NY
*
NY
+
NZ
*
NZ
);
NX
/=
N
;
NY
/=
N
;
NZ
/=
N
;
}
for
(
unsigned
int
j
=
0
;
j
<
PolygonSideCount
;
j
++
){
NormalsArray
[
offset
+
3
*
j
+
0
]
=
NX
;
NormalsArray
[
offset
+
3
*
j
+
1
]
=
NY
;
NormalsArray
[
offset
+
3
*
j
+
2
]
=
NZ
;
}
}
}
void
TransformVerticesArray
(
GLfloat
*
VerticesArray
,
unsigned
int
NVertices
){
GLfloat
m
[
16
];
glGetFloatv
(
GL_MODELVIEW_MATRIX
,
m
);
for
(
unsigned
int
i
=
0
;
i
<
NVertices
;
i
++
){
unsigned
int
offset
=
i
*
3
;
float
A
=
m
[
0
]
*
VerticesArray
[
offset
+
0
]
+
m
[
4
]
*
VerticesArray
[
offset
+
1
]
+
m
[
8
]
*
VerticesArray
[
offset
+
2
]
+
m
[
12
]
*
1.0f
;
float
B
=
m
[
1
]
*
VerticesArray
[
offset
+
0
]
+
m
[
5
]
*
VerticesArray
[
offset
+
1
]
+
m
[
9
]
*
VerticesArray
[
offset
+
2
]
+
m
[
13
]
*
1.0f
;
float
C
=
m
[
2
]
*
VerticesArray
[
offset
+
0
]
+
m
[
6
]
*
VerticesArray
[
offset
+
1
]
+
m
[
10
]
*
VerticesArray
[
offset
+
2
]
+
m
[
14
]
*
1.0f
;
VerticesArray
[
offset
+
0
]
=
A
;
VerticesArray
[
offset
+
1
]
=
B
;
VerticesArray
[
offset
+
2
]
=
C
;
}
}
void
GetVerticesArrayBarycenter
(
GLfloat
*
VerticesArray
,
unsigned
int
NVertices
,
float
&
x
,
float
&
y
,
float
&
z
){
x
=
0
;
y
=
0
;
z
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
NVertices
;
i
++
){
x
+=
VerticesArray
[
3
*
i
+
0
];
y
+=
VerticesArray
[
3
*
i
+
1
];
z
+=
VerticesArray
[
3
*
i
+
2
];
}
x
/=
NVertices
;
y
/=
NVertices
;
z
/=
NVertices
;
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Jan 21, 1:44 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4243491
Default Alt Text
FROG_Primitives.cpp (2 KB)
Attached To
rFROGSVN frogsvn
Event Timeline
Log In to Comment