浏览代码

Most unit tests working

Thomas Buck 11 年前
父节点
当前提交
cb3e837080
共有 6 个文件被更改,包括 181 次插入139 次删除
  1. 6
    0
      ChangeLog
  2. 33
    11
      Makefile
  3. 11
    3
      src/GLString.cpp
  4. 58
    57
      src/hel/Matrix.cpp
  5. 46
    41
      src/hel/Quaternion.cpp
  6. 27
    27
      src/hel/math.cpp

+ 6
- 0
ChangeLog 查看文件

5
 
5
 
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7
 
7
 
8
+	[ 20140104 ]
9
+	* Hel Unit Test build & passes
10
+	* Spring & Simulation Tests unbuildable, missing files?
11
+	* GLString Unit Test builds, works not every time?
12
+	* TombRaider Unit & Regression Test working
13
+
8
 	[ 20140103 ]
14
 	[ 20140103 ]
9
 	* Removed more (unused?) code, PSKModel & UTPackage
15
 	* Removed more (unused?) code, PSKModel & UTPackage
10
 	* Removed unused MD3, mtk3d, MtkImage stuff!
16
 	* Removed unused MD3, mtk3d, MtkImage stuff!

+ 33
- 11
Makefile 查看文件

15
 MAJOR_VERSION=0
15
 MAJOR_VERSION=0
16
 MINOR_VERSION=1
16
 MINOR_VERSION=1
17
 MICRO_VERSION=2
17
 MICRO_VERSION=2
18
-BUILD_ID=20140102
18
+BUILD_ID=$(shell date "+%Y%m%d")
19
 PRE=
19
 PRE=
20
 VERSION=$(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)$(PRE)
20
 VERSION=$(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)$(PRE)
21
 VERSION_DEB=$(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION).$(BUILD_ID)
21
 VERSION_DEB=$(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION).$(BUILD_ID)
22
 BUILD_HOST=$(shell uname -s -n -r -m)
22
 BUILD_HOST=$(shell uname -s -n -r -m)
23
 ARCH=$(shell uname -m)
23
 ARCH=$(shell uname -m)
24
-#ARCH=i386
25
 UNAME=$(shell uname -s)
24
 UNAME=$(shell uname -s)
26
 
25
 
27
 ###############################################################
26
 ###############################################################
166
 memory:
165
 memory:
167
 	@-mkdir -p $(BUILD_MEM_DIR)
166
 	@-mkdir -p $(BUILD_MEM_DIR)
168
 	$(MAKE) targets BUILDDIR=$(BUILD_MEM_DIR) \
167
 	$(MAKE) targets BUILDDIR=$(BUILD_MEM_DIR) \
169
-	DEBUG_OBJ="$(BUILD_MEM_DIR)/memeory_test.o" \
168
+	DEBUG_OBJ="$(BUILD_MEM_DIR)/memory_test.o" \
170
 	CFLAGS="$(DEBUG_CFLAGS) -DDEBUG_MEMEORY" \
169
 	CFLAGS="$(DEBUG_CFLAGS) -DDEBUG_MEMEORY" \
171
 	LD_FLAGS="$(LD_FLAGS)"
170
 	LD_FLAGS="$(LD_FLAGS)"
172
 
171
 
367
 	$(MAKE) targets NAME=TombRaider.test BUILDDIR=$(BUILD_TEST_DIR) \
366
 	$(MAKE) targets NAME=TombRaider.test BUILDDIR=$(BUILD_TEST_DIR) \
368
 	OBJS="$(BUILD_TEST_DIR)/TombRaider.o $(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/memeory_test.o" \
367
 	OBJS="$(BUILD_TEST_DIR)/TombRaider.o $(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/memeory_test.o" \
369
 	CFLAGS="$(BASE_CFLAGS) -g -D__TOMBRAIDER_TEST__ -D__TEST_TR5_DUMP_TGA -D__TEST_32BIT_TEXTILES -DDEBUG_MEMEORY" \
368
 	CFLAGS="$(BASE_CFLAGS) -g -D__TOMBRAIDER_TEST__ -D__TEST_TR5_DUMP_TGA -D__TEST_32BIT_TEXTILES -DDEBUG_MEMEORY" \
370
-	LD_FLAGS="-lz"
369
+	LD_FLAGS="-lz -lstdc++"
371
 
370
 
372
 #################################################################
371
 #################################################################
373
 
372
 
373
+ifeq ($(UNAME),Darwin)
374
+GLString.test:
375
+	mkdir -p $(BUILD_TEST_DIR)
376
+	$(CC) -Wall -Isrc -D__TEST__ -DHAVE_MTK -DHAVE_SDL -DUSING_MTK_TGA \
377
+	$(shell sdl-config --cflags) $(shell sdl-config --libs) \
378
+	-I/opt/local/include -I/usr/local/include \
379
+	-framework OpenGL \
380
+	-framework GLUT \
381
+	-lm -lstdc++ \
382
+	src/Texture.cpp src/mtk_tga.cpp \
383
+	src/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
384
+else
374
 GLString.test:
385
 GLString.test:
375
 	mkdir -p $(BUILD_TEST_DIR)
386
 	mkdir -p $(BUILD_TEST_DIR)
376
 	$(CC) -Wall -Isrc -D__TEST__ -DHAVE_MTK -DHAVE_SDL -DUSING_MTK_TGA \
387
 	$(CC) -Wall -Isrc -D__TEST__ -DHAVE_MTK -DHAVE_SDL -DUSING_MTK_TGA \
378
 	-lGL -lGLU -lm \
389
 	-lGL -lGLU -lm \
379
 	src/Texture.cpp src/mtk_tga.cpp \
390
 	src/Texture.cpp src/mtk_tga.cpp \
380
 	src/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
391
 	src/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
392
+endif
381
 
393
 
382
 #################################################################
394
 #################################################################
395
+
396
+# CollisionObject and HeightCollisionObject seem to be missing?
397
+# -- xythobuz, 2014-01-04
398
+
383
 SIMULATION_CFLAGS=-Wall -O0 -g -Isrc $(shell sdl-config --cflags) \
399
 SIMULATION_CFLAGS=-Wall -O0 -g -Isrc $(shell sdl-config --cflags) \
400
+		-I/opt/local/include \
384
 		-DUSING_OPENGL -DUSING_HEL -DUSING_MTK_TGA \
401
 		-DUSING_OPENGL -DUSING_HEL -DUSING_MTK_TGA \
385
 		-DUNIT_TEST_SIMULATION
402
 		-DUNIT_TEST_SIMULATION
386
 SIMULATION_OBJS=$(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/Texture.o \
403
 SIMULATION_OBJS=$(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/Texture.o \
399
 	$(MAKE) targets NAME=Simulation.test BUILDDIR=$(BUILD_TEST_DIR) \
416
 	$(MAKE) targets NAME=Simulation.test BUILDDIR=$(BUILD_TEST_DIR) \
400
 		OBJS="$(SIMULATION_OBJS)" \
417
 		OBJS="$(SIMULATION_OBJS)" \
401
 		CFLAGS="$(SIMULATION_CFLAGS)" \
418
 		CFLAGS="$(SIMULATION_CFLAGS)" \
402
-		LD_FLAGS="-lm -lstdc++ -lGL -lGLU $(shell sdl-config --libs)"
419
+		LD_FLAGS="-lm -lstdc++ -lSDL_ttf -lSDL -lGL -lGLU $(shell sdl-config --libs)"
403
 
420
 
404
 #################################################################
421
 #################################################################
422
+
423
+# Spring files seem to be missing?
424
+# -- xythobuz, 2014-01-04
425
+
405
 HEL_PARTICLE_CFLAGS=-Wall -O0 -g -Isrc $(shell sdl-config --cflags) \
426
 HEL_PARTICLE_CFLAGS=-Wall -O0 -g -Isrc $(shell sdl-config --cflags) \
427
+		-I/opt/local/include \
406
 		-DUSING_OPENGL -DUSING_HEL -DUSING_MTK_TGA \
428
 		-DUSING_OPENGL -DUSING_HEL -DUSING_MTK_TGA \
407
-		-DUNIT_TEST_SPRING -DHAVE_SDL_TTF -lSDL_ttf
429
+		-DUNIT_TEST_SPRING -DHAVE_SDL_TTF
408
 HEL_PARTICLE_OBJS=$(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/Texture.o \
430
 HEL_PARTICLE_OBJS=$(BUILD_TEST_DIR)/mtk_tga.o $(BUILD_TEST_DIR)/Texture.o \
409
 		$(BUILD_TEST_DIR)/Mass.o \
431
 		$(BUILD_TEST_DIR)/Mass.o \
410
 		$(BUILD_TEST_DIR)/Spring.o \
432
 		$(BUILD_TEST_DIR)/Spring.o \
422
 	$(MAKE) targets NAME=Spring.test BUILDDIR=$(BUILD_TEST_DIR) \
444
 	$(MAKE) targets NAME=Spring.test BUILDDIR=$(BUILD_TEST_DIR) \
423
 		OBJS="$(HEL_PARTICLE_OBJS)" \
445
 		OBJS="$(HEL_PARTICLE_OBJS)" \
424
 		CFLAGS="$(HEL_PARTICLE_CFLAGS)" \
446
 		CFLAGS="$(HEL_PARTICLE_CFLAGS)" \
425
-		LD_FLAGS="-lm -lstdc++ -lGL -lGLU $(shell sdl-config --libs)"
447
+		LD_FLAGS="-lm -lstdc++ -lSDL_ttf-lGL -lGLU $(shell sdl-config --libs)"
426
 
448
 
427
 #################################################################
449
 #################################################################
428
 
450
 
441
 Quaternion.test:
463
 Quaternion.test:
442
 	@-echo "Building Quaternion unit test"
464
 	@-echo "Building Quaternion unit test"
443
 	mkdir -p $(BUILD_TEST_DIR)
465
 	mkdir -p $(BUILD_TEST_DIR)
444
-	$(CC) -Wall -g -DQUATERNION_UNIT_TEST -lm -lstdc++ -Isrc \
466
+	$(CC) -Wall -g -DUNIT_TEST_QUATERNION -lm -lstdc++ -Isrc \
445
 	src/hel/Quaternion.cpp -o $(BUILD_TEST_DIR)/Quaternion.test
467
 	src/hel/Quaternion.cpp -o $(BUILD_TEST_DIR)/Quaternion.test
446
 	@-echo "================================================="
468
 	@-echo "================================================="
447
 	@-echo "Running Quaternion unit test"
469
 	@-echo "Running Quaternion unit test"
451
 	@-echo "Building Math unit test"
473
 	@-echo "Building Math unit test"
452
 	mkdir -p $(BUILD_TEST_DIR)
474
 	mkdir -p $(BUILD_TEST_DIR)
453
 	$(CC) -Wall -g -DMATH_UNIT_TEST -lm -lstdc++ -Isrc \
475
 	$(CC) -Wall -g -DMATH_UNIT_TEST -lm -lstdc++ -Isrc \
454
-	src/hel/math.cpp -o $(BUILD_TEST_DIR)/Math.test
476
+	src/hel/math.cpp src/hel/Vector3d.cpp -o $(BUILD_TEST_DIR)/Math.test
455
 	@-echo "================================================="
477
 	@-echo "================================================="
456
 	@-echo "Running hel unit test"
478
 	@-echo "Running hel unit test"
457
 	$(BUILD_TEST_DIR)/Math.test
479
 	$(BUILD_TEST_DIR)/Math.test
458
 
480
 
459
 #################################################################
481
 #################################################################
460
 
482
 
461
-Memeory.test:
483
+Memory.test:
462
 	mkdir -p $(BUILD_TEST_DIR)
484
 	mkdir -p $(BUILD_TEST_DIR)
463
 	$(CC) -Wall -g -D__TEST__ -lstdc++ \
485
 	$(CC) -Wall -g -D__TEST__ -lstdc++ \
464
 	-DDEBUG_MEMEORY -DDEBUG_MEMEORY_ERROR \
486
 	-DDEBUG_MEMEORY -DDEBUG_MEMEORY_ERROR \
465
-	src/memeory_test.cpp -o $(BUILD_TEST_DIR)/memeory_test.test
487
+	src/memeory_test.cpp -o $(BUILD_TEST_DIR)/memory_test.test
466
 
488
 
467
 #################################################################
489
 #################################################################
468
 
490
 

+ 11
- 3
src/GLString.cpp 查看文件

410
 
410
 
411
 #ifdef __TEST__
411
 #ifdef __TEST__
412
 
412
 
413
+#include <math.h>
414
+
415
+#ifdef __APPLE__
416
+#include <OpenGL/glu.h>
417
+#else
413
 #include <GL/glu.h>
418
 #include <GL/glu.h>
419
+#endif
414
 
420
 
415
 #ifdef HAVE_MTK
421
 #ifdef HAVE_MTK
416
 #   include "Texture.h"
422
 #   include "Texture.h"
533
 	else
539
 	else
534
 	{
540
 	{
535
 		id[0] = gTexture.loadTGA("data/font-0.tga");
541
 		id[0] = gTexture.loadTGA("data/font-0.tga");
536
-		id[1] = gTexture.loadTGA("data/font-1.tga");
537
-		id[2] = gTexture.loadTGA("data/font-2.tga");
538
-		id[3] = gTexture.loadTGA("data/font-3.tga");
542
+		id[1] = gTexture.loadTGA("data/font-0.tga");
543
+		id[2] = gTexture.loadTGA("data/font-0.tga");
544
+		id[3] = gTexture.loadTGA("data/font-0.tga");
539
 	}
545
 	}
540
 
546
 
541
 	printf("%i %i %i %i\n", id[0], id[1], id[2], id[3]);
547
 	printf("%i %i %i %i\n", id[0], id[1], id[2], id[3]);
596
   // Create GL context
602
   // Create GL context
597
   SDL_Init(SDL_INIT_VIDEO);
603
   SDL_Init(SDL_INIT_VIDEO);
598
 
604
 
605
+#ifndef __APPLE__
599
   if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0)
606
   if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0)
600
   {
607
   {
601
 	  SDL_ClearError();
608
 	  SDL_ClearError();
614
 		  }
621
 		  }
615
 	  }
622
 	  }
616
   }
623
   }
624
+#endif
617
 
625
 
618
   flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
626
   flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
619
 
627
 

+ 58
- 57
src/hel/Matrix.cpp 查看文件

1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
 /*================================================================
2
 /*================================================================
3
- * 
3
+ *
4
  * Project : Freyja
4
  * Project : Freyja
5
  * Author  : Terry 'Mongoose' Hendrix II
5
  * Author  : Terry 'Mongoose' Hendrix II
6
  * Website : http://www.westga.edu/~stu7440/
6
  * Website : http://www.westga.edu/~stu7440/
10
  * Comments: 3d Matrix class
10
  * Comments: 3d Matrix class
11
  *
11
  *
12
  *
12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14
  *           template generator script.  <stu7440@westga.edu>
14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------- 
15
+ *
16
+ *-- History -------------------------------------------------
17
  *
17
  *
18
  * 2002.05.11:
18
  * 2002.05.11:
19
  * Mongoose - Created
19
  * Mongoose - Created
76
 	/* NB. OpenGL Matrices are COLUMN major. */
76
 	/* NB. OpenGL Matrices are COLUMN major. */
77
 #define SWAP_ROWS(a, b) { float *_tmp = a; (a)=(b); (b)=_tmp; }
77
 #define SWAP_ROWS(a, b) { float *_tmp = a; (a)=(b); (b)=_tmp; }
78
 #define MAT(m,r,c) (m)[(c)*4+(r)]
78
 #define MAT(m,r,c) (m)[(c)*4+(r)]
79
-	
79
+
80
 	float wtmp[4][8];
80
 	float wtmp[4][8];
81
 	float m0, m1, m2, m3, s;
81
 	float m0, m1, m2, m3, s;
82
 	float *r0, *r1, *r2, *r3;
82
 	float *r0, *r1, *r2, *r3;
83
-	
83
+
84
 	r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
84
 	r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
85
-	
85
+
86
 	r0[0] = MAT(m,0,0), r0[1] = MAT(m,0,1),
86
 	r0[0] = MAT(m,0,0), r0[1] = MAT(m,0,1),
87
 	r0[2] = MAT(m,0,2), r0[3] = MAT(m,0,3),
87
 	r0[2] = MAT(m,0,2), r0[3] = MAT(m,0,3),
88
 	r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0,
88
 	r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0,
89
-	
89
+
90
 	r1[0] = MAT(m,1,0), r1[1] = MAT(m,1,1),
90
 	r1[0] = MAT(m,1,0), r1[1] = MAT(m,1,1),
91
 	r1[2] = MAT(m,1,2), r1[3] = MAT(m,1,3),
91
 	r1[2] = MAT(m,1,2), r1[3] = MAT(m,1,3),
92
 	r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0,
92
 	r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0,
93
-	
93
+
94
 	r2[0] = MAT(m,2,0), r2[1] = MAT(m,2,1),
94
 	r2[0] = MAT(m,2,0), r2[1] = MAT(m,2,1),
95
 	r2[2] = MAT(m,2,2), r2[3] = MAT(m,2,3),
95
 	r2[2] = MAT(m,2,2), r2[3] = MAT(m,2,3),
96
 	r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0,
96
 	r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0,
97
-	
97
+
98
 	r3[0] = MAT(m,3,0), r3[1] = MAT(m,3,1),
98
 	r3[0] = MAT(m,3,0), r3[1] = MAT(m,3,1),
99
 	r3[2] = MAT(m,3,2), r3[3] = MAT(m,3,3),
99
 	r3[2] = MAT(m,3,2), r3[3] = MAT(m,3,3),
100
 	r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
100
 	r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
104
 	if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1);
104
 	if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1);
105
 	if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0);
105
 	if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0);
106
 	if (0.0 == r0[0])  return false;
106
 	if (0.0 == r0[0])  return false;
107
-	
107
+
108
 	/* eliminate first variable     */
108
 	/* eliminate first variable     */
109
 	m1 = r1[0]/r0[0]; m2 = r2[0]/r0[0]; m3 = r3[0]/r0[0];
109
 	m1 = r1[0]/r0[0]; m2 = r2[0]/r0[0]; m3 = r3[0]/r0[0];
110
 	s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
110
 	s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
118
 	if (s != 0.0) { r1[6] -= m1 * s; r2[6] -= m2 * s; r3[6] -= m3 * s; }
118
 	if (s != 0.0) { r1[6] -= m1 * s; r2[6] -= m2 * s; r3[6] -= m3 * s; }
119
 	s = r0[7];
119
 	s = r0[7];
120
 	if (s != 0.0) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; }
120
 	if (s != 0.0) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; }
121
-	
121
+
122
 	/* choose pivot - or die */
122
 	/* choose pivot - or die */
123
 	if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2);
123
 	if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2);
124
 	if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1);
124
 	if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1);
125
 	if (0.0 == r1[1])  return false;
125
 	if (0.0 == r1[1])  return false;
126
-	
126
+
127
 	/* eliminate second variable */
127
 	/* eliminate second variable */
128
 	m2 = r2[1]/r1[1]; m3 = r3[1]/r1[1];
128
 	m2 = r2[1]/r1[1]; m3 = r3[1]/r1[1];
129
 	r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
129
 	r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
132
 	s = r1[5]; if (0.0 != s) { r2[5] -= m2 * s; r3[5] -= m3 * s; }
132
 	s = r1[5]; if (0.0 != s) { r2[5] -= m2 * s; r3[5] -= m3 * s; }
133
 	s = r1[6]; if (0.0 != s) { r2[6] -= m2 * s; r3[6] -= m3 * s; }
133
 	s = r1[6]; if (0.0 != s) { r2[6] -= m2 * s; r3[6] -= m3 * s; }
134
 	s = r1[7]; if (0.0 != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; }
134
 	s = r1[7]; if (0.0 != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; }
135
-	
135
+
136
 	/* choose pivot - or die */
136
 	/* choose pivot - or die */
137
 	if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2);
137
 	if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2);
138
 	if (0.0 == r2[2])  return false;
138
 	if (0.0 == r2[2])  return false;
139
-	
139
+
140
 	/* eliminate third variable */
140
 	/* eliminate third variable */
141
 	m3 = r3[2]/r2[2];
141
 	m3 = r3[2]/r2[2];
142
 	r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4],
142
 	r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4],
143
 	r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6],
143
 	r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6],
144
 	r3[7] -= m3 * r2[7];
144
 	r3[7] -= m3 * r2[7];
145
-	
145
+
146
 	/* last check */
146
 	/* last check */
147
 	if (0.0 == r3[3]) return false;
147
 	if (0.0 == r3[3]) return false;
148
-	
148
+
149
 	s = 1.0/r3[3];              /* now back substitute row 3 */
149
 	s = 1.0/r3[3];              /* now back substitute row 3 */
150
 	r3[4] *= s; r3[5] *= s; r3[6] *= s; r3[7] *= s;
150
 	r3[4] *= s; r3[5] *= s; r3[6] *= s; r3[7] *= s;
151
-	
151
+
152
 	m2 = r2[3];                 /* now back substitute row 2 */
152
 	m2 = r2[3];                 /* now back substitute row 2 */
153
 	s  = 1.0/r2[2];
153
 	s  = 1.0/r2[2];
154
 	r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2),
154
 	r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2),
159
 	m0 = r0[3];
159
 	m0 = r0[3];
160
 	r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0,
160
 	r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0,
161
 	r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0;
161
 	r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0;
162
-	
162
+
163
 	m1 = r1[2];                 /* now back substitute row 1 */
163
 	m1 = r1[2];                 /* now back substitute row 1 */
164
 	s  = 1.0/r1[1];
164
 	s  = 1.0/r1[1];
165
 	r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1),
165
 	r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1),
167
 	m0 = r0[2];
167
 	m0 = r0[2];
168
 	r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0,
168
 	r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0,
169
 	r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0;
169
 	r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0;
170
-	
170
+
171
 	m0 = r0[1];                 /* now back substitute row 0 */
171
 	m0 = r0[1];                 /* now back substitute row 0 */
172
 	s  = 1.0/r0[0];
172
 	s  = 1.0/r0[0];
173
 	r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
173
 	r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
174
 	r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
174
 	r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
175
-	
176
-	MAT(out,0,0) = r0[4]; 
177
-	MAT(out,0,1) = r0[5], MAT(out,0,2) = r0[6]; 
175
+
176
+	MAT(out,0,0) = r0[4];
177
+	MAT(out,0,1) = r0[5], MAT(out,0,2) = r0[6];
178
 	MAT(out,0,3) = r0[7], MAT(out,1,0) = r1[4];
178
 	MAT(out,0,3) = r0[7], MAT(out,1,0) = r1[4];
179
 	MAT(out,1,1) = r1[5], MAT(out,1,2) = r1[6];
179
 	MAT(out,1,1) = r1[5], MAT(out,1,2) = r1[6];
180
 	MAT(out,1,3) = r1[7], MAT(out,2,0) = r2[4];
180
 	MAT(out,1,3) = r1[7], MAT(out,2,0) = r2[4];
181
 	MAT(out,2,1) = r2[5], MAT(out,2,2) = r2[6];
181
 	MAT(out,2,1) = r2[5], MAT(out,2,2) = r2[6];
182
 	MAT(out,2,3) = r2[7], MAT(out,3,0) = r3[4];
182
 	MAT(out,2,3) = r2[7], MAT(out,3,0) = r3[4];
183
 	MAT(out,3,1) = r3[5], MAT(out,3,2) = r3[6];
183
 	MAT(out,3,1) = r3[5], MAT(out,3,2) = r3[6];
184
-	MAT(out,3,3) = r3[7]; 
185
-	
184
+	MAT(out,3,3) = r3[7];
185
+
186
 	return true;
186
 	return true;
187
 #undef MAT
187
 #undef MAT
188
 #undef SWAP_ROWS
188
 #undef SWAP_ROWS
267
 {
267
 {
268
 	vec_t x = v[0], y = v[1], z = v[2], w = v[3];
268
 	vec_t x = v[0], y = v[1], z = v[2], w = v[3];
269
 
269
 
270
-	
270
+
271
    result[0] = mMatrix[ 0]*x + mMatrix[ 1]*y + mMatrix[ 2]*z + mMatrix[ 3]*w;
271
    result[0] = mMatrix[ 0]*x + mMatrix[ 1]*y + mMatrix[ 2]*z + mMatrix[ 3]*w;
272
 	result[1] = mMatrix[ 4]*x + mMatrix[ 5]*y + mMatrix[ 6]*z + mMatrix[ 7]*w;
272
 	result[1] = mMatrix[ 4]*x + mMatrix[ 5]*y + mMatrix[ 6]*z + mMatrix[ 7]*w;
273
 	result[2] = mMatrix[ 8]*x + mMatrix[ 9]*y + mMatrix[10]*z + mMatrix[11]*w;
273
 	result[2] = mMatrix[ 8]*x + mMatrix[ 9]*y + mMatrix[10]*z + mMatrix[11]*w;
296
 bool Matrix::isIdentity()
296
 bool Matrix::isIdentity()
297
 {
297
 {
298
 	// Hhhmm... floating point using direct comparisions
298
 	// Hhhmm... floating point using direct comparisions
299
-	if (mMatrix[ 0] == 1 && mMatrix[ 1] == 0 && mMatrix[ 2] == 0 && 
300
-		 mMatrix[ 3] == 0 &&	mMatrix[ 4] == 0 && mMatrix[ 5] == 1 && 
301
-		 mMatrix[ 6] == 0 && mMatrix[ 7] == 0 && mMatrix[ 8] == 0 && 
299
+	if (mMatrix[ 0] == 1 && mMatrix[ 1] == 0 && mMatrix[ 2] == 0 &&
300
+		 mMatrix[ 3] == 0 &&	mMatrix[ 4] == 0 && mMatrix[ 5] == 1 &&
301
+		 mMatrix[ 6] == 0 && mMatrix[ 7] == 0 && mMatrix[ 8] == 0 &&
302
 		 mMatrix[ 9] == 0 && mMatrix[10] == 1 && mMatrix[11] == 0 &&
302
 		 mMatrix[ 9] == 0 && mMatrix[10] == 1 && mMatrix[11] == 0 &&
303
-		 mMatrix[12] == 0 && mMatrix[13] == 0 && mMatrix[14] == 0 && 
303
+		 mMatrix[12] == 0 && mMatrix[13] == 0 && mMatrix[14] == 0 &&
304
 		 mMatrix[15] == 1)
304
 		 mMatrix[15] == 1)
305
 		return true;
305
 		return true;
306
 
306
 
448
 	result[ 1] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b[ 7];
448
 	result[ 1] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b[ 7];
449
 	result[ 2] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
449
 	result[ 2] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
450
 	result[ 3] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
450
 	result[ 3] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
451
-	
451
+
452
 	result[ 4] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b[ 3];
452
 	result[ 4] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b[ 3];
453
 	result[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b[ 7];
453
 	result[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b[ 7];
454
 	result[ 6] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
454
 	result[ 6] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
455
 	result[ 7] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
455
 	result[ 7] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
456
-	
456
+
457
 	result[ 8] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b[ 3];
457
 	result[ 8] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b[ 3];
458
 	result[ 9] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b[ 7];
458
 	result[ 9] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b[ 7];
459
 	result[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
459
 	result[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
460
 	result[11] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
460
 	result[11] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
461
-	
461
+
462
 	result[12] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b[ 3];
462
 	result[12] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b[ 3];
463
 	result[13] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b[ 7];
463
 	result[13] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b[ 7];
464
 	result[14] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
464
 	result[14] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
469
 	result[ 1] = a[ 0] * b[ 1] + a[ 1] * b[ 5] + a[ 2] * b[ 9] + a[ 3] * b[13];
469
 	result[ 1] = a[ 0] * b[ 1] + a[ 1] * b[ 5] + a[ 2] * b[ 9] + a[ 3] * b[13];
470
 	result[ 2] = a[ 0] * b[ 2] + a[ 1] * b[ 6] + a[ 2] * b[10] + a[ 3] * b[14];
470
 	result[ 2] = a[ 0] * b[ 2] + a[ 1] * b[ 6] + a[ 2] * b[10] + a[ 3] * b[14];
471
 	result[ 3] = a[ 0] * b[ 3] + a[ 1] * b[ 7] + a[ 2] * b[11] + a[ 3] * b[15];
471
 	result[ 3] = a[ 0] * b[ 3] + a[ 1] * b[ 7] + a[ 2] * b[11] + a[ 3] * b[15];
472
-	
472
+
473
 	result[ 4] = a[ 4] * b[ 0] + a[ 5] * b[ 4] + a[ 6] * b[ 8] + a[ 7] * b[12];
473
 	result[ 4] = a[ 4] * b[ 0] + a[ 5] * b[ 4] + a[ 6] * b[ 8] + a[ 7] * b[12];
474
 	result[ 5] = a[ 4] * b[ 1] + a[ 5] * b[ 5] + a[ 6] * b[ 9] + a[ 7] * b[13];
474
 	result[ 5] = a[ 4] * b[ 1] + a[ 5] * b[ 5] + a[ 6] * b[ 9] + a[ 7] * b[13];
475
 	result[ 6] = a[ 4] * b[ 2] + a[ 5] * b[ 6] + a[ 6] * b[10] + a[ 7] * b[14];
475
 	result[ 6] = a[ 4] * b[ 2] + a[ 5] * b[ 6] + a[ 6] * b[10] + a[ 7] * b[14];
476
 	result[ 7] = a[ 4] * b[ 3] + a[ 5] * b[ 7] + a[ 6] * b[11] + a[ 7] * b[15];
476
 	result[ 7] = a[ 4] * b[ 3] + a[ 5] * b[ 7] + a[ 6] * b[11] + a[ 7] * b[15];
477
-	
477
+
478
 	result[ 8] = a[ 8] * b[ 0] + a[ 9] * b[ 4] + a[10] * b[ 8] + a[11] * b[12];
478
 	result[ 8] = a[ 8] * b[ 0] + a[ 9] * b[ 4] + a[10] * b[ 8] + a[11] * b[12];
479
 	result[ 9] = a[ 8] * b[ 1] + a[ 9] * b[ 5] + a[10] * b[ 9] + a[11] * b[13];
479
 	result[ 9] = a[ 8] * b[ 1] + a[ 9] * b[ 5] + a[10] * b[ 9] + a[11] * b[13];
480
 	result[10] = a[ 8] * b[ 2] + a[ 9] * b[ 6] + a[10] * b[10] + a[11] * b[14];
480
 	result[10] = a[ 8] * b[ 2] + a[ 9] * b[ 6] + a[10] * b[10] + a[11] * b[14];
481
 	result[11] = a[ 8] * b[ 3] + a[ 9] * b[ 7] + a[10] * b[11] + a[11] * b[15];
481
 	result[11] = a[ 8] * b[ 3] + a[ 9] * b[ 7] + a[10] * b[11] + a[11] * b[15];
482
-	
482
+
483
 	result[12] = a[12] * b[ 0] + a[13] * b[ 4] + a[14] * b[ 8] + a[15] * b[12];
483
 	result[12] = a[12] * b[ 0] + a[13] * b[ 4] + a[14] * b[ 8] + a[15] * b[12];
484
 	result[13] = a[12] * b[ 1] + a[13] * b[ 5] + a[14] * b[ 9] + a[15] * b[13];
484
 	result[13] = a[12] * b[ 1] + a[13] * b[ 5] + a[14] * b[ 9] + a[15] * b[13];
485
 	result[14] = a[12] * b[ 2] + a[13] * b[ 6] + a[14] * b[10] + a[15] * b[14];
485
 	result[14] = a[12] * b[ 2] + a[13] * b[ 6] + a[14] * b[10] + a[15] * b[14];
489
 
489
 
490
 
490
 
491
 ////////////////////////////////////////////////////////////
491
 ////////////////////////////////////////////////////////////
492
-// Unit Test 
492
+// Unit Test
493
 ////////////////////////////////////////////////////////////
493
 ////////////////////////////////////////////////////////////
494
 
494
 
495
 #ifdef MATRIX_UNIT_TEST
495
 #ifdef MATRIX_UNIT_TEST
496
+#include <strings.h>
496
 /* <Order> is (r)ow or (c)ol */
497
 /* <Order> is (r)ow or (c)ol */
497
 void generateMatrixSourceTest(char order)
498
 void generateMatrixSourceTest(char order)
498
 {
499
 {
499
 	int i, j, k;
500
 	int i, j, k;
500
 
501
 
501
-	
502
+
502
 	if (order == 'r')
503
 	if (order == 'r')
503
 	{
504
 	{
504
 		printf("/* Row order */\n");
505
 		printf("/* Row order */\n");
507
 	{
508
 	{
508
 		printf("/* Column order */\n");
509
 		printf("/* Column order */\n");
509
 	}
510
 	}
510
-	
511
+
511
 	for (i = 0; i < 4; ++i)
512
 	for (i = 0; i < 4; ++i)
512
 	{
513
 	{
513
 		for (j = 0; j < 4; ++j)
514
 		for (j = 0; j < 4; ++j)
520
 			{
521
 			{
521
 				printf("result[%2i] = ", j+i*4);
522
 				printf("result[%2i] = ", j+i*4);
522
 			}
523
 			}
523
-			
524
+
524
 			for (k = 0; k < 4; ++k)
525
 			for (k = 0; k < 4; ++k)
525
 			{
526
 			{
526
 				if (order == 'r')
527
 				if (order == 'r')
527
 				{
528
 				{
528
 					printf("a[%2i] * b[%2i]%s",
529
 					printf("a[%2i] * b[%2i]%s",
529
-							  k+i*4, j+k*4, (k == 3) ? ";\n" : " + "); 
530
+							  k+i*4, j+k*4, (k == 3) ? ";\n" : " + ");
530
 				}
531
 				}
531
 				else
532
 				else
532
 				{
533
 				{
533
-					printf("a[%2i] * b[%2i]%s", 
534
+					printf("a[%2i] * b[%2i]%s",
534
 							 i+k*4, k+j*4, (k == 3) ? ";\n" : " + ");
535
 							 i+k*4, k+j*4, (k == 3) ? ";\n" : " + ");
535
 				}
536
 				}
536
 
537
 
584
 			printf("Identity * Identity");
585
 			printf("Identity * Identity");
585
 			c.setIdentity();
586
 			c.setIdentity();
586
 			b.setIdentity();
587
 			b.setIdentity();
587
-			a = c * b; 
588
+			a = c * b;
588
 			break;
589
 			break;
589
 		case 2:
590
 		case 2:
590
 			printf("Identity *= Identity");
591
 			printf("Identity *= Identity");
608
 		printf("\n");
609
 		printf("\n");
609
 	}
610
 	}
610
 
611
 
611
-	/* 2003.06.18, Mongoose - These tests are weak and 
612
+	/* 2003.06.18, Mongoose - These tests are weak and
612
 		only spot check some of the matrix */
613
 		only spot check some of the matrix */
613
 
614
 
614
 
615
 
619
 
620
 
620
 #ifdef COLUMN_ORDER
621
 #ifdef COLUMN_ORDER
621
 	unsigned char i0  = 0, i1  = 4, i2  =  8, i3  = 12;
622
 	unsigned char i0  = 0, i1  = 4, i2  =  8, i3  = 12;
622
-	unsigned char i4  = 1, i5  = 5, i6  =  9, i7  = 13; 
623
+	unsigned char i4  = 1, i5  = 5, i6  =  9, i7  = 13;
623
 	unsigned char i8  = 2, i9  = 6, i10 = 10, i11 = 14;
624
 	unsigned char i8  = 2, i9  = 6, i10 = 10, i11 = 14;
624
 	unsigned char i12 = 3, i13 = 7, i14 = 11, i15 = 15;
625
 	unsigned char i12 = 3, i13 = 7, i14 = 11, i15 = 15;
625
 #else
626
 #else
626
-	unsigned char i0  =  0, i1  =  1, i2  =  2, i3  =  3;
627
-	unsigned char i4  =  4, i5  =  5, i6  =  6, i7  =  7;
628
-	unsigned char i8  =  8, i9  =  9, i10 = 10, i11 = 11;
627
+	unsigned char i0  =  0, i1  =  1, i2  =  2; // i3  =  3
628
+	unsigned char i4  =  4, i6  =  6; // i5  =  5, i7  =  7
629
+	unsigned char i8  =  8, i9  =  9, i10 = 10; // i11 = 11
629
 	unsigned char i12 = 12, i13 = 13, i14 = 14, i15 = 15;
630
 	unsigned char i12 = 12, i13 = 13, i14 = 14, i15 = 15;
630
 #endif
631
 #endif
631
 
632
 
632
-	if (a.mMatrix[i12] != 10 || 
633
-		 a.mMatrix[i13] != 20 || 
633
+	if (a.mMatrix[i12] != 10 ||
634
+		 a.mMatrix[i13] != 20 ||
634
 		 a.mMatrix[i14] != 30)
635
 		 a.mMatrix[i14] != 30)
635
 	{
636
 	{
636
 			++errs;
637
 			++errs;
637
 			printf(" \t[ Failed ]\a\n"); // beep
638
 			printf(" \t[ Failed ]\a\n"); // beep
638
-			a.print();		
639
+			a.print();
639
 	}
640
 	}
640
 
641
 
641
 	/* Cheap X rotation test */
642
 	/* Cheap X rotation test */
643
 	printf("I -> Rotate (90 degrees, 0, 0)\n");
644
 	printf("I -> Rotate (90 degrees, 0, 0)\n");
644
 	a.rotate(90*0.01745329251994329f, 0, 0);
645
 	a.rotate(90*0.01745329251994329f, 0, 0);
645
 
646
 
646
-	if (a.mMatrix[i0] != 1 || a.mMatrix[i15] != 1 || 
647
+	if (a.mMatrix[i0] != 1 || a.mMatrix[i15] != 1 ||
647
 		 a.mMatrix[i9] != -1 || a.mMatrix[i6] != 1)
648
 		 a.mMatrix[i9] != -1 || a.mMatrix[i6] != 1)
648
 	{
649
 	{
649
 			++errs;
650
 			++errs;
650
 			printf(" \t[ Failed ]\a\n"); // beep
651
 			printf(" \t[ Failed ]\a\n"); // beep
651
-			a.print();		
652
+			a.print();
652
 	}
653
 	}
653
 
654
 
654
 	/* Cheap Y rotation test */
655
 	/* Cheap Y rotation test */
661
 	{
662
 	{
662
 			++errs;
663
 			++errs;
663
 			printf(" \t[ Failed ]\a\n"); // beep
664
 			printf(" \t[ Failed ]\a\n"); // beep
664
-			a.print();		
665
+			a.print();
665
 	}
666
 	}
666
 
667
 
667
 	/* Cheap Z rotation test */
668
 	/* Cheap Z rotation test */
669
 	printf("I -> Rotate (0, 0, 90 degrees)\n");
670
 	printf("I -> Rotate (0, 0, 90 degrees)\n");
670
 	a.rotate(0, 0, 90*0.01745329251994329f);
671
 	a.rotate(0, 0, 90*0.01745329251994329f);
671
 
672
 
672
-	if (a.mMatrix[i4] != -1 || a.mMatrix[i15] != 1 || 
673
+	if (a.mMatrix[i4] != -1 || a.mMatrix[i15] != 1 ||
673
 		 a.mMatrix[i1] != 1 || a.mMatrix[i10] != 1)
674
 		 a.mMatrix[i1] != 1 || a.mMatrix[i10] != 1)
674
 	{
675
 	{
675
 			++errs;
676
 			++errs;
676
 			printf(" \t[ Failed ]\a\n"); // beep
677
 			printf(" \t[ Failed ]\a\n"); // beep
677
-			a.print();		
678
+			a.print();
678
 	}
679
 	}
679
 
680
 
680
 	printf("\n%i errors\n", errs);
681
 	printf("\n%i errors\n", errs);
699
 	a.translate(-10, -20, -30);
700
 	a.translate(-10, -20, -30);
700
 	printf(" -> Rotate (0, 0, -90 degrees)\n");
701
 	printf(" -> Rotate (0, 0, -90 degrees)\n");
701
 	a.rotate(0, 0, -90*0.01745329251994329f);
702
 	a.rotate(0, 0, -90*0.01745329251994329f);
702
-	a.print();	
703
+	a.print();
703
 
704
 
704
 	printf("\n%i errors\n", errs);
705
 	printf("\n%i errors\n", errs);
705
 
706
 

+ 46
- 41
src/hel/Quaternion.cpp 查看文件

1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
 /*================================================================
2
 /*================================================================
3
- * 
3
+ *
4
  * Project : Hel
4
  * Project : Hel
5
  * Author  : Terry 'Mongoose' Hendrix II
5
  * Author  : Terry 'Mongoose' Hendrix II
6
  * Website : http://www.westga.edu/~stu7440/
6
  * Website : http://www.westga.edu/~stu7440/
10
  * Comments: Quaternion now in C++ class form fresh from the grove
10
  * Comments: Quaternion now in C++ class form fresh from the grove
11
  *
11
  *
12
  *
12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14
  *           template generator script.  <stu7440@westga.edu>
14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------- 
15
+ *
16
+ *-- History -------------------------------------------------
17
  *
17
  *
18
  * 2002.12.16:
18
  * 2002.12.16:
19
  * Mongoose - Created, based on mtk3d ( freyja )
19
  * Mongoose - Created, based on mtk3d ( freyja )
69
 	m[ 1] = 2.0f * (mX*mY - mW*mZ);
69
 	m[ 1] = 2.0f * (mX*mY - mW*mZ);
70
 	m[ 2] = 2.0f * (mX*mZ + mW*mY);
70
 	m[ 2] = 2.0f * (mX*mZ + mW*mY);
71
 	m[ 3] = 0.0f;
71
 	m[ 3] = 0.0f;
72
-	
72
+
73
 	m[ 4] = 2.0f * (mX*mY + mW*mZ);
73
 	m[ 4] = 2.0f * (mX*mY + mW*mZ);
74
 	m[ 5] = 1.0f - 2.0f * (mX*mX + mZ*mZ);
74
 	m[ 5] = 1.0f - 2.0f * (mX*mX + mZ*mZ);
75
 	m[ 6] = 2.0f * (mY*mZ - mW*mX);
75
 	m[ 6] = 2.0f * (mY*mZ - mW*mX);
76
 	m[ 7] = 0.0f;
76
 	m[ 7] = 0.0f;
77
-	
77
+
78
 	m[ 8] = 2.0f * (mX*mZ - mW*mY);
78
 	m[ 8] = 2.0f * (mX*mZ - mW*mY);
79
 	m[ 9] = 2.0f * (mY*mZ + mW*mX);
79
 	m[ 9] = 2.0f * (mY*mZ + mW*mX);
80
 	m[10] = 1.0 - 2.0f * (mX*mX + mY*mY);
80
 	m[10] = 1.0 - 2.0f * (mX*mX + mY*mY);
81
 	m[11] = 0.0f;
81
 	m[11] = 0.0f;
82
-	
82
+
83
 	m[12] = 0.0f;
83
 	m[12] = 0.0f;
84
 	m[13] = 0.0f;
84
 	m[13] = 0.0f;
85
 	m[14] = 0.0f;
85
 	m[14] = 0.0f;
93
 	mX = q.mX;
93
 	mX = q.mX;
94
 	mY = q.mY;
94
 	mY = q.mY;
95
 	mZ = q.mZ;
95
 	mZ = q.mZ;
96
-  
96
+
97
   return (*this);
97
   return (*this);
98
 }
98
 }
99
 
99
 
175
 {
175
 {
176
 	vec_t temp, dist;
176
 	vec_t temp, dist;
177
 
177
 
178
-	
178
+
179
 	// Normalize
179
 	// Normalize
180
 	temp = x*x + y*y + z*z;
180
 	temp = x*x + y*y + z*z;
181
-	
181
+
182
 	dist = (float)(1.0 / sqrt(temp));
182
 	dist = (float)(1.0 / sqrt(temp));
183
-	
183
+
184
 	x *= dist;
184
 	x *= dist;
185
 	y *= dist;
185
 	y *= dist;
186
 	z *= dist;
186
 	z *= dist;
187
-	
187
+
188
 	mX = x;
188
 	mX = x;
189
 	mY = y;
189
 	mY = y;
190
 	mZ = z;
190
 	mZ = z;
191
-	
192
-	mW = (float)cos(angle / 2.0f);	
191
+
192
+	mW = (float)cos(angle / 2.0f);
193
 }
193
 }
194
 
194
 
195
 
195
 
199
 
199
 
200
 
200
 
201
 	square = mX * mX + mY * mY + mZ * mZ + mW * mW;
201
 	square = mX * mX + mY * mY + mZ * mZ + mW * mW;
202
-	
202
+
203
 	if (square > 0.0)
203
 	if (square > 0.0)
204
 	{
204
 	{
205
 		dist = (float)(1.0 / sqrt(square));
205
 		dist = (float)(1.0 / sqrt(square));
206
 	}
206
 	}
207
-	else 
207
+	else
208
 	{
208
 	{
209
 		dist = 1;
209
 		dist = 1;
210
 	}
210
 	}
212
 	mX *= dist;
212
 	mX *= dist;
213
 	mY *= dist;
213
 	mY *= dist;
214
 	mZ *= dist;
214
 	mZ *= dist;
215
-	mW *= dist; 
215
+	mW *= dist;
216
 }
216
 }
217
 
217
 
218
 
218
 
237
 	 *
237
 	 *
238
 	 * http://www.magic-software.com/Documentation/quat.pdf
238
 	 * http://www.magic-software.com/Documentation/quat.pdf
239
 	 *
239
 	 *
240
-	 * Thanks to digiben for algorithms and basis of the notes in 
240
+	 * Thanks to digiben for algorithms and basis of the notes in
241
 	 * this func
241
 	 * this func
242
 	 *
242
 	 *
243
 	 *******************************************************************/
243
 	 *******************************************************************/
247
 
247
 
248
 
248
 
249
 	// Don't bother if it's the same rotation, it's the same as the result
249
 	// Don't bother if it's the same rotation, it's the same as the result
250
-	if (a == b) 
250
+	if (a == b)
251
 	{
251
 	{
252
 		return a;
252
 		return a;
253
 	}
253
 	}
254
 
254
 
255
-	// A . B 
255
+	// A . B
256
 	result = dot(a, b);
256
 	result = dot(a, b);
257
-  
257
+
258
 	// If the dot product is less than 0, the angle is greater than 90 degrees
258
 	// If the dot product is less than 0, the angle is greater than 90 degrees
259
 	if (result < 0.0f)
259
 	if (result < 0.0f)
260
 	{
260
 	{
273
 	// angle is fairly small, we can actually just do a simpler linear interpolation
273
 	// angle is fairly small, we can actually just do a simpler linear interpolation
274
 	// of the 2 quaternions, and skip all the complex math.  We create a "delta" value
274
 	// of the 2 quaternions, and skip all the complex math.  We create a "delta" value
275
 	// of 0.1 to say that if the cosine of the angle (result of the dot product) between
275
 	// of 0.1 to say that if the cosine of the angle (result of the dot product) between
276
-	// the 2 quaternions is smaller than 0.1, then we do NOT want to perform the full on 
276
+	// the 2 quaternions is smaller than 0.1, then we do NOT want to perform the full on
277
 	// interpolation using.  This is because you won't really notice the difference.
277
 	// interpolation using.  This is because you won't really notice the difference.
278
-	
279
-	// Check if the angle between the 2 quaternions was big enough 
278
+
279
+	// Check if the angle between the 2 quaternions was big enough
280
 	// to warrant such calculations
280
 	// to warrant such calculations
281
 	if (1 - result > 0.1f)
281
 	if (1 - result > 0.1f)
282
 	{
282
 	{
289
 		// the angle and it's sine value
289
 		// the angle and it's sine value
290
 		scaleA = (float)sin((1 - time) * theta) / sinTheta;
290
 		scaleA = (float)sin((1 - time) * theta) / sinTheta;
291
 		scaleB = (float)sin((time * theta)) / sinTheta;
291
 		scaleB = (float)sin((time * theta)) / sinTheta;
292
-	}	
292
+	}
293
 
293
 
294
 	// Calculate the x, y, z and w values for the quaternion by using a special
294
 	// Calculate the x, y, z and w values for the quaternion by using a special
295
 	// form of linear interpolation for quaternions.
295
 	// form of linear interpolation for quaternions.
298
 
298
 
299
 
299
 
300
 void Quaternion::setByMatrix(matrix_t matrix)
300
 void Quaternion::setByMatrix(matrix_t matrix)
301
-{   
301
+{
302
 	float diagonal = matrix[0] + matrix[5] + matrix[10] + 1.0f;
302
 	float diagonal = matrix[0] + matrix[5] + matrix[10] + 1.0f;
303
 	float scale = 0.0f;
303
 	float scale = 0.0f;
304
 	float w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f;
304
 	float w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f;
305
-	
306
-	
305
+
306
+
307
 	if (diagonal > 0.00000001)
307
 	if (diagonal > 0.00000001)
308
 	{
308
 	{
309
 		// Calculate the scale of the diagonal
309
 		// Calculate the scale of the diagonal
310
 		scale = (float)(sqrt(diagonal) * 2);
310
 		scale = (float)(sqrt(diagonal) * 2);
311
-		
311
+
312
 		w = 0.25f * scale;
312
 		w = 0.25f * scale;
313
 		x = (matrix[9] - matrix[6]) / scale;
313
 		x = (matrix[9] - matrix[6]) / scale;
314
 		y = (matrix[2] - matrix[8]) / scale;
314
 		y = (matrix[2] - matrix[8]) / scale;
315
 		z = (matrix[4] - matrix[1]) / scale;
315
 		z = (matrix[4] - matrix[1]) / scale;
316
 	}
316
 	}
317
-	else 
317
+	else
318
 	{
318
 	{
319
 		 // If the first element of the diagonal is the greatest value
319
 		 // If the first element of the diagonal is the greatest value
320
 		if (matrix[0] > matrix[5] && matrix[0] > matrix[10])
320
 		if (matrix[0] > matrix[5] && matrix[0] > matrix[10])
321
-		{   
321
+		{
322
 			 // Find the scale according to the first element, and double it
322
 			 // Find the scale according to the first element, and double it
323
 			scale = (float)sqrt(1.0f + matrix[0] - matrix[5] - matrix[10])*2.0f;
323
 			scale = (float)sqrt(1.0f + matrix[0] - matrix[5] - matrix[10])*2.0f;
324
-			
324
+
325
 			// Calculate the quaternion
325
 			// Calculate the quaternion
326
-			w = (matrix[9] - matrix[6]) / scale; 
326
+			w = (matrix[9] - matrix[6]) / scale;
327
 			x = 0.25f * scale;
327
 			x = 0.25f * scale;
328
 			y = (matrix[4] + matrix[1]) / scale;
328
 			y = (matrix[4] + matrix[1]) / scale;
329
 			z = (matrix[2] + matrix[8]) / scale;
329
 			z = (matrix[2] + matrix[8]) / scale;
330
-		} 
330
+		}
331
 		// The second element of the diagonal is the greatest value
331
 		// The second element of the diagonal is the greatest value
332
-		else if (matrix[5] > matrix[10]) 
332
+		else if (matrix[5] > matrix[10])
333
 		{
333
 		{
334
 			// Find the scale according to the second element, and double it
334
 			// Find the scale according to the second element, and double it
335
 			scale = (float)sqrt(1.0f + matrix[5] - matrix[0] - matrix[10])*2.0f;
335
 			scale = (float)sqrt(1.0f + matrix[5] - matrix[0] - matrix[10])*2.0f;
336
-			
337
-			// Calculate the quaternion 
336
+
337
+			// Calculate the quaternion
338
 			w = (matrix[2] - matrix[8]) / scale;
338
 			w = (matrix[2] - matrix[8]) / scale;
339
 			x = (matrix[4] + matrix[1]) / scale;
339
 			x = (matrix[4] + matrix[1]) / scale;
340
 			y = 0.25f * scale;
340
 			y = 0.25f * scale;
341
 			z = (matrix[9] + matrix[6]) / scale;
341
 			z = (matrix[9] + matrix[6]) / scale;
342
-		} 
342
+		}
343
 		// The third element of the diagonal is the greatest value
343
 		// The third element of the diagonal is the greatest value
344
-		else 
345
-		{   
344
+		else
345
+		{
346
 			// Find the scale according to the third element, and double it
346
 			// Find the scale according to the third element, and double it
347
 			scale = (float)sqrt(1.0f + matrix[10] - matrix[0] - matrix[5])*2.0f;
347
 			scale = (float)sqrt(1.0f + matrix[10] - matrix[0] - matrix[5])*2.0f;
348
-			
348
+
349
 			// Calculate the quaternion
349
 			// Calculate the quaternion
350
 			w = (matrix[4] - matrix[1]) / scale;
350
 			w = (matrix[4] - matrix[1]) / scale;
351
 			x = (matrix[2] + matrix[8]) / scale;
351
 			x = (matrix[2] + matrix[8]) / scale;
408
 ////////////////////////////////////////////////////////////
408
 ////////////////////////////////////////////////////////////
409
 
409
 
410
 #ifdef UNIT_TEST_QUATERNION
410
 #ifdef UNIT_TEST_QUATERNION
411
+
412
+#include <stdio.h>
413
+
411
 int runQuaternionUnitTest(int argc, char *argv[])
414
 int runQuaternionUnitTest(int argc, char *argv[])
412
 {
415
 {
416
+    //! \todo Implement Quaternion Unit Tests!
417
+    printf("Not implemented!\n");
413
 	return 0;
418
 	return 0;
414
 }
419
 }
415
 
420
 

+ 27
- 27
src/hel/math.cpp 查看文件

25
 }
25
 }
26
 
26
 
27
 
27
 
28
-bool tmpHelSphereIntersectLine(Vector3d pos, Vector3d lastPos, 
28
+bool tmpHelSphereIntersectLine(Vector3d pos, Vector3d lastPos,
29
 										 Vector3d center, vec_t radius)
29
 										 Vector3d center, vec_t radius)
30
 {
30
 {
31
 	Vector3d seg, segToCenter, delta;
31
 	Vector3d seg, segToCenter, delta;
65
 
65
 
66
 	dist = Vector3d::dot(d, d);
66
 	dist = Vector3d::dot(d, d);
67
 	minDist = radiusA + radiusB;
67
 	minDist = radiusA + radiusB;
68
-	
68
+
69
 	return (dist <= minDist * minDist);
69
 	return (dist <= minDist * minDist);
70
 }
70
 }
71
 
71
 
72
 
72
 
73
-inline vec_t square(vec_t a) 
73
+inline vec_t square(vec_t a)
74
 {
74
 {
75
 	return a * a;
75
 	return a * a;
76
 }
76
 }
85
 {
85
 {
86
 	// float x , y , z;
86
 	// float x , y , z;
87
 	vec_t a, b, c, mu, i ;
87
 	vec_t a, b, c, mu, i ;
88
-	
89
 
88
 
90
-	a = (square(posB[0] - posA[0]) + 
91
-		  square(posB[1] - posA[1]) + 
89
+
90
+	a = (square(posB[0] - posA[0]) +
91
+		  square(posB[1] - posA[1]) +
92
 		  square(posB[2] - posA[2]));
92
 		  square(posB[2] - posA[2]));
93
 	b = (2 * ((posB[0] - posA[0]) * (posA[0] - center[0]) +
93
 	b = (2 * ((posB[0] - posA[0]) * (posA[0] - center[0]) +
94
 				 (posB[1] - posA[1]) * (posA[1] - center[1]) +
94
 				 (posB[1] - posA[1]) * (posA[1] - center[1]) +
96
 	c = (square(center[0]) + square(center[1]) +
96
 	c = (square(center[0]) + square(center[1]) +
97
 		  square(center[2]) + square(posA[0]) +
97
 		  square(center[2]) + square(posA[0]) +
98
 		  square(posA[1]) + square(posA[2]) -
98
 		  square(posA[1]) + square(posA[2]) -
99
-		  2 * (center[0]*posA[0] + center[1]*posA[1] + center[2]*posA[2]) - 
99
+		  2 * (center[0]*posA[0] + center[1]*posA[1] + center[2]*posA[2]) -
100
 		  square(radius));
100
 		  square(radius));
101
 
101
 
102
 	i = b * b - 4 * a * c;
102
 	i = b * b - 4 * a * c;
103
 
103
 
104
-	
104
+
105
 	if (i < 0.0)
105
 	if (i < 0.0)
106
 	{
106
 	{
107
 		// No intersection
107
 		// No intersection
120
 	else
120
 	else
121
 	{
121
 	{
122
 		// Two intersections
122
 		// Two intersections
123
-		
123
+
124
 		// First intersection
124
 		// First intersection
125
 		mu = (-b + sqrt( square(b) - 4*a*c)) / (2*a);
125
 		mu = (-b + sqrt( square(b) - 4*a*c)) / (2*a);
126
 		intersectionA[1] = posA[0] + mu*(posB[0]-posA[0]);
126
 		intersectionA[1] = posA[0] + mu*(posB[0]-posA[0]);
127
 		intersectionA[2] = posA[1] + mu*(posB[1]-posA[1]);
127
 		intersectionA[2] = posA[1] + mu*(posB[1]-posA[1]);
128
 		intersectionA[3] = posA[2] + mu*(posB[2]-posA[2]);
128
 		intersectionA[3] = posA[2] + mu*(posB[2]-posA[2]);
129
-		
129
+
130
 		// Second intersection
130
 		// Second intersection
131
 		mu = (-b - sqrt(square(b) - 4*a*c)) / (2*a);
131
 		mu = (-b - sqrt(square(b) - 4*a*c)) / (2*a);
132
 		intersectionB[0] = posA[0] + mu*(posB[0]-posA[0]);
132
 		intersectionB[0] = posA[0] + mu*(posB[0]-posA[0]);
163
 
163
 
164
 	// find D
164
 	// find D
165
 	//d = (normal[0] * ploygon[0][0] -
165
 	//d = (normal[0] * ploygon[0][0] -
166
-	//	  normal[1] * ploygon[0][1] - 
166
+	//	  normal[1] * ploygon[0][1] -
167
 	//	  normal[2] * ploygon[0][2]);
167
 	//	  normal[2] * ploygon[0][2]);
168
 	d = (normal.mVec[0] * ploygon[0][0] -
168
 	d = (normal.mVec[0] * ploygon[0][0] -
169
-		  normal.mVec[1] * ploygon[0][1] - 
169
+		  normal.mVec[1] * ploygon[0][1] -
170
 		  normal.mVec[2] * ploygon[0][2]);
170
 		  normal.mVec[2] * ploygon[0][2]);
171
 
171
 
172
 	// line segment parallel to plane?
172
 	// line segment parallel to plane?
196
 	intersect[0] = b.mVec[0];
196
 	intersect[0] = b.mVec[0];
197
 	intersect[1] = b.mVec[1];
197
 	intersect[1] = b.mVec[1];
198
 	intersect[2] = b.mVec[2];
198
 	intersect[2] = b.mVec[2];
199
-	
199
+
200
 
200
 
201
 	// See if the intercept is bound by polygon by winding number
201
 	// See if the intercept is bound by polygon by winding number
202
 #ifdef WINDING_NUMBERS_TRIANGLE
202
 #ifdef WINDING_NUMBERS_TRIANGLE
233
 	vec_t d;
233
 	vec_t d;
234
 
234
 
235
 
235
 
236
-	d = (plane[0] * center[0] + 
236
+	d = (plane[0] * center[0] +
237
 		  plane[1] * center[1] +
237
 		  plane[1] * center[1] +
238
-		  plane[2] * center[2] + 
238
+		  plane[2] * center[2] +
239
 		  plane[3]);
239
 		  plane[3]);
240
 
240
 
241
 	if (d <= -radius)
241
 	if (d <= -radius)
253
 
253
 
254
 	helMidpoint3v(min, max, center);
254
 	helMidpoint3v(min, max, center);
255
 
255
 
256
-	d = (plane[0] * center[0] + 
257
-		  plane[1] * center[1] + 
258
-		  plane[2] * center[2] + 
256
+	d = (plane[0] * center[0] +
257
+		  plane[1] * center[1] +
258
+		  plane[2] * center[2] +
259
 		  plane[3]);
259
 		  plane[3]);
260
 
260
 
261
 	radius = helDist3v(max, center);
261
 	radius = helDist3v(max, center);
270
 vec_t helDist3v(vec3_t a, vec3_t b)
270
 vec_t helDist3v(vec3_t a, vec3_t b)
271
 {
271
 {
272
 	return (sqrt( ((b[0] - a[0]) * (b[0] - a[0])) +
272
 	return (sqrt( ((b[0] - a[0]) * (b[0] - a[0])) +
273
-					  ((b[1] - a[1]) * (b[1] - a[1])) + 
273
+					  ((b[1] - a[1]) * (b[1] - a[1])) +
274
 					  ((b[2] - a[2]) * (b[2] - a[2]))));
274
 					  ((b[2] - a[2]) * (b[2] - a[2]))));
275
 }
275
 }
276
 
276
 
284
 
284
 
285
 
285
 
286
 vec_t helNorm4v(vec4_t v)
286
 vec_t helNorm4v(vec4_t v)
287
-{ 
287
+{
288
 	return (sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3]));
288
 	return (sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3]));
289
 }
289
 }
290
 
290
 
291
 
291
 
292
 vec_t helNorm3v(vec3_t v)
292
 vec_t helNorm3v(vec3_t v)
293
-{ 
293
+{
294
 	return (sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]));
294
 	return (sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]));
295
-} 
295
+}
296
 
296
 
297
 
297
 
298
 vec_t helNorm2v(vec2_t v)
298
 vec_t helNorm2v(vec2_t v)
299
-{ 
299
+{
300
 	return (sqrt(v[0]*v[0] + v[1]*v[1]));
300
 	return (sqrt(v[0]*v[0] + v[1]*v[1]));
301
 }
301
 }
302
 
302
 
321
 vec_t helRadToDeg(vec_t rad)
321
 vec_t helRadToDeg(vec_t rad)
322
 {
322
 {
323
 #ifdef COMPUTE
323
 #ifdef COMPUTE
324
-	return ((rad / HEL_PI) * 180.0); 
324
+	return ((rad / HEL_PI) * 180.0);
325
 #else
325
 #else
326
 	// rad * (PI / 180.0);
326
 	// rad * (PI / 180.0);
327
 	return (rad * HEL_PI_OVER_180);
327
 	return (rad * HEL_PI_OVER_180);
334
 
334
 
335
 void helMathTest()
335
 void helMathTest()
336
 {
336
 {
337
-	printf("180/PI: %f, %f, %f\n", 
338
-			 HEL_180_OVER_PI, 
337
+	printf("180/PI: %f, %f, %f\n",
338
+			 HEL_180_OVER_PI,
339
 			 180.0f / HEL_PI,
339
 			 180.0f / HEL_PI,
340
 			 180.0 / M_PI);
340
 			 180.0 / M_PI);
341
 }
341
 }
342
 
342
 
343
 
343
 
344
-int main(int argc, char *argv)
344
+int main(int argc, char *argv[])
345
 {
345
 {
346
 	helMathTest();
346
 	helMathTest();
347
 
347
 

正在加载...
取消
保存