| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-additional-options "-Ofast" } */ |
| 3 |
/* { dg-additional-options "-march=bdver2" { target x86_64-*-* i?86-*-* } } */ |
| 4 |
|
| 5 |
template <class T> struct Vector3 { |
| 6 |
Vector3(); |
| 7 |
Vector3(T, T, T); |
| 8 |
T length() const; |
| 9 |
T x, y, z; |
| 10 |
}; |
| 11 |
template <class T> |
| 12 |
Vector3<T>::Vector3(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {} |
| 13 |
Vector3<float> cross(Vector3<float> a, Vector3<float> b) { |
| 14 |
return Vector3<float>(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, |
| 15 |
a.x * b.y - a.y * b.x); |
| 16 |
} |
| 17 |
template <class T> T Vector3<T>::length() const { return z; } |
| 18 |
int generateNormals_i; |
| 19 |
float generateNormals_p2_0, generateNormals_p0_0; |
| 20 |
struct SphereMesh { |
| 21 |
void generateNormals(); |
| 22 |
float vertices; |
| 23 |
}; |
| 24 |
void SphereMesh::generateNormals() { |
| 25 |
Vector3<float> *faceNormals = new Vector3<float>; |
| 26 |
for (int j; j; j++) { |
| 27 |
float *p0 = &vertices + 3, *p1 = &vertices + j * 3, *p2 = &vertices + 3, |
| 28 |
*p3 = &vertices + generateNormals_i + j * 3; |
| 29 |
Vector3<float> v0(p1[0] - generateNormals_p0_0, p1[1] - 1, p1[2] - 2), |
| 30 |
v1(0, 1, 2); |
| 31 |
if (v0.length()) |
| 32 |
v1 = Vector3<float>(p3[0] - generateNormals_p2_0, p3[1] - p2[1], |
| 33 |
p3[2] - p2[2]); |
| 34 |
else |
| 35 |
v1 = Vector3<float>(generateNormals_p0_0 - p3[0], p0[1] - p3[1], |
| 36 |
p0[2] - p3[2]); |
| 37 |
Vector3<float> faceNormal = cross(v0, v1); |
| 38 |
faceNormals[j] = faceNormal; |
| 39 |
} |
| 40 |
} |