Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions G3Dcpp/Matrix4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@

namespace G3D {

const Matrix4& Matrix4::identity() {
static Matrix4 m(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
return m;
}

const Matrix4& Matrix4::zero() {
static Matrix4 m(
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0);
return m;
}
// *** Read Matrix.h comment regarding identity and zero ***

// const Matrix4& Matrix4::identity() {
// static Matrix4 m(
// 1, 0, 0, 0,
// 0, 1, 0, 0,
// 0, 0, 1, 0,
// 0, 0, 0, 1);
// return m;
// }

// const Matrix4& Matrix4::zero() {
// static Matrix4 m(
// 0, 0, 0, 0,
// 0, 0, 0, 0,
// 0, 0, 0, 0,
// 0, 0, 0, 0);
// return m;
// }

// Deprecated.
const Matrix4 Matrix4::IDENTITY
Expand Down
23 changes: 20 additions & 3 deletions include/G3D/Matrix3.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ class Matrix3 {

static const float EPSILON;

// The following comment is wrong. Modern linkers are smart enough to deduplicate
// multiple static objects into a single memory address, as long as any function with
// a static local variable is marked inline.

// *** Original G3D comment ***
// Special values.
// The unguaranteed order of initialization of static variables across
// translation units can be a source of annoying bugs, so now the static
Expand All @@ -255,7 +260,7 @@ class Matrix3 {
// "You might be tempted to write [...] them as inline functions
// inside their respective header files, but this is something you
// must definitely not do. An inline function can be duplicated
// in every file in which it appears � and this duplication
// in every file in which it appears � and this duplication
// includes the static object definition. Because inline functions
// automatically default to internal linkage, this would result in
// having multiple static objects across the various translation
Expand All @@ -264,8 +269,20 @@ class Matrix3 {
// function, and this means not making the wrapping functions inline",
// according to Chapter 10 of "Thinking in C++, 2nd ed. Volume 1" by Bruce Eckel,
// http://www.mindview.net/
static const Matrix3& zero();
static const Matrix3& identity();
// *** End of G3D comment ***

static const Matrix3& zero() {
static Matrix3 m(0, 0, 0, 0, 0, 0, 0, 0, 0);
return m;
}

static const Matrix3& identity() {
static Matrix3 m(1, 0, 0, 0, 1, 0, 0, 0, 1);
return m;
}

// static const Matrix3& zero();
// static const Matrix3& identity();

// Deprecated.
/** @deprecated Use Matrix3::zero() */
Expand Down