Browse code

Add cpp-v5

Ingemar Ragnemalm authored on 21/02/2024 20:24:32 • Robert Cranston committed on 21/02/2024 20:24:32
Showing 5 changed files

1 1
new file mode 100755
2 2
Binary files /dev/null and b/._TSBK07-labs-cpp differ
3 3
Binary files a/common/._LittleOBJLoader.h and b/common/._LittleOBJLoader.h differ
4 4
Binary files a/common/._VectorUtils4.h and b/common/._VectorUtils4.h differ
... ...
@@ -84,8 +84,12 @@ void DisposeModel(Model *m);
84 84
 //}
85 85
 ///#endif
86 86
 
87
+#endif
88
+
87 89
 // --------------- Implementation part ----------------
88 90
 
91
+#ifdef MAIN
92
+
89 93
 #ifndef LOL_IMPLEMENTATION
90 94
 #define LOL_IMPLEMENTATION
91 95
 
... ...
@@ -88,6 +88,7 @@
88 88
 // 20220525: Revised perpective() to conform with the reference manual as well as GLM.
89 89
 // 20230205: Added new helper functions, uploadMat4ToShader etc.
90 90
 // Made a better #ifdef for handling multiple inclusions.
91
+// 20230227: Fixed the mat4(mat3) constructor.
91 92
 
92 93
 // You may use VectorUtils as you please. A reference to the origin is appreciated
93 94
 // but if you grab some snippets from it without reference... no problem.
... ...
@@ -253,14 +254,16 @@
253 254
 	} mat3;
254 255
 
255 256
 #ifdef __cplusplus
256
-	vec3::vec3(vec4 v) : x(v.x), y(v.y), z(v.z) {}
257
-	mat4::mat4(mat3 x)
258
-	{
259
-		m[0] = x.m[0]; m[1] = x.m[1]; m[2] = x.m[2]; m[3] = 0;
260
-		m[4] = x.m[3]; m[5] = x.m[4]; m[6] = x.m[5]; m[7] = 0;
261
-		m[8] = x.m[6]; m[9] = x.m[7]; m[10] = x.m[8]; m[11] = 0;
262
-		m[12] = x.m[0]; m[13] = x.m[0]; m[14] = x.m[0]; m[15] = 1;
263
-	}
257
+// This needed to be compiled only once - moved to implementation.
258
+// This most likely must be done with several more!
259
+//	vec3::vec3(vec4 v) : x(v.x), y(v.y), z(v.z) {}
260
+//	mat4::mat4(mat3 x)
261
+//	{
262
+//		m[0] = x.m[0]; m[1] = x.m[1]; m[2] = x.m[2]; m[3] = 0;
263
+//		m[4] = x.m[3]; m[5] = x.m[4]; m[6] = x.m[5]; m[7] = 0;
264
+//		m[8] = x.m[6]; m[9] = x.m[7]; m[10] = x.m[8]; m[11] = 0;
265
+//		m[12] = x.m[0]; m[13] = x.m[0]; m[14] = x.m[0]; m[15] = 1;
266
+//	}
264 267
 #endif
265 268
 
266 269
 //#ifdef __cplusplus
... ...
@@ -375,7 +378,7 @@
375 378
 #ifdef __cplusplus
376 379
 // Some C++ operator overloads
377 380
 // Non-member C++ operators!
378
-// New version 2021-05-2x: Constructiors for vec3 etc replaced in order to avoid
381
+// New version 2021-05-2x: Constructors for vec3 etc replaced in order to avoid
379 382
 // problems with some C++ compilers.
380 383
 
381 384
 // --- vec3 operations ---
... ...
@@ -1656,6 +1659,20 @@ mat4 lookAt(vec3 p, vec3 l, vec3 u)
1656 1659
 	return lookAtv(p, l, u);
1657 1660
 }
1658 1661
 
1662
+
1663
+#ifdef __cplusplus
1664
+	vec3::vec3(vec4 v) : x(v.x), y(v.y), z(v.z) {}
1665
+	// Was wrong, fixed 2023-02-27
1666
+	mat4::mat4(mat3 x)
1667
+	{
1668
+		m[0]  = x.m[0]; m[1]  = x.m[1]; m[2] =  x.m[2]; m[3]  = 0;
1669
+		m[4]  = x.m[3]; m[5]  = x.m[4]; m[6] =  x.m[5]; m[7]  = 0;
1670
+		m[8]  = x.m[6]; m[9]  = x.m[7]; m[10] = x.m[8]; m[11] = 0;
1671
+		m[12] = 0;      m[13] = 0;      m[14] = 0;      m[15] = 1;
1672
+	}
1673
+#endif
1674
+
1675
+
1659 1676
 #endif
1660 1677
 #endif
1661 1678
 #endif