Changeset 2840
- Timestamp:
- Mar 10, 2012, 9:19:31 PM (13 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/R2/src/R2Fonts.cpp
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <stdarg.h> 3 4 #include <fstream> 5 2 6 #include <R2/R2Fonts.h> 3 7 #include <R2/R2FilePath.h> 4 #include <fstream>5 #include <stdarg.h>6 8 7 9 // constants -
trunk/packages/vizservers/nanovis/R2/src/R2Geometry.cpp
r2798 r2840 2 2 #include <GL/glew.h> 3 3 #include <GL/gl.h> 4 4 5 #include <R2/graphics/R2Geometry.h> 5 6 -
trunk/packages/vizservers/nanovis/R2/src/R2IndexBuffer.cpp
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <R2/graphics/R2IndexBuffer.h>3 2 #include <stdlib.h> 4 3 #include <memory.h> 4 5 #include <R2/graphics/R2IndexBuffer.h> 5 6 6 7 R2IndexBuffer::R2IndexBuffer(int indexCount, int* data, bool copy) -
trunk/packages/vizservers/nanovis/R2/src/R2VertexBuffer.cpp
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <GL/glew.h>3 #include <R2/graphics/R2VertexBuffer.h>4 #include <GL/gl.h>5 2 #include <memory.h> 6 3 #include <stdlib.h> 4 5 #include <GL/glew.h> 6 #include <GL/gl.h> 7 8 #include <R2/graphics/R2VertexBuffer.h> 7 9 8 10 R2VertexBuffer::R2VertexBuffer(int type, int vertexCount, int byteSize, void* data, bool copy) -
trunk/packages/vizservers/nanovis/R2/src/R2string.cpp
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <string.h> 3 2 4 #include <R2/R2string.h> 3 #include <string.h>4 5 5 6 R2string::R2string() : -
trunk/packages/vizservers/nanovis/dxReader.cpp
r2839 r2840 121 121 // found origin 122 122 } else if (sscanf(start, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) { 123 int count = 0;124 // found one of the delta lines125 if (ddx != 0.0) {126 dx = ddx;127 count++;128 }129 if (ddy != 0.0) {130 dy = ddy;131 count++;132 }133 if (ddz != 0.0) {134 dz = ddz;135 count++;136 }137 if (count > 1) {138 result.addError("don't know how to handle multiple non-zero"139 " delta values");140 return NULL;141 }123 int count = 0; 124 // found one of the delta lines 125 if (ddx != 0.0) { 126 dx = ddx; 127 count++; 128 } 129 if (ddy != 0.0) { 130 dy = ddy; 131 count++; 132 } 133 if (ddz != 0.0) { 134 dz = ddz; 135 count++; 136 } 137 if (count > 1) { 138 result.addError("don't know how to handle multiple non-zero" 139 " delta values"); 140 return NULL; 141 } 142 142 } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { 143 143 if (isrect && (npts != nx*ny*nz)) { -
trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.cpp
r2831 r2840 6 6 #include "BMPImageLoaderImpl.h" 7 7 #include "Image.h" 8 #include "Trace.h" 8 9 9 10 BMPImageLoaderImpl::BMPImageLoaderImpl() … … 18 19 Image *BMPImageLoaderImpl::load(const char *fileName) 19 20 { 20 printf("BMP loader\n"); 21 fflush(stdout); 21 TRACE("BMP loader\n"); 22 22 Image *image = NULL; 23 23 24 printf("opening image file \"%s\"\n", fileName);24 TRACE("opening image file \"%s\"\n", fileName); 25 25 FILE *f = fopen(fileName, "rb"); 26 26 27 27 if (!f) { 28 printf("File not found\n");28 TRACE("File not found\n"); 29 29 return 0; 30 30 } … … 32 32 char header[54]; 33 33 if (fread(&header, 54, 1, f) != 1) { 34 printf("can't read header of BMP file\n");34 TRACE("can't read header of BMP file\n"); 35 35 return 0; 36 36 } 37 37 38 38 if (header[0] != 'B' || header[1] != 'M') { 39 printf("File is not BMP format\n");39 TRACE("File is not BMP format\n"); 40 40 return 0; 41 41 } … … 50 50 int bits = int(header[28]); //colourdepth 51 51 52 printf("image width = %d height = %d bits=%d\n", width, height, bits); 53 fflush(stdout); 52 TRACE("image width = %d height = %d bits=%d\n", width, height, bits); 54 53 55 54 image = new Image(width, height, _targetImageFormat, 56 55 Image::IMG_UNSIGNED_BYTE, NULL); 57 56 58 printf("image created\n"); 59 fflush(stdout); 57 TRACE("image created\n"); 60 58 61 59 unsigned char *bytes = (unsigned char *)image->getImageBuffer(); 62 60 memset(bytes, 0, sizeof(unsigned char) * width * height * _targetImageFormat); 63 61 64 printf("reset image buffer\n"); 65 fflush(stdout); 62 TRACE("reset image buffer\n"); 66 63 67 64 unsigned int x, y; … … 72 69 if (_targetImageFormat == Image::IMG_RGB) { 73 70 if (fread(bytes, width*height*3, 1, f) != 1) { 74 fprintf(stderr,"can't read image data\n");71 ERROR("can't read image data\n"); 75 72 } 76 73 for (x = 0; x < width*height*3; x += 3) { //except the format is BGR, grr … … 82 79 char *buff = (char*)malloc(width * height * sizeof(unsigned char) * 3); 83 80 if (fread(buff, width*height*3, 1, f) != 1) { 84 fprintf(stderr,"can't read BMP image data\n");81 ERROR("can't read BMP image data\n"); 85 82 } 86 83 for (x = 0, y = 0; x < width*height*3; x += 3, y += 4) { //except the format is BGR, grr … … 96 93 if (_targetImageFormat == Image::IMG_RGBA) { 97 94 if (fread(bytes, width*height*4, 1, f) != 1) { 98 fprintf(stderr,"can't read image data\n");95 ERROR("can't read image data\n"); 99 96 } 100 97 for (x = 0; x < width*height*4; x += 4) { //except the format is BGR, grr … … 106 103 char *buff = (char*)malloc(width * height * sizeof(unsigned char) * 3); 107 104 if (fread(buff, width*height*4, 1, f) != 1) { 108 fprintf(stderr,"can't read BMP image data\n");105 ERROR("can't read BMP image data\n"); 109 106 } 110 107 for (x = 0, y = 0; x < width*height*4; x += 4, y += 3) { //except the format is BGR, grr … … 117 114 case 8: 118 115 if (fread(cols, 256 * 4, 1, f) != 1) { 119 fprintf(stderr,"can't read colortable from BMP file\n");116 ERROR("can't read colortable from BMP file\n"); 120 117 } 121 118 fseek(f,offset,SEEK_SET); … … 124 121 unsigned char byte; 125 122 if (fread(&byte, 1, 1, f) != 1) { 126 fprintf(stderr,"error reading BMP file\n");123 ERROR("error reading BMP file\n"); 127 124 } 128 125 for (int c = 0; c < 3; ++c) { … … 135 132 } 136 133 137 printf("image initialized\n"); 138 fflush(stdout); 134 TRACE("image initialized\n"); 139 135 return image; 140 136 } -
trunk/packages/vizservers/nanovis/imgLoaders/ImageLoaderFactory.cpp
r2831 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <stdio.h>3 4 2 #include <map> 5 3 #include <string> … … 8 6 #include "ImageLoaderImpl.h" 9 7 #include "ImageLoaderFactory.h" 8 #include "Trace.h" 10 9 11 10 ImageLoaderFactory *ImageLoaderFactory::_instance = NULL; … … 31 30 _loaderImpls[ext] = loaderImpl; 32 31 } else { 33 printf("conflicting data loader for .%s files\n", ext.c_str());32 TRACE("conflicting data loader for .%s files\n", ext.c_str()); 34 33 return; 35 34 } … … 45 44 return imageLoader; 46 45 } else { 47 printf("%s file not supported\n", ext.c_str());46 TRACE("%s file not supported\n", ext.c_str()); 48 47 } 49 48 return 0; -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrBBox.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRBBOX_H 3 #define VRBBOX_H 3 4 4 5 #include <vrmath/vrLinmath.h> … … 6 7 #include <vrmath/vrMatrix4x4f.h> 7 8 8 class LmExport vrBBox { 9 public : 10 vrVector3f min; 11 vrVector3f max; 9 class LmExport vrBBox 10 { 11 public: 12 /** 13 * @brief constructor 14 */ 15 vrBBox(); 12 16 17 /** 18 * @brief constructor 19 * @param bbox bounding box 20 */ 21 vrBBox(const vrBBox& bbox); 13 22 23 /** 24 * @brief constructor 25 * @param min minimum point of the bounding box 26 * @param max maximum point of the bounding box 27 */ 28 vrBBox(const vrVector3f& min, const vrVector3f& max); 14 29 15 public : 30 /** 31 * @brief make an empty bounding box 32 */ 33 void makeEmpty(); 16 34 17 /** 35 /** 36 * @brief make an bouning box 37 * @param center the center of bounding box 38 * @param size the size of bounding box 39 */ 40 void make(const vrVector3f& center, const vrVector3f& size); 18 41 19 * @brief constructor 42 /** 43 * @brief check if the bounding box is empty 44 */ 45 bool isEmpty(); 20 46 21 */ 47 /** 48 * @brief extend the bounding box by a point 49 */ 50 void extend(const vrVector3f& point); 22 51 23 vrBBox(); 52 /** 53 * @brief extend the bounding box by a bbox 54 */ 55 void extend(const vrBBox& bbox); 24 56 57 /** 58 * @brief transform a bounding box with an matrix and set the bounding box 59 */ 60 void transform(const vrBBox& box, const vrMatrix4x4f& mat); 25 61 62 /** 63 * @brief check if the bounding box intersect with a box 64 */ 65 bool intersect(const vrBBox& box); 26 66 27 /** 67 /** 68 * @brief check if the bounding box intersect with a point 69 */ 70 bool intersect(const vrVector3f& point); 28 71 29 * @brief constructor 72 float getRadius() const; 73 vrVector3f getCenter() const; 74 vrVector3f getSize() const; 30 75 31 * @param bbox bounding box 32 33 */ 34 35 vrBBox(const vrBBox& bbox); 36 37 38 39 /** 40 41 * @brief constructor 42 43 * @param min minimum point of the bounding box 44 45 * @param max maximum point of the bounding box 46 47 */ 48 49 vrBBox(const vrVector3f& min, const vrVector3f& max); 50 51 52 53 public : 54 55 /** 56 57 * @brief make an empty bounding box 58 59 */ 60 61 void makeEmpty(); 62 63 64 65 /** 66 67 * @brief make an bouning box 68 69 * @param center the center of bounding box 70 71 * @param size the size of bounding box 72 73 */ 74 75 void make(const vrVector3f& center, const vrVector3f& size); 76 77 78 79 /** 80 81 * @brief check if the bounding box is empty 82 83 */ 84 85 bool isEmpty(); 86 87 88 89 /** 90 91 * @brief extend the bounding box by a point 92 93 */ 94 95 void extend(const vrVector3f& point); 96 97 98 99 /** 100 101 * @brief extend the bounding box by a bbox 102 103 */ 104 105 void extend(const vrBBox& bbox); 106 107 108 109 /** 110 111 * @brief transform a bounding box with an matrix and set the bounding box 112 113 */ 114 115 void transform(const vrBBox& box, const vrMatrix4x4f& mat); 116 117 118 119 /** 120 121 * @brief check if the bounding box intersect with a box 122 123 */ 124 125 bool intersect(const vrBBox& box); 126 127 128 129 /** 130 131 * @brief check if the bounding box intersect with a point 132 133 */ 134 135 bool intersect(const vrVector3f& point); 136 137 138 float getRadius(void) const; 139 vrVector3f getCenter(void) const; 140 vrVector3f getSize(void) const; 141 142 76 vrVector3f min; 77 vrVector3f max; 143 78 }; 144 79 145 inline float vrBBox::getRadius( void) const80 inline float vrBBox::getRadius() const 146 81 { 147 82 return max.distance( min ) * 0.5f; 148 83 } 149 84 150 inline vrVector3f vrBBox::getCenter( void) const85 inline vrVector3f vrBBox::getCenter() const 151 86 { 152 153 154 155 156 87 vrVector3f temp; 88 temp.x = (max.x+ min.x) * 0.5f; 89 temp.y = (max.y + min.y) * 0.5f; 90 temp.z = (max.z + min.z) * 0.5f; 91 return temp; 157 92 } 158 93 159 inline vrVector3f vrBBox::getSize( void) const94 inline vrVector3f vrBBox::getSize() const 160 95 { 161 162 163 164 165 96 vrVector3f temp; 97 temp.x = max.x - min.x; 98 temp.y = max.y - min.y; 99 temp.z = max.z - min.z; 100 return temp; 166 101 } 167 102 168 103 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrBPlane.h
r2798 r2840 7 7 * \date Nov. 2006-2007 8 8 */ 9 10 # pragma once9 #ifndef VRBPLANE_H 10 #define VRBPLANE_H 11 11 12 12 #include <vrmath/vrLinmath.h> … … 14 14 #include <vrmath/vrLineSegment.h> 15 15 16 class LmExport vrBPlane { 16 class LmExport vrBPlane 17 { 17 18 public: 18 vrVector3f normal; 19 vrVector3f point; 19 void makePts(const vrVector3f& pt1, const vrVector3f& pt2, const vrVector3f& pt3); 20 void makeNormalPt(const vrVector3f& norm, const vrVector3f& pos); 21 bool intersect(const vrLineSegment &seg, float &d) const; 22 float distance(const vrVector3f& point) const; 23 vrVector3f crossPoint(const vrVector3f& point) const; 20 24 21 public : 22 void makePts(const vrVector3f& pt1, const vrVector3f& pt2, const vrVector3f& pt3); 23 void makeNormalPt(const vrVector3f& norm, const vrVector3f& pos); 24 bool intersect(const vrLineSegment &seg, float &d) const; 25 float distance(const vrVector3f& point) const; 26 vrVector3f crossPoint(const vrVector3f& point) const; 25 vrVector3f normal; 26 vrVector3f point; 27 27 }; 28 29 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrColor4f.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRCOLOR4F_H 3 #define VRCOLOR4F_H 4 3 5 #include <vrmath/vrLinmath.h> 4 6 5 class LmExport vrColor4f { 6 public : 7 float r, g, b, a; 7 class LmExport vrColor4f 8 { 9 public: 10 float r, g, b, a; 8 11 9 public : 10 vrColor4f(); 11 vrColor4f(float r1, float g1, float b1, float a1 = 0); 12 vrColor4f(const vrColor4f& col) 13 : r(col.r), g(col.g), b(col.b), a(col.a) 14 { 15 } 12 vrColor4f(); 16 13 17 public : 18 friend bool operator==(const vrColor4f col1, const vrColor4f& col2); 19 friend bool operator!=(const vrColor4f col1, const vrColor4f& col2); 14 vrColor4f(float r1, float g1, float b1, float a1 = 0); 15 16 vrColor4f(const vrColor4f& col) : 17 r(col.r), g(col.g), b(col.b), a(col.a) 18 {} 19 20 friend bool operator==(const vrColor4f col1, const vrColor4f& col2); 21 friend bool operator!=(const vrColor4f col1, const vrColor4f& col2); 20 22 }; 21 23 22 24 inline bool operator==(const vrColor4f col1, const vrColor4f& col2) 23 25 { 24 26 return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b)); 25 27 } 26 28 27 29 inline bool operator!=(const vrColor4f col1, const vrColor4f& col2) 28 30 { 29 31 return ((col1.r != col2.r) || (col1.g != col2.g) || (col1.b != col2.b)); 30 32 } 33 34 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrLineSegment.h
r2798 r2840 7 7 * \date Nov. 2006-2007 8 8 */ 9 #pragma once 9 #ifndef VRLINESEGMENT_H 10 #define VRLINESEGMENT_H 10 11 11 12 #include <vrmath/vrLinmath.h> … … 13 14 #include <vrmath/vrMatrix4x4f.h> 14 15 15 class LmExport vrLineSegment { 16 class LmExport vrLineSegment 17 { 16 18 public: 17 /** 18 * @brief The position of the line segment 19 */ 20 vrVector3f pos; 19 vrLineSegment(); 21 20 22 /** 23 * @brief The direction of the line segment 24 */ 25 vrVector3f dir; 21 /// Return the point 22 vrVector3f getPoint(float d) const; 26 23 27 /** 28 * @brief The length of the line segment 29 */ 30 float length; 24 /// Transfrom the line segment using mat 25 void transform(const vrMatrix4x4f &transMat, const vrLineSegment &seg); 31 26 32 public : 33 /** 34 * @brief Constructor 35 */ 36 vrLineSegment(); 37 38 /** 39 * @brief Return the point 40 */ 41 vrVector3f getPoint(float d) const; 27 /// The position of the line segment 28 vrVector3f pos; 42 29 43 /** 44 * @brief Transfrom the line segment using mat 45 */ 46 void transform(const vrMatrix4x4f &transMat, const vrLineSegment &seg); 30 /// The direction of the line segment 31 vrVector3f dir; 32 33 /// The length of the line segment 34 float length; 47 35 }; 48 36 49 37 inline vrVector3f vrLineSegment::getPoint(float d) const 50 38 { 39 return vrVector3f(pos.x + d * dir.x, pos.y + d * dir.y, pos.z + d * dir.z); 40 } 51 41 52 return vrVector3f(pos.x + d * dir.x, pos.y + d * dir.y, pos.z + d * dir.z); 53 } 42 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrLinmath.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRLINMATH_H 3 #define VRLINMATH_H 3 4 4 5 #ifdef _WIN32 … … 38 39 #endif 39 40 41 #endif 40 42 -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRMATRIX4X4_H 3 #define VRMATRIX4X4_H 3 4 4 5 #include <vrmath/vrLinmath.h> … … 7 8 #include <memory.h> 8 9 9 class LmExport vrMatrix4x4f { 10 float _data[16]; 10 class LmExport vrMatrix4x4f 11 { 12 public: 13 /** 14 * @brief make a identity matrix 15 */ 16 void makeIdentity(); 11 17 12 public : 13 /** 14 * @brief make a identity matrix 15 16 void makeIdentity();18 /** 19 * @brief make a translation matrix 20 * @param translation translation 21 */ 22 void makeTranslation(const vrVector3f& translation); 17 23 18 19 20 * @param translation translation21 22 void makeTranslation(const vrVector3f& translation);24 /** 25 * @brief make a translation matrix 26 * @param x x position 27 */ 28 void makeTranslation(float x, float y, float z); 23 29 24 25 * @brief make a translation matrix26 * @param x x position27 28 void makeTranslation(float x, float y, float z);30 /** 31 * @brief make a rotation matrix 32 * @param rotation rotation 33 */ 34 void makeRotation(const vrRotation& rotation); 29 35 30 31 * @brief make a rotation matrix32 33 34 void makeRotation(const vrRotation& rotation);36 /** 37 * @brief Make a rotation matrix 38 * @param rotation rotation 39 */ 40 void makeRotation(float x, float y, float z, float angle); 35 41 36 /** 37 * @brief Make a rotation matrix 38 * @param rotation rotation 39 */ 40 void makeRotation(float x, float y, float z, float angle); 42 void makeVecRotVec(const vrVector3f& vec1, const vrVector3f& vec2); 41 43 42 void makeVecRotVec(const vrVector3f& vec1, const vrVector3f& vec2); 44 /** 45 * @brief make a scale matrix 46 * @param scale scale 47 */ 48 void makeScale(const vrVector3f& scale); 49 void makeTR(const vrVector3f& translation, const vrRotation& rotation); 50 void makeTRS(const vrVector3f& translation, const vrRotation& rotation, const vrVector3f& scale); 43 51 44 /** 45 * @brief make a scale matrix 46 * @param scale scale 47 */ 48 void makeScale(const vrVector3f& scale); 49 void makeTR(const vrVector3f& translation, const vrRotation& rotation); 50 void makeTRS(const vrVector3f& translation, const vrRotation& rotation, const vrVector3f& scale); 52 void multiply(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2); 51 53 52 void multiply(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2); 54 void multiply(const vrMatrix4x4f& mat1, const vrVector3f& position); 55 void multiplyScale(const vrMatrix4x4f& mat, const vrVector3f& scale); 56 void multiply(const vrMatrix4x4f& mat1, const vrRotation& rotation); 57 void multiply(const vrVector3f& position, const vrMatrix4x4f& mat1); 58 void multiply(const vrRotation& rotation, const vrMatrix4x4f& mat1); 59 void multiplyScale(const vrVector3f& scale, const vrMatrix4x4f& mat); 53 60 54 void multiply(const vrMatrix4x4f& mat1, const vrVector3f& position); 55 void multiplyScale(const vrMatrix4x4f& mat, const vrVector3f& scale); 56 void multiply(const vrMatrix4x4f& mat1, const vrRotation& rotation); 57 void multiply(const vrVector3f& position, const vrMatrix4x4f& mat1); 58 void multiply(const vrRotation& rotation, const vrMatrix4x4f& mat1); 59 void multiplyScale(const vrVector3f& scale, const vrMatrix4x4f& mat); 61 void multiply(const vrMatrix4x4f& mat1); 62 void multiplyFast(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2); 60 63 61 void multiply(const vrMatrix4x4f& mat1); 62 void multiplyFast(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2); 64 void invert(); 65 void invert(const vrMatrix4x4f& mat); 66 void invertFast(const vrMatrix4x4f& mat); 63 67 64 void invert(); 65 void invert(const vrMatrix4x4f& mat); 66 void invertFast(const vrMatrix4x4f& mat); 68 void transpose(); 69 void transpose(const vrMatrix4x4f& mat); 70 void transposeFast(const vrMatrix4x4f& mat); 71 72 void getTranslation(vrVector3f& vector); 73 void getRotation(vrRotation& rotation); 67 74 68 void transpose(); 69 void transpose(const vrMatrix4x4f& mat); 70 void transposeFast(const vrMatrix4x4f& mat); 71 72 void getTranslation(vrVector3f& vector); 73 void getRotation(vrRotation& rotation); 75 /** 76 * @brief return data pointer of the matrix 77 * @return float array of the matrix 78 */ 79 const float *get() const; 74 80 75 76 77 78 79 const float* get() const;81 /** 82 * @brief return data pointer of the matrix 83 * @return float array of the matrix 84 */ 85 float *get(); 80 86 81 82 * @brief return data pointer of the matrix 83 * @return float array of the matrix 84 85 float* get();87 /** 88 * @brief set float arrary to this 89 * @param m float matrix values 90 */ 91 void set(float *m); 86 92 87 88 * @brief set floatarrary to this89 90 91 void set(float*m);93 /** 94 * @brief set double arrary to this 95 * @param m float matrix values 96 */ 97 void set(double *m); 92 98 93 /** 94 * @brief set double arrary to this 95 * @param m float matrix values 96 */ 97 void set(double* m); 99 private: 100 float _data[16]; 98 101 }; 99 102 100 inline const float *vrMatrix4x4f::get() const103 inline const float *vrMatrix4x4f::get() const 101 104 { 102 105 return _data; 103 106 } 104 107 105 inline float *vrMatrix4x4f::get()108 inline float *vrMatrix4x4f::get() 106 109 { 107 110 return _data; 108 111 } 109 112 110 inline void vrMatrix4x4f::set(float *m)113 inline void vrMatrix4x4f::set(float *m) 111 114 { 112 115 memcpy(_data, m, sizeof(float) * 16); 113 116 } 114 117 … … 116 119 inline void vrMatrix4x4f::getTranslation(vrVector3f& translation) 117 120 { 118 121 translation.set(_data[12],_data[13], _data[14]); 119 122 } 120 123 121 124 inline void vrMatrix4x4f::makeTRS(const vrVector3f& translation, const vrRotation& rotation, const vrVector3f& scale) 122 125 { 123 124 126 vrMatrix4x4f mat; 127 mat.makeTR(translation, rotation); 125 128 126 129 makeScale(scale); 127 130 128 131 multiply(mat, *this); 129 132 } 130 133 131 134 inline void vrMatrix4x4f::makeTR(const vrVector3f& translation, const vrRotation& rotation) 132 135 { 133 136 makeRotation(rotation); 134 137 135 136 137 138 _data[12] = translation.x; 139 _data[13] = translation.y; 140 _data[14] = translation.z; 138 141 } 142 143 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrPlane.h
r2798 r2840 7 7 * \date Nov. 2006-2007 8 8 */ 9 10 # pragma once9 #ifndef VRPLANE_H 10 #define VRPLANE_H 11 11 12 12 #include <vrmath/vrLinmath.h> … … 15 15 #include <vrmath/vrVector3f.h> 16 16 17 class LmExport vrPlane { 18 public : 19 /** 20 * @brief normal vector 21 */ 22 vrVector3f normal; 23 24 /** 25 * @brief the distance from the origin 26 */ 27 float distance; 28 29 public : 30 bool intersect(const vrVector3f& p1, const vrVector3f& p2, vrVector3f& intersectPoint) const; 17 class LmExport vrPlane 18 { 19 public: 20 bool intersect(const vrVector3f& p1, const vrVector3f& p2, vrVector3f& intersectPoint) const; 31 21 bool intersect(const vrVector3f& p1, const vrVector3f& p2, vrVector4f& intersectPoint) const; 32 22 void transform(vrMatrix4x4f& mat); 23 24 /// normal vector 25 vrVector3f normal; 26 27 /// @brief the distance from the origin 28 float distance; 33 29 }; 34 30 35 31 inline bool vrPlane::intersect(const vrVector3f& p1, const vrVector3f& p2, vrVector3f& intersectPoint) const 36 32 { 37 38 39 33 // http://astronomy.swin.edu.au/pbourke/geometry/planeline/ 34 float numerator = normal.x * p1.x + normal.y * p1.y + normal.z * p1.z; 35 float denominator = normal.x * (p1.x - p2.x) + normal.y * (p1.y - p2.y) + normal.z * (p1.z - p2.z); 40 36 41 37 if (denominator == 0.0f) return false; 42 38 43 float u = numerator / denominator; 44 if ((u > 0) && (u < 1.0f)) 45 { 46 return true; 47 } 39 float u = numerator / denominator; 40 if ((u > 0) && (u < 1.0f)) { 41 return true; 42 } 48 43 49 44 intersectPoint.x = p1.x + u * (p2.x - p1.x); … … 51 46 intersectPoint.z = p1.z + u * (p2.z - p1.z); 52 47 53 48 return false; 54 49 } 55 50 56 51 inline bool vrPlane::intersect(const vrVector3f& p1, const vrVector3f& p2, vrVector4f& intersectPoint) const 57 52 { 58 59 60 61 62 53 // http://astronomy.swin.edu.au/pbourke/geometry/planeline/ 54 float numerator = normal.x * p1.x + normal.y * p1.y + normal.z * p1.z; 55 float denominator = normal.x * (p1.x - p2.x) + normal.y * (p1.y - p2.y) + normal.z * (p1.z - p2.z); 56 if (denominator == 0.0f) return false; 57 float u = numerator / denominator; 63 58 64 if ((u > 0) && (u < 1.0f)) 65 { 66 return true; 67 } 59 if ((u > 0) && (u < 1.0f)) { 60 return true; 61 } 68 62 69 63 intersectPoint.x = p1.x + u * (p2.x - p1.x); … … 72 66 intersectPoint.w = 1.0f; 73 67 74 68 return false; 75 69 } 70 71 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrPlane2.h
r2798 r2840 6 6 * \version 1.0 7 7 */ 8 9 # pragma once8 #ifndef VRPLANE2_H 9 #define VRPLANE2_H 10 10 11 11 #include <vrmath/vrLinmath.h> … … 13 13 #include <vrmath/vrLineSegment.h> 14 14 15 class LmExport vrPlane2 { 15 class LmExport vrPlane2 16 { 16 17 public: 17 vrVector3f normal; 18 vrVector3f point; 18 void makePts(const vrVector3f& pt1, const vrVector3f& pt2, const vrVector3f& pt3); 19 void makeNormalPt(const vrVector3f& norm, const vrVector3f& pos); 20 bool intersect(const vrLineSegment &seg, float &d) const; 21 float distance(const vrVector3f& point) const; 22 vrVector3f crossPoint(const vrVector3f& point) const; 19 23 20 public : 21 void makePts(const vrVector3f& pt1, const vrVector3f& pt2, const vrVector3f& pt3); 22 void makeNormalPt(const vrVector3f& norm, const vrVector3f& pos); 23 bool intersect(const vrLineSegment &seg, float &d) const; 24 float distance(const vrVector3f& point) const; 25 vrVector3f crossPoint(const vrVector3f& point) const; 24 vrVector3f normal; 25 vrVector3f point; 26 26 }; 27 28 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrProjection.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRPROJECTION_H 3 #define VRPROJECTION_H 3 4 4 5 #ifdef __cplusplus … … 6 7 #endif 7 8 8 LmExport int unproject(float winx, float winy, float winz, 9 const float modelMatrix[16], 10 const float projMatrix[16], 11 const int viewport[4], 12 float *objx, float *objy, float *objz); 9 LmExport int 10 unproject(float winx, float winy, float winz, 11 const float modelMatrix[16], 12 const float projMatrix[16], 13 const int viewport[4], 14 float *objx, float *objy, float *objz); 13 15 14 LmExport void perspective(float fovy, float aspect, float zNear, float zFar, float* matrix); 16 LmExport void 17 perspective(float fovy, float aspect, float zNear, float zFar, float *matrix); 15 18 16 19 #ifdef __cplusplus … … 18 21 #endif 19 22 23 #endif 24 -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrQuaternion.h
r2798 r2840 6 6 * I (Insoo Woo) have changed names according to my naming rules 7 7 */ 8 #ifndef VRQUATERNION_H 9 #define VRQUATERNION_H 8 10 9 #pragma once10 11 #include <vrmath/vrLinmath.h> 11 12 12 13 class vrRotation; 13 14 14 class LmExport vrQuaternion { 15 public : 16 float x, y, z, w; 15 class LmExport vrQuaternion 16 { 17 public: 18 vrQuaternion(); 19 explicit vrQuaternion(const vrRotation& rot); 20 vrQuaternion(float x, float y = 0, float z = 0, float w = 0); 17 21 18 public : 19 vrQuaternion(); 20 explicit vrQuaternion(const vrRotation& rot); 21 vrQuaternion(float x, float y = 0, float z = 0, float w = 0); 22 void set(float x1, float y1, float z1, float w1); 23 const vrQuaternion& set(const vrRotation& rot); 22 24 23 public : 24 const vrQuaternion& set(const vrRotation& rot); 25 void slerp(const vrRotation &a,const vrRotation &b, const float t); 26 void slerp(const vrQuaternion &a,const vrQuaternion &b, const float t); 27 const vrQuaternion& normalize(); 28 friend bool operator==(const vrQuaternion& q1, const vrQuaternion& q2); 29 void set(float x1, float y1, float z1, float w1); 25 void slerp(const vrRotation &a,const vrRotation &b, const float t); 26 27 void slerp(const vrQuaternion &a,const vrQuaternion &b, const float t); 28 29 const vrQuaternion& normalize(); 30 31 friend bool operator==(const vrQuaternion& q1, const vrQuaternion& q2); 32 33 float x, y, z, w; 30 34 }; 31 35 32 36 inline bool operator==(const vrQuaternion& q1, const vrQuaternion& q2) 33 37 { 34 38 return ((q1.x == q2.x) && (q1.y == q2.y) && (q1.z == q2.z) && (q1.w == q2.w)); 35 39 } 36 40 37 41 inline void vrQuaternion::slerp(const vrRotation &a,const vrRotation &b, const float t) 38 42 { 39 43 slerp(vrQuaternion(a), vrQuaternion(b), t); 40 44 } 41 45 42 46 inline void vrQuaternion::set(float x1, float y1, float z1, float w1) 43 47 { 44 45 46 47 48 x = x1; 49 y = y1; 50 z = z1; 51 w = w1; 48 52 } 53 54 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrRotation.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRROTATION_H 3 #define VRROTATION_H 3 4 4 5 #include <vrmath/vrLinmath.h> … … 7 8 class vrQuaternion; 8 9 9 class LmExport vrRotation { 10 public : 11 float x, y, z, angle; 10 class LmExport vrRotation 11 { 12 public: 13 vrRotation() : 14 x(0.0f), y(1.0f), z(0.0f), angle(0.0f) 15 {} 12 16 13 public : 17 vrRotation(float x1, float y1, float z1, float angle1) : 18 x(x1), y(y1), z(z1), angle(angle1) 19 {} 14 20 15 vrRotation() : x(0.0f), y(1.0f), z(0.0f), angle(0.0f) {} 16 vrRotation(float x1, float y1, float z1, float angle1) 17 : x(x1), y(y1), z(z1), angle(angle1){}21 vrRotation(const vrRotation& rotation) : 22 x(rotation.x), y(rotation.y), z(rotation.z), angle(rotation.angle) 23 {} 18 24 19 vrRotation(const vrRotation& rotation) 20 : x(rotation.x), y(rotation.y), z(rotation.z), angle(rotation.angle) {} 25 float getX() const; 26 float getY() const; 27 float getZ() const; 28 float getAngle() const; 21 29 22 float getX() const; 23 float getY() const; 24 float getZ() const; 25 float getAngle() const; 30 void set(float x, float y, float z, float angle); 31 void set(const vrVector3f &vec1, const vrVector3f &vec2); 32 void set(const vrQuaternion& quat); 33 void set(const vrRotation& rot); 34 void setAxis(float x, float y, float z); 35 void setAngle(float angle); 36 37 friend bool operator!=(const vrRotation& rot1, const vrRotation& rot2); 38 friend bool operator==(const vrRotation& rot1, const vrRotation& rot2); 26 39 27 void set(float x, float y, float z, float angle); 28 void set(const vrVector3f &vec1, const vrVector3f &vec2); 29 void set(const vrQuaternion& quat); 30 void set(const vrRotation& rot); 31 void setAxis(float x, float y, float z); 32 void setAngle(float angle); 33 34 friend bool operator!=(const vrRotation& rot1, const vrRotation& rot2); 35 friend bool operator==(const vrRotation& rot1, const vrRotation& rot2); 36 40 float x, y, z, angle; 37 41 }; 38 39 40 42 41 43 inline float vrRotation::getX() const 42 44 { 43 45 return x; 44 46 } 45 47 46 48 inline float vrRotation::getY() const 47 49 { 48 50 return y; 49 51 } 50 52 51 53 inline float vrRotation::getZ() const 52 54 { 53 55 return z; 54 56 } 55 57 56 58 inline float vrRotation::getAngle() const 57 59 { 58 60 return angle; 59 61 } 60 62 61 63 inline void vrRotation::set(float x, float y, float z, float angle) 62 64 { 63 65 this->x = x; this->y = y; this->z = z; this->angle = angle; 64 66 } 65 67 66 68 inline void vrRotation::set(const vrRotation& rot) 67 69 { 68 70 this->x = rot.x; this->y = rot.y; this->z = rot.z; this->angle = rot.angle; 69 71 } 70 72 71 73 inline void vrRotation::setAxis(float x, float y, float z) 72 74 { 73 75 this->x = x; this->y = y; this->z = z; 74 76 } 75 77 76 78 inline void vrRotation::setAngle(float angle) 77 79 { 78 80 this->angle = angle; 79 81 } 80 82 81 83 inline bool operator==(const vrRotation& rot1, const vrRotation& rot2) 82 84 { 83 85 return ((rot1.x == rot2.x) && (rot1.y == rot2.y) && (rot1.z == rot2.z) && (rot1.angle == rot2.angle)); 84 86 } 85 87 86 88 inline bool operator!=(const vrRotation& rot1, const vrRotation& rot2) 87 89 { 88 90 return ((rot1.x != rot2.x) || (rot1.y != rot2.y) || (rot1.z != rot2.z) || (rot1.angle != rot2.angle)); 89 91 } 90 92 93 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrVector2f.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRVECTOR2F_H 3 #define VRVECTOR2F_H 4 3 5 #include <vrmath/vrLinmath.h> 4 6 … … 6 8 #include <cmath> 7 9 8 //#define LmExport 9 class LmExport vrVector2f { 10 public : 11 float x, y; 10 class LmExport vrVector2f 11 { 12 public: 13 vrVector2f() : 14 x(0.0f), y(0.0f) 15 {} 12 16 13 public : 14 vrVector2f() : x(0.0f), y(0.0f) {} 15 vrVector2f(const vrVector2f& v) : x(v.x), y(v.y) {} 16 vrVector2f(float x1, float y1) : x(x1), y(y1) {} 17 vrVector2f(const vrVector2f& v) : 18 x(v.x), y(v.y) 19 {} 17 20 18 void set(float x1, float y1); 19 void set(const vrVector2f& v); 21 vrVector2f(float x1, float y1) : 22 x(x1), y(y1) 23 {} 20 24 21 float dot() const; 22 float length() const; 23 float distance(const vrVector2f& v) const; 24 float distance(float x1, float y1) const; 25 float distanceSquare(const vrVector2f& v) const; 26 float distanceSquare(float x1, float y1) const; 25 void set(float x1, float y1); 26 27 void set(const vrVector2f& v); 28 29 float dot() const; 30 31 float length() const; 32 33 float distance(const vrVector2f& v) const; 34 35 float distance(float x1, float y1) const; 36 37 float distanceSquare(const vrVector2f& v) const; 38 39 float distanceSquare(float x1, float y1) const; 40 41 float x, y; 27 42 }; 28 43 29 44 inline void vrVector2f::set(float x1, float y1) 30 45 { 31 32 46 x = x1; 47 y = y1; 33 48 } 34 49 35 50 inline void vrVector2f::set(const vrVector2f& v) 36 51 { 37 38 52 x = v.x; 53 y = v.y; 39 54 } 40 55 41 56 inline float vrVector2f::dot() const 42 57 { 43 58 return (x * x + y * y); 44 59 } 45 46 60 47 61 inline float vrVector2f::length() const 48 62 { 49 63 return sqrt(x * x + y * y); 50 64 } 51 52 53 65 54 66 inline float vrVector2f::distance(const vrVector2f& v) const 55 67 { 56 57 68 float x1 = (v.x - x) , y1 = (v.y - y); 69 return sqrt(x1 * x1 + y1 * y1); 58 70 } 59 60 61 71 62 72 inline float vrVector2f::distance(float x1, float y1) const 63 73 { 64 65 74 float x2 = (x1 - x) , y2 = (y1 - y); 75 return sqrt(x2 * x2 + y2 * y2); 66 76 } 67 68 69 70 77 71 78 inline float vrVector2f::distanceSquare(const vrVector2f& v) const 72 79 { 73 74 80 float x1 = (v.x - x) , y1 = (v.y - y); 81 return (x1 * x1 + y1 * y1); 75 82 } 76 83 77 84 inline float vrVector2f::distanceSquare(float x1, float y1) const 78 85 { 79 80 86 float x2 = (x1 - x) , y2 = (y1 - y); 87 return (x2 * x2 + y2 * y2); 81 88 } 89 90 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrVector3f.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRVECTOR3F_H 3 #define VRVECTOR3F_H 3 4 4 5 #include <cstdlib> 5 6 #include <cmath> 7 6 8 #include <vrmath/vrLinmath.h> 9 7 10 class vrMatrix4x4f; 8 11 9 class LmExport vrVector3f { 10 public : 11 float x, y, z; 12 13 public : 14 vrVector3f() : x(0.0f), y(0.0f), z(0.0f) {} 15 vrVector3f(const vrVector3f& v3) : x(v3.x), y(v3.y), z(v3.z) {} 16 vrVector3f(float x1, float y1, float z1) : x(x1), y(y1), z(z1) {} 17 18 void set(float x1, float y1, float z1); 19 void set(const vrVector3f& v3); 20 21 float dot(const vrVector3f& v) const; 22 float length() const; 23 float distance(const vrVector3f& v3) const; 24 float distance(float x1, float y1, float z1) const; 25 float distanceSquare(const vrVector3f& v3) const; 26 float distanceSquare(float x1, float y1, float z1) const; 27 28 void cross(const vrVector3f& v1, const vrVector3f& v2); 29 void cross(const vrVector3f& v1); 30 31 void transform(const vrMatrix4x4f& m, const vrVector3f& v); 32 void transformVec(const vrMatrix4x4f& m, const vrVector3f& v); 33 void scale(vrVector3f& sc); 12 class LmExport vrVector3f 13 { 14 public: 15 vrVector3f() : 16 x(0.0f), y(0.0f), z(0.0f) 17 {} 18 19 vrVector3f(const vrVector3f& v3) : 20 x(v3.x), y(v3.y), z(v3.z) 21 {} 22 23 vrVector3f(float x1, float y1, float z1) : 24 x(x1), y(y1), z(z1) 25 {} 26 27 void set(float x1, float y1, float z1); 28 29 void set(const vrVector3f& v3); 30 31 float dot(const vrVector3f& v) const; 32 33 float length() const; 34 35 float distance(const vrVector3f& v3) const; 36 37 float distance(float x1, float y1, float z1) const; 38 39 float distanceSquare(const vrVector3f& v3) const; 40 41 float distanceSquare(float x1, float y1, float z1) const; 42 43 void cross(const vrVector3f& v1, const vrVector3f& v2); 44 45 void cross(const vrVector3f& v1); 46 47 void transform(const vrMatrix4x4f& m, const vrVector3f& v); 48 49 void transformVec(const vrMatrix4x4f& m, const vrVector3f& v); 50 51 void scale(vrVector3f& sc); 52 34 53 float normalize(); 35 void scale(float scale); 36 bool operator==(const vrVector3f& v) const; 37 bool operator!=(const vrVector3f& v) const; 38 friend vrVector3f operator-(const vrVector3f& value1, const vrVector3f& value2); 39 friend vrVector3f operator+(const vrVector3f& value1, const vrVector3f& value2); 40 friend vrVector3f operator*(const vrVector3f& value, float scale); 41 vrVector3f& operator+=(const vrVector3f& value1); 42 vrVector3f operator*(const vrVector3f& scale); // scale 43 vrVector3f operator*(float scale); 44 vrVector3f operator-(void) const ; 45 46 bool isEqual(const vrVector3f& v) const; 47 bool isAlmostEqual(const vrVector3f& v, float tol) const; 48 49 float getX() const; 50 float getY() const; 51 float getZ() const; 54 55 void scale(float scale); 56 57 bool operator==(const vrVector3f& v) const; 58 59 bool operator!=(const vrVector3f& v) const; 60 61 vrVector3f& operator+=(const vrVector3f& value1); 62 vrVector3f operator*(const vrVector3f& scale); // scale 63 vrVector3f operator*(float scale); 64 vrVector3f operator-(void) const ; 65 66 bool isEqual(const vrVector3f& v) const; 67 bool isAlmostEqual(const vrVector3f& v, float tol) const; 68 69 float getX() const; 70 float getY() const; 71 float getZ() const; 72 73 friend vrVector3f operator-(const vrVector3f& value1, const vrVector3f& value2); 74 friend vrVector3f operator+(const vrVector3f& value1, const vrVector3f& value2); 75 friend vrVector3f operator*(const vrVector3f& value, float scale); 76 77 float x, y, z; 52 78 }; 53 79 … … 55 81 inline bool vrVector3f::operator==(const vrVector3f &v) const 56 82 { 57 83 return ( v.x == x && v.y == y && v.z == z); 58 84 } 59 85 60 86 inline bool vrVector3f::operator!=(const vrVector3f &v) const 61 87 { 62 88 return !(v.x == x && v.y == y && v.z == z); 63 89 } 64 90 65 91 inline vrVector3f vrVector3f::operator*(float scale) 66 92 { 67 68 69 70 71 93 vrVector3f vec; 94 vec.x = x * scale; 95 vec.y = y * scale; 96 vec.z = z * scale; 97 return vec; 72 98 } 73 99 74 100 inline vrVector3f vrVector3f::operator*(const vrVector3f& scale) 75 101 { 76 77 78 79 80 102 vrVector3f vec; 103 vec.x = x * scale.x; 104 vec.y = y * scale.y; 105 vec.z = z * scale.z; 106 return vec; 81 107 } 82 108 83 109 inline vrVector3f& vrVector3f::operator+=(const vrVector3f& scale) 84 110 { 85 86 87 88 111 x = x + scale.x; 112 y = y + scale.y; 113 z = z + scale.z; 114 return *this; 89 115 } 90 116 91 117 inline vrVector3f operator-(const vrVector3f& value1, const vrVector3f& value2) 92 118 { 93 119 return vrVector3f(value1.x - value2.x, value1.y - value2.y, value1.z - value2.z); 94 120 } 95 121 96 122 inline vrVector3f operator+(const vrVector3f& value1, const vrVector3f& value2) 97 123 { 98 124 return vrVector3f(value1.x + value2.x, value1.y + value2.y, value1.z + value2.z); 99 125 } 100 126 101 127 inline void vrVector3f::set(float x1, float y1, float z1) 102 128 { 103 104 105 129 x = x1; 130 y = y1; 131 z = z1; 106 132 } 107 133 108 134 inline void vrVector3f::set(const vrVector3f& v3) 109 135 { 110 111 112 136 x = v3.x; 137 y = v3.y; 138 z = v3.z; 113 139 } 114 140 115 141 inline float vrVector3f::dot(const vrVector3f& v) const 116 142 { 117 143 return (x * v.x + y * v.y + z * v.z); 118 144 } 119 145 120 146 inline float vrVector3f::length() const 121 147 { 122 148 return sqrt(x * x + y * y + z * z); 123 149 } 124 150 125 151 inline float vrVector3f::distance(const vrVector3f& v3) const 126 152 { 127 128 153 float x1 = (v3.x - x) , y1 = (v3.y - y), z1 = (v3.z - z); 154 return sqrt(x1 * x1 + y1 * y1 + z1 * z1); 129 155 } 130 156 131 157 inline float vrVector3f::distance(float x1, float y1, float z1) const 132 158 { 133 134 159 float x2 = (x1 - x) , y2 = (y1 - y), z2 = (z1 - z); 160 return sqrt(x2 * x2 + y2 * y2 + z2 * z2); 135 161 } 136 162 137 163 inline float vrVector3f::distanceSquare(const vrVector3f& v3) const 138 164 { 139 140 165 float x1 = (v3.x - x) , y1 = (v3.y - y), z1 = (v3.z - z); 166 return (x1 * x1 + y1 * y1 + z1 * z1); 141 167 } 142 168 143 169 inline float vrVector3f::distanceSquare(float x1, float y1, float z1) const 144 170 { 145 146 171 float x2 = (x1 - x) , y2 = (y1 - y), z2 = (z1 - z); 172 return (x2 * x2 + y2 * y2 + z2 * z2); 147 173 } 148 174 149 175 inline void vrVector3f::cross(const vrVector3f& v1, const vrVector3f& v2) 150 176 { 151 152 153 154 155 156 157 158 177 float vec[3]; 178 vec[0] = v1.y * v2.z - v2.y * v1.z; 179 vec[1] = v1.z * v2.x - v2.z * v1.x; 180 vec[2] = v1.x * v2.y - v2.x * v1.y; 181 182 x = vec[0]; 183 y = vec[1]; 184 z = vec[2]; 159 185 } 160 186 161 187 inline void vrVector3f::cross(const vrVector3f& v1) 162 188 { 163 164 165 166 167 168 169 189 float vec[3]; 190 vec[0] = y * v1.z - v1.y * z; 191 vec[1] = z * v1.x - v1.z * x; 192 vec[2] = x * v1.y - v1.x * y; 193 x = vec[0]; 194 y = vec[1]; 195 z = vec[2]; 170 196 } 171 197 … … 173 199 { 174 200 float inverseLength = length(); 175 if (inverseLength != 0) 176 { 201 if (inverseLength != 0) { 177 202 inverseLength = 1 / inverseLength; 178 203 x *= inverseLength; … … 181 206 } 182 207 183 208 return inverseLength; 184 209 } 185 210 186 211 inline void vrVector3f::scale(float scale) 187 212 { 188 189 190 213 x *= scale; 214 y *= scale; 215 z *= scale; 191 216 } 192 217 193 218 inline void vrVector3f::scale(vrVector3f& sc) 194 219 { 195 196 197 220 x *= sc.x; 221 y *= sc.y; 222 z *= sc.z; 198 223 } 199 224 200 225 inline vrVector3f operator*(const vrVector3f& value, float scale) 201 226 { 202 227 return vrVector3f(value.x * scale, value.y * scale, value.z * scale); 203 228 } 204 229 … … 210 235 } 211 236 212 213 237 inline bool vrVector3f::isEqual(const vrVector3f& v) const 214 238 { … … 216 240 } 217 241 218 219 220 242 inline vrVector3f vrVector3f::operator-() const 221 243 { … … 223 245 } 224 246 225 226 247 inline float vrVector3f::getX() const 227 248 { 228 249 return x; 229 250 } 230 251 231 252 inline float vrVector3f::getY() const 232 253 { 233 254 return y; 234 255 } 235 256 236 257 inline float vrVector3f::getZ() const 237 258 { 238 return z; 239 } 259 return z; 260 } 261 262 #endif -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrVector4f.h
r2798 r2840 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #pragma once 2 #ifndef VRVECTOR4F_H 3 #define VRVECTOR4F_H 3 4 4 5 #include <vrmath/vrLinmath.h> … … 8 9 class vrMatrix4x4f; 9 10 10 class LmExport vrVector4f { 11 public : 12 float x, y, z, w; 11 class LmExport vrVector4f 12 { 13 public: 14 vrVector4f() : 15 x(0.0f), y(0.0f), z(0.0f), w(0.0f) 16 {} 13 17 14 public : 15 vrVector4f() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} 16 vrVector4f(const vrVector4f& v4) : x(v4.x), y(v4.y), z(v4.z) , w(v4.w) {} 17 vrVector4f(const vrVector3f& v3, float w1) : x(v3.x), y(v3.y), z(v3.z) , w(w1) {} 18 vrVector4f(float x1, float y1, float z1, float w1) : x(x1), y(y1), z(z1), w(w1) {} 18 vrVector4f(const vrVector4f& v4) : 19 x(v4.x), y(v4.y), z(v4.z), w(v4.w) 20 {} 19 21 20 void set(float x1, float y1, float z1, float w1); 21 void set(const vrVector3f& v, float w); 22 void set(const vrVector4f& v4); 22 vrVector4f(const vrVector3f& v3, float w1) : 23 x(v3.x), y(v3.y), z(v3.z), w(w1) 24 {} 25 26 vrVector4f(float x1, float y1, float z1, float w1) : 27 x(x1), y(y1), z(z1), w(w1) 28 {} 29 30 void set(float x1, float y1, float z1, float w1); 31 32 void set(const vrVector3f& v, float w); 33 34 void set(const vrVector4f& v4); 35 23 36 void divideByW(); 37 24 38 float dot(const vrVector4f& vec); 39 25 40 void mult(const vrMatrix4x4f& mat, const vrVector4f& vec); 41 26 42 void mult(const vrMatrix4x4f& mat); 27 43 28 void transform(const vrVector4f& v, const vrMatrix4x4f& m); 44 void transform(const vrVector4f& v, const vrMatrix4x4f& m); 45 46 float x, y, z, w; 29 47 }; 30 48 31 49 inline void vrVector4f::divideByW() 32 50 { 33 if (w != 0) 34 { 51 if (w != 0) { 35 52 x /= w; y /= w; z /= w; 36 53 w = 1.0f; … … 40 57 inline void vrVector4f::set(float x1, float y1, float z1, float w1) 41 58 { 42 43 44 59 x = x1; 60 y = y1; 61 z = z1; 45 62 w = w1; 46 63 } … … 48 65 inline void vrVector4f::set(const vrVector4f& v4) 49 66 { 50 51 52 67 x = v4.x; 68 y = v4.y; 69 z = v4.z; 53 70 w = v4.w; 54 71 } … … 56 73 inline void vrVector4f::set(const vrVector3f& v, float w1) 57 74 { 58 59 60 75 x = v.x; 76 y = v.y; 77 z = v.z; 61 78 w = w1; 62 79 } … … 66 83 return x * vec.x + y * vec.y + z * vec.z + w * vec.w; 67 84 } 85 86 #endif -
trunk/packages/vizservers/nanovis/vrmath/vrBBox.cpp
r2798 r2840 4 4 5 5 vrBBox::vrBBox() 6 7 6 { 8 9 makeEmpty(); 10 7 makeEmpty(); 11 8 } 12 9 13 14 15 10 vrBBox::vrBBox(const vrBBox& bbox) 16 17 11 { 18 19 min = bbox.min; 20 21 max = bbox.max; 22 12 min = bbox.min; 13 max = bbox.max; 23 14 } 24 15 25 26 27 16 vrBBox::vrBBox(const vrVector3f& minv, const vrVector3f& maxv) 28 29 17 { 30 31 min = minv; 32 33 max = maxv; 34 18 min = minv; 19 max = maxv; 35 20 } 36 21 37 38 39 40 41 22 void vrBBox::makeEmpty() 42 43 23 { 44 45 float big = 1e27f; 46 47 min.set(big, big, big); 48 49 max.set(-big, -big, -big); 50 24 float big = 1e27f; 25 min.set(big, big, big); 26 max.set(-big, -big, -big); 51 27 } 52 28 29 bool vrBBox::isEmpty() 30 { 31 if ((min.x > max.x) || (min.y > max.y) || (min.z > max.z)) { 32 return true; 33 } 53 34 54 55 bool vrBBox::isEmpty() 56 57 { 58 59 if ((min.x > max.x) || (min.y > max.y) || (min.z > max.z)) 60 61 { 62 63 return true; 64 65 } 66 67 68 69 return false; 70 35 return false; 71 36 } 72 73 74 37 75 38 void vrBBox::make(const vrVector3f& center, const vrVector3f& size) 76 39 { 77 40 float halfX = size.x * 0.5f, halfY = size.y * 0.5f, halfZ = size.z * 0.5f; 78 41 79 80 42 min.x = center.x - halfX; 43 max.x = center.x + halfX; 81 44 45 min.y = center.y - halfY; 46 max.y = center.y + halfY; 82 47 83 84 min.y = center.y - halfY; 85 86 max.y = center.y + halfY; 87 88 89 90 min.z = center.z - halfZ; 91 92 max.z = center.z + halfZ; 93 48 min.z = center.z - halfZ; 49 max.z = center.z + halfZ; 94 50 } 95 51 52 void vrBBox::extend(const vrVector3f& point) 53 { 54 if (min.x > point.x) { 55 min.x = point.x; 56 } else if (max.x < point.x) { 57 max.x = point.x; 58 } 96 59 60 if (min.y > point.y) { 61 min.y = point.y; 62 } else if (max.y < point.y) { 63 max.y = point.y; 64 } 97 65 98 void vrBBox::extend(const vrVector3f& point) 99 100 { 101 102 if (min.x > point.x) 103 104 { 105 106 min.x = point.x; 107 108 } 109 110 else if (max.x < point.x) 111 112 { 113 114 max.x = point.x; 115 116 } 117 118 119 120 if (min.y > point.y) 121 122 { 123 124 min.y = point.y; 125 126 } 127 128 else if (max.y < point.y) 129 130 { 131 132 max.y = point.y; 133 134 } 135 136 137 138 if (min.z > point.z) 139 140 { 141 142 min.z = point.z; 143 144 } 145 146 else if (max.z < point.z) 147 148 { 149 150 max.z = point.z; 151 152 } 153 66 if (min.z > point.z) { 67 min.z = point.z; 68 } else if (max.z < point.z) { 69 max.z = point.z; 70 } 154 71 } 155 72 73 void vrBBox::extend(const vrBBox& box) 74 { 75 if (min.x > box.min.x) min.x = box.min.x; 76 if (min.y > box.min.y) min.y = box.min.y; 77 if (min.z > box.min.z) min.z = box.min.z; 156 78 157 158 void vrBBox::extend(const vrBBox& box) 159 160 { 161 162 if (min.x > box.min.x) min.x = box.min.x; 163 164 if (min.y > box.min.y) min.y = box.min.y; 165 166 if (min.z > box.min.z) min.z = box.min.z; 167 168 169 170 if (max.x < box.max.x) max.x = box.max.x; 171 172 if (max.y < box.max.y) max.y = box.max.y; 173 174 if (max.z < box.max.z) max.z = box.max.z; 175 79 if (max.x < box.max.x) max.x = box.max.x; 80 if (max.y < box.max.y) max.y = box.max.y; 81 if (max.z < box.max.z) max.z = box.max.z; 176 82 } 177 83 84 void vrBBox::transform(const vrBBox& box, const vrMatrix4x4f& mat) 85 { 86 float halfSizeX = (box.max.x - box.min.x) * 0.5f; 87 float halfSizeY = (box.max.y - box.min.y) * 0.5f; 88 float halfSizeZ = (box.max.z - box.min.z) * 0.5f; 178 89 90 float centerX = (box.max.x + box.min.x) * 0.5f; 91 float centerY = (box.max.y + box.min.y) * 0.5f; 92 float centerZ = (box.max.z + box.min.z) * 0.5f; 179 93 180 void vrBBox::transform(const vrBBox& box, const vrMatrix4x4f& mat) 94 vrVector3f points[8]; 181 95 182 { 96 points[0].set(centerX + halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ); 97 points[1].set(centerX + halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ); 98 points[2].set(centerX - halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ); 99 points[3].set(centerX - halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ); 100 points[4].set(centerX - halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ); 101 points[5].set(centerX - halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ); 102 points[6].set(centerX + halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ); 103 points[7].set(centerX + halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ); 183 104 184 float halfSizeX = (box.max.x - box.min.x) * 0.5f; 105 float minX, minY, minZ; 106 float maxX, maxY, maxZ; 185 107 186 float halfSizeY = (box.max.y - box.min.y) * 0.5f;108 points[0].transform(mat, points[0]); 187 109 188 float halfSizeZ = (box.max.z - box.min.z) * 0.5f; 110 minX = maxX = points[0].x; 111 minY = maxY = points[0].y; 112 minZ = maxZ = points[0].z; 189 113 114 for (int i = 1; i < 8; i++) { 115 points[i].transform(mat, points[i]); 190 116 117 if (points[i].x > maxX) maxX = points[i].x; 118 else if (points[i].x < minX) minX = points[i].x; 191 119 192 float centerX = (box.max.x + box.min.x) * 0.5f; 120 if (points[i].y > maxY) maxY = points[i].y; 121 else if (points[i].y < minY) minY = points[i].y; 193 122 194 float centerY = (box.max.y + box.min.y) * 0.5f; 123 if (points[i].z > maxZ) maxZ = points[i].z; 124 else if (points[i].z < minZ) minZ = points[i].z; 125 } 195 126 196 float centerZ = (box.max.z + box.min.z) * 0.5f; 197 198 199 200 vrVector3f points[8]; 201 202 points[0].set(centerX + halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ); 203 204 points[1].set(centerX + halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ); 205 206 points[2].set(centerX - halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ); 207 208 points[3].set(centerX - halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ); 209 210 points[4].set(centerX - halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ); 211 212 points[5].set(centerX - halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ); 213 214 points[6].set(centerX + halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ); 215 216 points[7].set(centerX + halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ); 217 218 219 220 float minX, minY, minZ; 221 222 float maxX, maxY, maxZ; 223 224 225 226 points[0].transform(mat, points[0]); 227 228 minX = maxX = points[0].x; 229 230 minY = maxY = points[0].y; 231 232 minZ = maxZ = points[0].z; 233 234 235 236 for(int i = 1; i < 8; i++) 237 238 { 239 240 points[i].transform(mat, points[i]); 241 242 243 244 if (points[i].x > maxX) maxX = points[i].x ; 245 246 else if (points[i].x < minX) minX = points[i].x ; 247 248 249 250 if (points[i].y > maxY) maxY = points[i].y; 251 252 else if (points[i].y < minY) minY = points[i].y; 253 254 255 256 if (points[i].z > maxZ) maxZ = points[i].z; 257 258 else if (points[i].z < minZ) minZ = points[i].z; 259 260 261 262 } 263 264 265 266 min.set(minX, minY, minZ); 267 268 max.set(maxX, maxY, maxZ); 269 127 min.set(minX, minY, minZ); 128 max.set(maxX, maxY, maxZ); 270 129 } 271 130 131 bool vrBBox::intersect(const vrBBox& box) 132 { 133 if (min.x > box.max.x || max.x < box.min.x) return false; 134 if (min.y > box.max.y || max.y < box.min.y) return false; 135 if (min.z > box.max.z || max.z < box.min.z) return false; 272 136 273 274 bool vrBBox::intersect(const vrBBox& box) 275 276 { 277 278 if (min.x > box.max.x || max.x < box.min.x) return false; 279 280 if (min.y > box.max.y || max.y < box.min.y) return false; 281 282 if (min.z > box.max.z || max.z < box.min.z) return false; 283 284 285 286 return true; 287 137 return true; 288 138 } 289 139 140 bool vrBBox::intersect(const vrVector3f& point) 141 { 142 if ((point.x < min.x) || (point.x > max.x)) return false; 143 if ((point.y < min.y) || (point.y > max.y)) return false; 144 if ((point.z < min.z) || (point.z > max.z)) return false; 290 145 291 292 bool vrBBox::intersect(const vrVector3f& point) 293 294 { 295 296 if ((point.x < min.x) || (point.x > max.x)) return false; 297 298 if ((point.y < min.y) || (point.y > max.y)) return false; 299 300 if ((point.z < min.z) || (point.z > max.z)) return false; 301 302 303 304 return true; 305 146 return true; 306 147 } 307 -
trunk/packages/vizservers/nanovis/vrmath/vrBPlane.cpp
r2798 r2840 2 2 #include <vrmath/vrBPlane.h> 3 3 4 void vrBPlane::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) { 4 void vrBPlane::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) 5 { 6 normal.cross(p2 - p1, p3 - p1); 7 normal.normalize(); 5 8 6 normal.cross(p2 - p1, p3 - p1); 7 normal.normalize(); 8 9 point = p1; 10 9 point = p1; 11 10 } 12 11 13 void vrBPlane::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) { 14 normal = norm; 15 point = pos; 12 void vrBPlane::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) 13 { 14 normal = norm; 15 point = pos; 16 16 } 17 17 18 18 bool vrBPlane::intersect(const vrLineSegment &seg, float &d) const 19 19 { 20 21 20 // STEVE 21 // 2005-09-07 22 22 23 23 float tu, td; 24 24 25 26 25 tu = normal.x * (point.x - seg.pos.x) + normal.y * (point.y - seg.pos.y) 26 + normal.z * (point.z - seg.pos.z); 27 27 28 28 td = normal.x * seg.dir.x + normal.y * seg.dir.y + normal.z * seg.dir.z; 29 29 30 30 if ( td == 0.0f ) return false; 31 31 32 32 d = tu / td; 33 33 34 34 return true; 35 35 } 36 36 37 37 float vrBPlane::distance(const vrVector3f& pos) const 38 38 { 39 vrVector3f plane_point = crossPoint( pos ); 39 40 40 vrVector3f plane_point = crossPoint( pos ); 41 42 return pos.distance( plane_point ); 41 return pos.distance( plane_point ); 43 42 } 44 43 45 vrVector3f vrBPlane::crossPoint(const vrVector3f& pos) const { 44 vrVector3f vrBPlane::crossPoint(const vrVector3f& pos) const 45 { 46 vrLineSegment seg; 46 47 47 vrLineSegment seg; 48 seg.pos = pos; 49 seg.dir = normal; 48 50 49 seg.pos = pos;50 seg.dir = normal;51 float t = 0; 52 intersect(seg, t); 51 53 52 float t = 0; 53 intersect(seg, t); 54 55 return seg.getPoint(t); 54 return seg.getPoint(t); 56 55 } -
trunk/packages/vizservers/nanovis/vrmath/vrColor4f.cpp
r2798 r2840 2 2 #include <vrmath/vrColor4f.h> 3 3 4 vrColor4f::vrColor4f() 5 :r(0.0f), g(0.0f), b(0.0f), a(1.0f)4 vrColor4f::vrColor4f() : 5 r(0.0f), g(0.0f), b(0.0f), a(1.0f) 6 6 { 7 7 } 8 8 9 vrColor4f::vrColor4f(float r1, float g1, float b1, float a1) 10 :r(r1), g(g1), b(b1), a(a1)9 vrColor4f::vrColor4f(float r1, float g1, float b1, float a1) : 10 r(r1), g(g1), b(b1), a(a1) 11 11 { 12 12 } -
trunk/packages/vizservers/nanovis/vrmath/vrLineSegment.cpp
r2798 r2840 3 3 4 4 5 vrLineSegment::vrLineSegment() 6 :pos(0.0f, 0.0f, 0.0f), dir(0.0f, 0.0f, -1.0f), length(0.0f)5 vrLineSegment::vrLineSegment(): 6 pos(0.0f, 0.0f, 0.0f), dir(0.0f, 0.0f, -1.0f), length(0.0f) 7 7 { 8 9 8 } 10 9 11 10 void vrLineSegment::transform(const vrMatrix4x4f &mat, const vrLineSegment &seg) 12 11 { 13 12 pos.transform(mat, seg.pos); 14 13 15 16 17 14 dir.x *= length; 15 dir.y *= length; 16 dir.z *= length; 18 17 19 20 21 18 dir.transformVec(mat, seg.dir); 19 length = dir.length(); 20 dir.normalize(); 22 21 } -
trunk/packages/vizservers/nanovis/vrmath/vrLinmath.cpp
r2798 r2840 8 8 vrVector3f vrCalcuNormal(const vrVector3f& v1, const vrVector3f& v2, const vrVector3f& v3) 9 9 { 10 10 vrVector3f temp; 11 11 12 12 float a[3], b[3]; 13 13 14 15 16 17 18 19 14 a[0] = v2.x - v1.x; 15 a[1] = v2.y - v1.y; 16 a[2] = v2.z - v1.z; 17 b[0] = v3.x - v1.x; 18 b[1] = v3.y - v1.y; 19 b[2] = v3.z - v1.z; 20 20 21 22 23 21 temp.x = a[1] * b[2] - a[2] * b[1]; 22 temp.y = a[2] * b[0] - a[0] * b[2]; 23 temp.z = a[0] * b[1] - a[1] * b[0]; 24 24 25 25 float leng = (float)sqrt(temp.x * temp.x + temp.y * temp.y + temp.z * temp.z); 26 26 27 if (leng != 0.0f) { 27 if (leng != 0.0f) { 28 temp.x /= leng; 29 temp.y /= leng; 30 temp.z /= leng; 31 } 32 else temp.set(-1.0f, 0.0f, 0.0f); 28 33 29 temp.x /= leng; 30 temp.y /= leng; 31 temp.z /= leng; 32 } 33 else temp.set(-1.0f, 0.0f, 0.0f); 34 35 return temp; 34 return temp; 36 35 } 37 38 36 39 37 static void __gluMakeIdentityd(float m[16]) … … 45 43 } 46 44 47 48 45 static int __gluInvertMatrixd(const float m[16], float invOut[16]) 49 46 { … … 52 49 53 50 inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15] 54 51 + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10]; 55 52 inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15] 56 53 - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10]; 57 54 inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15] 58 55 + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9]; 59 56 inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14] 60 57 - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9]; 61 58 inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15] 62 59 - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10]; 63 60 inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15] 64 61 + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10]; 65 62 inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15] 66 63 - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9]; 67 64 inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14] 68 65 + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9]; 69 66 inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15] 70 67 + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6]; 71 68 inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15] 72 69 - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6]; 73 70 inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15] 74 71 + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5]; 75 72 inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14] 76 73 - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5]; 77 74 inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11] 78 75 - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6]; 79 76 inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11] 80 77 + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6]; 81 78 inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11] 82 79 - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5]; 83 80 inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10] 84 81 + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5]; 85 82 86 83 det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12]; 87 84 88 85 if (det == 0) 89 86 return 0; 90 87 … … 97 94 } 98 95 99 100 96 static void __gluMultMatrixVecd(const float matrix[16], const float in[4], 101 float out[4])97 float out[4]) 102 98 { 103 99 int i; … … 113 109 114 110 static void __gluMultMatricesd(const float a[16], const float b[16], 115 111 float r[16]) 116 112 { 117 113 int i, j; … … 191 187 memcpy(matrix, &m[0][0], sizeof(float) * 16); 192 188 } 193 -
trunk/packages/vizservers/nanovis/vrmath/vrMatrix4x4f.cpp
r2798 r2840 6 6 void vrMatrix4x4f::makeIdentity() 7 7 { 8 8 _data[1] = _data[2] = _data[3] = _data[4] = 9 9 _data[6] = _data[7] = _data[8] = _data[9] = 10 10 _data[11] = _data[12] = _data[13] = _data[14] = 0.0f; 11 11 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 12 12 } 13 13 14 14 void vrMatrix4x4f::makeTranslation(const vrVector3f& translation) 15 15 { 16 16 _data[1] = _data[2] = _data[3] = _data[4] = 17 17 _data[6] = _data[7] = _data[8] = _data[9] = 18 18 _data[11] = 0.0f; 19 20 21 22 19 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 20 _data[12] = translation.x; 21 _data[13] = translation.y; 22 _data[14] = translation.z; 23 23 } 24 24 25 25 void vrMatrix4x4f::makeTranslation(float x, float y, float z) 26 26 { 27 27 _data[1] = _data[2] = _data[3] = _data[4] = 28 28 _data[6] = _data[7] = _data[8] = _data[9] = 29 29 _data[11] = 0.0f; 30 31 32 33 30 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 31 _data[12] = x; 32 _data[13] = y; 33 _data[14] = z; 34 34 } 35 35 36 36 void vrMatrix4x4f::makeRotation(const vrRotation& rotation) 37 37 { 38 if (rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f) 39 { 40 makeIdentity(); 41 return; 42 } 43 44 float xAxis = rotation.getX(), yAxis = rotation.getY(), zAxis = rotation.getZ(); 45 float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 46 float cosine = cos(rotation.getAngle()); 38 if (rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f) { 39 makeIdentity(); 40 return; 41 } 42 43 float xAxis = rotation.getX(), yAxis = rotation.getY(), zAxis = rotation.getZ(); 44 float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 45 float cosine = cos(rotation.getAngle()); 47 46 float sine = sin(rotation.getAngle()); 48 47 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 48 xAxis *= invLen; 49 yAxis *= invLen; 50 zAxis *= invLen; 51 52 float oneMinusCosine = 1.0f - cosine; 53 54 _data[3] = _data[7] = _data[11] = _data[12] = _data[13] = _data[14] = 0.0f; 55 _data[15] = 1.0f; 56 57 _data[0] = xAxis * xAxis * oneMinusCosine + cosine; 58 _data[1] = yAxis * xAxis * oneMinusCosine + zAxis * sine; 59 _data[2] = xAxis * zAxis * oneMinusCosine - yAxis * sine; 60 61 _data[4] = xAxis * yAxis * oneMinusCosine - zAxis * sine; 62 _data[5] = yAxis * yAxis * oneMinusCosine + cosine; 63 _data[6] = yAxis * zAxis * oneMinusCosine + xAxis * sine; 64 65 _data[8] = xAxis * zAxis * oneMinusCosine + yAxis * sine; 66 _data[9] = yAxis * zAxis * oneMinusCosine - xAxis * sine; 67 _data[10] = zAxis * zAxis * oneMinusCosine + cosine; 69 68 } 70 69 71 70 void vrMatrix4x4f::makeRotation(float xAxis, float yAxis, float zAxis, float angle) 72 71 { 73 if (xAxis == 0.0f && yAxis == 0.0f && zAxis == 0.0f) 74 { 75 makeIdentity(); 76 return; 77 } 78 79 float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 80 float cosine = cos(angle); 72 if (xAxis == 0.0f && yAxis == 0.0f && zAxis == 0.0f) { 73 makeIdentity(); 74 return; 75 } 76 77 float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 78 float cosine = cos(angle); 81 79 float sine = sin(angle); 82 80 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 81 xAxis *= invLen; 82 yAxis *= invLen; 83 zAxis *= invLen; 84 85 float oneMinusCosine = 1.0f - cosine; 86 87 _data[3] = _data[7] = _data[11] = _data[12] = _data[13] = _data[14] = 0.0f; 88 _data[15] = 1.0f; 89 90 _data[0] = xAxis * xAxis * oneMinusCosine + cosine; 91 _data[1] = yAxis * xAxis * oneMinusCosine + zAxis * sine; 92 _data[2] = xAxis * zAxis * oneMinusCosine - yAxis * sine; 93 94 _data[4] = xAxis * yAxis * oneMinusCosine - zAxis * sine; 95 _data[5] = yAxis * yAxis * oneMinusCosine + cosine; 96 _data[6] = yAxis * zAxis * oneMinusCosine + xAxis * sine; 97 98 _data[8] = xAxis * zAxis * oneMinusCosine + yAxis * sine; 99 _data[9] = yAxis * zAxis * oneMinusCosine - xAxis * sine; 100 _data[10] = zAxis * zAxis * oneMinusCosine + cosine; 103 101 } 104 102 … … 106 104 void vrMatrix4x4f::makeScale(const vrVector3f& scale) 107 105 { 108 106 _data[1] = _data[2] = _data[3] = _data[4] = 109 107 _data[6] = _data[7] = _data[8] = _data[9] = 110 108 _data[11] = 0.0f; 111 109 112 113 114 115 116 117 110 _data[0] = scale.x; 111 _data[5] = scale.y; 112 _data[10] = scale.z; 113 114 _data[15] = 1.0f; 115 _data[12] = _data[13] = _data[14] = 0.0f; 118 116 } 119 117 120 118 void vrMatrix4x4f::multiply(const vrMatrix4x4f& m1) 121 119 { 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 120 float mat[16]; 121 float* mat1 = (float*) m1._data; 122 123 // 1 row 124 mat[0] = float(_data[0] * mat1[0] + _data[4] * mat1[1] + 125 _data[8] * mat1[2] + _data[12] * mat1[3]); 126 mat[4] = float(_data[0] * mat1[4] + _data[4] * mat1[5] + 127 _data[8] * mat1[6] + _data[12] * mat1[7]); 128 mat[8] = float(_data[0] * mat1[8] + _data[4] * mat1[9] + 129 _data[8] * mat1[10] + _data[12] * mat1[11]); 130 mat[12] = float(_data[0] * mat1[12] + _data[4] * mat1[13] + 131 _data[8] * mat1[14] + _data[12] * mat1[15]); 132 133 // 2 row 134 mat[1] = float(_data[1] * mat1[0] + _data[5] * mat1[1] + 135 _data[9] * mat1[2] + _data[13] * mat1[3]); 136 mat[5] = float(_data[1] * mat1[4] + _data[5] * mat1[5] + 137 _data[9] * mat1[6] + _data[13] * mat1[7]); 138 mat[9] = float(_data[1] * mat1[8] + _data[5] * mat1[9] + 139 _data[9] * mat1[10] + _data[13] * mat1[11]); 140 mat[13] = float(_data[1] * mat1[12] + _data[5] * mat1[13] + 141 _data[9] * mat1[14] + _data[13] * mat1[15]); 142 143 // 3 row 144 mat[2] = float(_data[2] * mat1[0] + _data[6] * mat1[1] + 145 _data[10] * mat1[2] + _data[14] * mat1[3]); 146 147 mat[6] = float(_data[2] * mat1[4] + _data[6] * mat1[5] + 148 _data[10] * mat1[6] + _data[14] * mat1[7]); 149 mat[10] = float(_data[2] * mat1[8] + _data[6] * mat1[9] + 150 _data[10] * mat1[10] + _data[14] * mat1[11]); 151 mat[14] = float(_data[2] * mat1[12] + _data[6] * mat1[13] + 152 _data[10] * mat1[14] + _data[14] * mat1[15]); 153 154 // 4 row 155 mat[3] = float(_data[3] * mat1[0] + _data[7] * mat1[1] + 156 _data[11] * mat1[2] + _data[15] * mat1[3]); 157 mat[7] = float(_data[3] * mat1[4] + _data[7] * mat1[5] + 158 _data[11] * mat1[6] + _data[15] * mat1[7]); 159 mat[11] = float(_data[3] * mat1[8] + _data[7] * mat1[9] + 160 _data[11] * mat1[10] + _data[15] * mat1[11]); 161 mat[15] = float(_data[3] * mat1[12] + _data[7] * mat1[13] + 162 _data[11] * mat1[14] + _data[15] * mat1[15]); 163 164 // set matrix 165 set(mat); 168 166 } 169 167 170 168 void vrMatrix4x4f::multiply(const vrMatrix4x4f& m1, const vrMatrix4x4f& m2) 171 169 { 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 170 float mat[16]; 171 float* mat1 = (float*) m1._data; 172 float* mat2 = (float*) m2._data; 173 174 // 1 row 175 mat[0] = float(mat1[0] * mat2[0] + mat1[4] * mat2[1] + 176 mat1[8] * mat2[2] + mat1[12] * mat2[3]); 177 mat[4] = float(mat1[0] * mat2[4] + mat1[4] * mat2[5] + 178 mat1[8] * mat2[6] + mat1[12] * mat2[7]); 179 mat[8] = float(mat1[0] * mat2[8] + mat1[4] * mat2[9] + 180 mat1[8] * mat2[10] + mat1[12] * mat2[11]); 181 mat[12] = float(mat1[0] * mat2[12] + mat1[4] * mat2[13] + 182 mat1[8] * mat2[14] + mat1[12] * mat2[15]); 183 184 // 2 row 185 mat[1] = float(mat1[1] * mat2[0] + mat1[5] * mat2[1] + 186 mat1[9] * mat2[2] + mat1[13] * mat2[3]); 187 mat[5] = float(mat1[1] * mat2[4] + mat1[5] * mat2[5] + 188 mat1[9] * mat2[6] + mat1[13] * mat2[7]); 189 mat[9] = float(mat1[1] * mat2[8] + mat1[5] * mat2[9] + 190 mat1[9] * mat2[10] + mat1[13] * mat2[11]); 191 mat[13] = float(mat1[1] * mat2[12] + mat1[5] * mat2[13] + 192 mat1[9] * mat2[14] + mat1[13] * mat2[15]); 193 194 // 3 row 195 mat[2] = float(mat1[2] * mat2[0] + mat1[6] * mat2[1] + 196 mat1[10] * mat2[2] + mat1[14] * mat2[3]); 197 mat[6] = float(mat1[2] * mat2[4] + mat1[6] * mat2[5] + 198 mat1[10] * mat2[6] + mat1[14] * mat2[7]); 199 mat[10] = float(mat1[2] * mat2[8] + mat1[6] * mat2[9] + 200 mat1[10] * mat2[10] + mat1[14] * mat2[11]); 201 mat[14] = float(mat1[2] * mat2[12] + mat1[6] * mat2[13] + 202 mat1[10] * mat2[14] + mat1[14] * mat2[15]); 203 204 // 4 row 205 mat[3] = float(mat1[3] * mat2[0] + mat1[7] * mat2[1] + 206 mat1[11] * mat2[2] + mat1[15] * mat2[3]); 207 mat[7] = float(mat1[3] * mat2[4] + mat1[7] * mat2[5] + 208 mat1[11] * mat2[6] + mat1[15] * mat2[7]); 209 mat[11] = float(mat1[3] * mat2[8] + mat1[7] * mat2[9] + 210 mat1[11] * mat2[10] + mat1[15] * mat2[11]); 211 mat[15] = float(mat1[3] * mat2[12] + mat1[7] * mat2[13] + 212 mat1[11] * mat2[14] + mat1[15] * mat2[15]); 213 214 // set matrix 215 set(mat); 218 216 } 219 217 220 218 void vrMatrix4x4f::multiplyFast(const vrMatrix4x4f& m1, const vrMatrix4x4f& m2) 221 219 { 222 223 float* mat1 = (float*) m1._data; 224 225 float* mat2 = (float*) m2._data; 226 227 228 229 // 1 row 230 231 _data[0] = float(mat1[0] * mat2[0] + mat1[4] * mat2[1] + 232 233 mat1[8] * mat2[2] + mat1[12] * mat2[3]); 234 235 _data[4] = float(mat1[0] * mat2[4] + mat1[4] * mat2[5] + 236 237 mat1[8] * mat2[6] + mat1[12] * mat2[7]); 238 239 _data[8] = float(mat1[0] * mat2[8] + mat1[4] * mat2[9] + 240 241 mat1[8] * mat2[10] + mat1[12] * mat2[11]); 242 243 _data[12] = float(mat1[0] * mat2[12] + mat1[4] * mat2[13] + 244 245 mat1[8] * mat2[14] + mat1[12] * mat2[15]); 246 247 248 249 // 2 row 250 251 _data[1] = float(mat1[1] * mat2[0] + mat1[5] * mat2[1] + 252 253 mat1[9] * mat2[2] + mat1[13] * mat2[3]); 254 255 _data[5] = float(mat1[1] * mat2[4] + mat1[5] * mat2[5] + 256 257 mat1[9] * mat2[6] + mat1[13] * mat2[7]); 258 259 _data[9] = float(mat1[1] * mat2[8] + mat1[5] * mat2[9] + 260 261 mat1[9] * mat2[10] + mat1[13] * mat2[11]); 262 263 _data[13] = float(mat1[1] * mat2[12] + mat1[5] * mat2[13] + 264 265 mat1[9] * mat2[14] + mat1[13] * mat2[15]); 266 267 268 269 // 3 row 270 271 _data[2] = float(mat1[2] * mat2[0] + mat1[6] * mat2[1] + 272 273 mat1[10] * mat2[2] + mat1[14] * mat2[3]); 274 275 _data[6] = float(mat1[2] * mat2[4] + mat1[6] * mat2[5] + 276 277 mat1[10] * mat2[6] + mat1[14] * mat2[7]); 278 279 _data[10] = float(mat1[2] * mat2[8] + mat1[6] * mat2[9] + 280 281 mat1[10] * mat2[10] + mat1[14] * mat2[11]); 282 283 _data[14] = float(mat1[2] * mat2[12] + mat1[6] * mat2[13] + 284 285 mat1[10] * mat2[14] + mat1[14] * mat2[15]); 286 287 288 289 // 4 row 290 291 _data[3] = float(mat1[3] * mat2[0] + mat1[7] * mat2[1] + 292 293 mat1[11] * mat2[2] + mat1[15] * mat2[3]); 294 295 _data[7] = float(mat1[3] * mat2[4] + mat1[7] * mat2[5] + 296 297 mat1[11] * mat2[6] + mat1[15] * mat2[7]); 298 299 _data[11] = float(mat1[3] * mat2[8] + mat1[7] * mat2[9] + 300 301 mat1[11] * mat2[10] + mat1[15] * mat2[11]); 302 303 _data[15] = float(mat1[3] * mat2[12] + mat1[7] * mat2[13] + 304 305 mat1[11] * mat2[14] + mat1[15] * mat2[15]); 306 307 } 308 309 220 float* mat1 = (float*) m1._data; 221 float* mat2 = (float*) m2._data; 222 223 // 1 row 224 _data[0] = float(mat1[0] * mat2[0] + mat1[4] * mat2[1] + 225 mat1[8] * mat2[2] + mat1[12] * mat2[3]); 226 _data[4] = float(mat1[0] * mat2[4] + mat1[4] * mat2[5] + 227 mat1[8] * mat2[6] + mat1[12] * mat2[7]); 228 _data[8] = float(mat1[0] * mat2[8] + mat1[4] * mat2[9] + 229 mat1[8] * mat2[10] + mat1[12] * mat2[11]); 230 _data[12] = float(mat1[0] * mat2[12] + mat1[4] * mat2[13] + 231 mat1[8] * mat2[14] + mat1[12] * mat2[15]); 232 233 // 2 row 234 _data[1] = float(mat1[1] * mat2[0] + mat1[5] * mat2[1] + 235 mat1[9] * mat2[2] + mat1[13] * mat2[3]); 236 _data[5] = float(mat1[1] * mat2[4] + mat1[5] * mat2[5] + 237 mat1[9] * mat2[6] + mat1[13] * mat2[7]); 238 _data[9] = float(mat1[1] * mat2[8] + mat1[5] * mat2[9] + 239 mat1[9] * mat2[10] + mat1[13] * mat2[11]); 240 _data[13] = float(mat1[1] * mat2[12] + mat1[5] * mat2[13] + 241 mat1[9] * mat2[14] + mat1[13] * mat2[15]); 242 243 // 3 row 244 _data[2] = float(mat1[2] * mat2[0] + mat1[6] * mat2[1] + 245 mat1[10] * mat2[2] + mat1[14] * mat2[3]); 246 _data[6] = float(mat1[2] * mat2[4] + mat1[6] * mat2[5] + 247 mat1[10] * mat2[6] + mat1[14] * mat2[7]); 248 _data[10] = float(mat1[2] * mat2[8] + mat1[6] * mat2[9] + 249 mat1[10] * mat2[10] + mat1[14] * mat2[11]); 250 _data[14] = float(mat1[2] * mat2[12] + mat1[6] * mat2[13] + 251 mat1[10] * mat2[14] + mat1[14] * mat2[15]); 252 253 // 4 row 254 _data[3] = float(mat1[3] * mat2[0] + mat1[7] * mat2[1] + 255 mat1[11] * mat2[2] + mat1[15] * mat2[3]); 256 _data[7] = float(mat1[3] * mat2[4] + mat1[7] * mat2[5] + 257 mat1[11] * mat2[6] + mat1[15] * mat2[7]); 258 _data[11] = float(mat1[3] * mat2[8] + mat1[7] * mat2[9] + 259 mat1[11] * mat2[10] + mat1[15] * mat2[11]); 260 _data[15] = float(mat1[3] * mat2[12] + mat1[7] * mat2[13] + 261 mat1[11] * mat2[14] + mat1[15] * mat2[15]); 262 } 310 263 311 264 void vrMatrix4x4f::getRotation(vrRotation& rotation) 312 265 { 313 float c = (_data[0] + _data[5] + _data[10] - 1.0f) * 0.5f; 314 315 rotation.setAxis(_data[6] - _data[9], _data[8] - _data[2], _data[1] - _data[4]); 316 317 318 319 float len = sqrt(rotation.getX() * rotation.getX() + 320 321 rotation.getY() * rotation.getY() + rotation.getZ() * rotation.getZ()); 322 323 float s = 0.5f * len; 324 325 rotation.setAngle((float)atan2(s, c)); 326 327 328 329 if ( rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f ) { 330 331 rotation.set(0.0f, 1.0f, 0.0f, 0.0f); 332 333 } 334 335 else { 336 len = 1.0f / len; 337 338 rotation.setAxis(rotation.getX() * len, rotation.getY() * len, rotation.getZ() * len); 339 } 340 } 341 342 343 266 float c = (_data[0] + _data[5] + _data[10] - 1.0f) * 0.5f; 267 268 rotation.setAxis(_data[6] - _data[9], _data[8] - _data[2], _data[1] - _data[4]); 269 270 float len = sqrt(rotation.getX() * rotation.getX() + 271 rotation.getY() * rotation.getY() + rotation.getZ() * rotation.getZ()); 272 273 float s = 0.5f * len; 274 275 rotation.setAngle((float)atan2(s, c)); 276 277 if ( rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f ) { 278 rotation.set(0.0f, 1.0f, 0.0f, 0.0f); 279 } else { 280 len = 1.0f / len; 281 rotation.setAxis(rotation.getX() * len, rotation.getY() * len, rotation.getZ() * len); 282 } 283 } 344 284 345 285 void vrMatrix4x4f::invert() 346 286 347 287 { 348 349 float det = 350 351 _data[12] * _data[9] * _data[6] * _data[3]- 352 353 _data[8] * _data[13] * _data[6] * _data[3]- 354 355 _data[12] * _data[5] * _data[10] * _data[3]+ 356 357 _data[4] * _data[13] * _data[10] * _data[3]+ 358 359 _data[8] * _data[5] * _data[14] * _data[3]- 360 361 _data[4] * _data[9] * _data[14] * _data[3]- 362 363 _data[12] * _data[9] * _data[2] * _data[7]+ 364 365 _data[8] * _data[13] * _data[2] * _data[7]+ 366 367 _data[12] * _data[1] * _data[10] * _data[7]- 368 369 _data[0] * _data[13] * _data[10] * _data[7]- 370 371 _data[8] * _data[1] * _data[14] * _data[7]+ 372 373 _data[0] * _data[9] * _data[14] * _data[7]+ 374 375 _data[12] * _data[5] * _data[2] * _data[11]- 376 377 _data[4] * _data[13] * _data[2] * _data[11]- 378 379 _data[12] * _data[1] * _data[6] * _data[11]+ 380 381 _data[0] * _data[13] * _data[6] * _data[11]+ 382 383 _data[4] * _data[1] * _data[14] * _data[11]- 384 385 _data[0] * _data[5] * _data[14] * _data[11]- 386 387 _data[8] * _data[5] * _data[2] * _data[15]+ 388 389 _data[4] * _data[9] * _data[2] * _data[15]+ 390 391 _data[8] * _data[1] * _data[6] * _data[15]- 392 393 _data[0] * _data[9] * _data[6] * _data[15]- 394 395 _data[4] * _data[1] * _data[10] * _data[15]+ 396 397 _data[0] * _data[5] * _data[10] * _data[15]; 398 399 400 401 if ( det == 0.0f ) return; 402 403 det = 1 / det; 404 405 406 407 float mat[16]; 408 409 mat[0] = (_data[9]*_data[14]*_data[7] - 410 411 _data[13]*_data[10]*_data[7] + 412 413 _data[13]*_data[6]*_data[11] - 414 415 _data[5]*_data[14]*_data[11] - 416 417 _data[9]*_data[6]*_data[15] + 418 419 _data[5]*_data[10]*_data[15]) * det; 420 421 mat[4] = (_data[12]*_data[10]*_data[7] - 422 423 _data[8]*_data[14]*_data[7] - 424 425 _data[12]*_data[6]*_data[11] + 426 427 _data[4]*_data[14]*_data[11] + 428 429 _data[8]*_data[6]*_data[15] - 430 431 _data[4]*_data[10]*_data[15]) * det; 432 433 mat[8] = (_data[8]*_data[13]*_data[7] - 434 435 _data[12]*_data[9]*_data[7] + 436 437 _data[12]*_data[5]*_data[11] - 438 439 _data[4]*_data[13]*_data[11] - 440 441 _data[8]*_data[5]*_data[15] + 442 443 _data[4]*_data[9]*_data[15]) * det; 444 445 mat[12] = (_data[12]*_data[9]*_data[6] - 446 447 _data[8]*_data[13]*_data[6] - 448 449 _data[12]*_data[5]*_data[10] + 450 451 _data[4]*_data[13]*_data[10] + 452 453 _data[8]*_data[5]*_data[14] - 454 455 _data[4]*_data[9]*_data[14]) * det; 456 457 mat[1] = (_data[13]*_data[10]*_data[3] - 458 459 _data[9]*_data[14]*_data[3] - 460 461 _data[13]*_data[2]*_data[11] + 462 463 _data[1]*_data[14]*_data[11] + 464 465 _data[9]*_data[2]*_data[15] - 466 467 _data[1]*_data[10]*_data[15]) * det; 468 469 mat[5] = (_data[8]*_data[14]*_data[3] - 470 471 _data[12]*_data[10]*_data[3] + 472 473 _data[12]*_data[2]*_data[11] - 474 475 _data[0]*_data[14]*_data[11] - 476 477 _data[8]*_data[2]*_data[15] + 478 479 _data[0]*_data[10]*_data[15]) * det; 480 481 mat[9] = (_data[12]*_data[9]*_data[3] - 482 483 _data[8]*_data[13]*_data[3] - 484 485 _data[12]*_data[1]*_data[11] + 486 487 _data[0]*_data[13]*_data[11] + 488 489 _data[8]*_data[1]*_data[15] - 490 491 _data[0]*_data[9]*_data[15]) * det; 492 493 mat[13] = (_data[8]*_data[13]*_data[2] - 494 495 _data[12]*_data[9]*_data[2] + 496 497 _data[12]*_data[1]*_data[10] - 498 499 _data[0]*_data[13]*_data[10] - 500 501 _data[8]*_data[1]*_data[14] + 502 503 _data[0]*_data[9]*_data[14]) * det; 504 505 mat[2] = (_data[5]*_data[14]*_data[3] - 506 507 _data[13]*_data[6]*_data[3] + 508 509 _data[13]*_data[2]*_data[7] - 510 511 _data[1]*_data[14]*_data[7] - 512 513 _data[5]*_data[2]*_data[15] + 514 515 _data[1]*_data[6]*_data[15]) * det; 516 517 mat[6] = (_data[12]*_data[6]*_data[3] - 518 519 _data[4]*_data[14]*_data[3] - 520 521 _data[12]*_data[2]*_data[7] + 522 523 _data[0]*_data[14]*_data[7] + 524 525 _data[4]*_data[2]*_data[15] - 526 527 _data[0]*_data[6]*_data[15]) * det; 528 529 mat[10] = (_data[4]*_data[13]*_data[3] - 530 531 _data[12]*_data[5]*_data[3] + 532 533 _data[12]*_data[1]*_data[7] - 534 535 _data[0]*_data[13]*_data[7] - 536 537 _data[4]*_data[1]*_data[15] + 538 539 _data[0]*_data[5]*_data[15]) * det; 540 541 mat[14] = (_data[12]*_data[5]*_data[2] - 542 543 _data[4]*_data[13]*_data[2] - 544 545 _data[12]*_data[1]*_data[6] + 546 547 _data[0]*_data[13]*_data[6] + 548 549 _data[4]*_data[1]*_data[14] - 550 551 _data[0]*_data[5]*_data[14]) * det; 552 553 mat[3] = (_data[9]*_data[6]*_data[3] - 554 555 _data[5]*_data[10]*_data[3] - 556 557 _data[9]*_data[2]*_data[7] + 558 559 _data[1]*_data[10]*_data[7] + 560 561 _data[5]*_data[2]*_data[11] - 562 563 _data[1]*_data[6]*_data[11]) * det; 564 565 mat[7] = (_data[4]*_data[10]*_data[3] - 566 567 _data[8]*_data[6]*_data[3] + 568 569 _data[8]*_data[2]*_data[7] - 570 571 _data[0]*_data[10]*_data[7] - 572 573 _data[4]*_data[2]*_data[11] + 574 575 _data[0]*_data[6]*_data[11]) * det; 576 577 mat[11] = (_data[8]*_data[5]*_data[3] - 578 579 _data[4]*_data[9]*_data[3] - 580 581 _data[8]*_data[1]*_data[7] + 582 583 _data[0]*_data[9]*_data[7] + 584 585 _data[4]*_data[1]*_data[11] - 586 587 _data[0]*_data[5]*_data[11]) * det; 588 589 mat[15] = (_data[4]*_data[9]*_data[2] - 590 591 _data[8]*_data[5]*_data[2] + 592 593 _data[8]*_data[1]*_data[6] - 594 595 _data[0]*_data[9]*_data[6] - 596 597 _data[4]*_data[1]*_data[10] + 598 599 _data[0]*_data[5]*_data[10]) * det; 600 601 602 603 set(mat); 604 288 float det = 289 _data[12] * _data[9] * _data[6] * _data[3]- 290 _data[8] * _data[13] * _data[6] * _data[3]- 291 _data[12] * _data[5] * _data[10] * _data[3]+ 292 _data[4] * _data[13] * _data[10] * _data[3]+ 293 _data[8] * _data[5] * _data[14] * _data[3]- 294 _data[4] * _data[9] * _data[14] * _data[3]- 295 _data[12] * _data[9] * _data[2] * _data[7]+ 296 _data[8] * _data[13] * _data[2] * _data[7]+ 297 _data[12] * _data[1] * _data[10] * _data[7]- 298 _data[0] * _data[13] * _data[10] * _data[7]- 299 _data[8] * _data[1] * _data[14] * _data[7]+ 300 _data[0] * _data[9] * _data[14] * _data[7]+ 301 _data[12] * _data[5] * _data[2] * _data[11]- 302 _data[4] * _data[13] * _data[2] * _data[11]- 303 _data[12] * _data[1] * _data[6] * _data[11]+ 304 _data[0] * _data[13] * _data[6] * _data[11]+ 305 _data[4] * _data[1] * _data[14] * _data[11]- 306 _data[0] * _data[5] * _data[14] * _data[11]- 307 _data[8] * _data[5] * _data[2] * _data[15]+ 308 _data[4] * _data[9] * _data[2] * _data[15]+ 309 _data[8] * _data[1] * _data[6] * _data[15]- 310 _data[0] * _data[9] * _data[6] * _data[15]- 311 _data[4] * _data[1] * _data[10] * _data[15]+ 312 _data[0] * _data[5] * _data[10] * _data[15]; 313 314 if ( det == 0.0f ) return; 315 det = 1 / det; 316 317 float mat[16]; 318 319 mat[0] = (_data[9]*_data[14]*_data[7] - 320 _data[13]*_data[10]*_data[7] + 321 _data[13]*_data[6]*_data[11] - 322 _data[5]*_data[14]*_data[11] - 323 _data[9]*_data[6]*_data[15] + 324 _data[5]*_data[10]*_data[15]) * det; 325 326 mat[4] = (_data[12]*_data[10]*_data[7] - 327 _data[8]*_data[14]*_data[7] - 328 _data[12]*_data[6]*_data[11] + 329 _data[4]*_data[14]*_data[11] + 330 _data[8]*_data[6]*_data[15] - 331 _data[4]*_data[10]*_data[15]) * det; 332 333 mat[8] = (_data[8]*_data[13]*_data[7] - 334 _data[12]*_data[9]*_data[7] + 335 _data[12]*_data[5]*_data[11] - 336 _data[4]*_data[13]*_data[11] - 337 _data[8]*_data[5]*_data[15] + 338 _data[4]*_data[9]*_data[15]) * det; 339 340 mat[12] = (_data[12]*_data[9]*_data[6] - 341 _data[8]*_data[13]*_data[6] - 342 _data[12]*_data[5]*_data[10] + 343 _data[4]*_data[13]*_data[10] + 344 _data[8]*_data[5]*_data[14] - 345 _data[4]*_data[9]*_data[14]) * det; 346 347 mat[1] = (_data[13]*_data[10]*_data[3] - 348 _data[9]*_data[14]*_data[3] - 349 _data[13]*_data[2]*_data[11] + 350 _data[1]*_data[14]*_data[11] + 351 _data[9]*_data[2]*_data[15] - 352 _data[1]*_data[10]*_data[15]) * det; 353 354 mat[5] = (_data[8]*_data[14]*_data[3] - 355 _data[12]*_data[10]*_data[3] + 356 _data[12]*_data[2]*_data[11] - 357 _data[0]*_data[14]*_data[11] - 358 _data[8]*_data[2]*_data[15] + 359 _data[0]*_data[10]*_data[15]) * det; 360 361 mat[9] = (_data[12]*_data[9]*_data[3] - 362 _data[8]*_data[13]*_data[3] - 363 _data[12]*_data[1]*_data[11] + 364 _data[0]*_data[13]*_data[11] + 365 _data[8]*_data[1]*_data[15] - 366 _data[0]*_data[9]*_data[15]) * det; 367 368 mat[13] = (_data[8]*_data[13]*_data[2] - 369 _data[12]*_data[9]*_data[2] + 370 _data[12]*_data[1]*_data[10] - 371 _data[0]*_data[13]*_data[10] - 372 _data[8]*_data[1]*_data[14] + 373 _data[0]*_data[9]*_data[14]) * det; 374 375 mat[2] = (_data[5]*_data[14]*_data[3] - 376 _data[13]*_data[6]*_data[3] + 377 _data[13]*_data[2]*_data[7] - 378 _data[1]*_data[14]*_data[7] - 379 _data[5]*_data[2]*_data[15] + 380 _data[1]*_data[6]*_data[15]) * det; 381 382 mat[6] = (_data[12]*_data[6]*_data[3] - 383 _data[4]*_data[14]*_data[3] - 384 _data[12]*_data[2]*_data[7] + 385 _data[0]*_data[14]*_data[7] + 386 _data[4]*_data[2]*_data[15] - 387 _data[0]*_data[6]*_data[15]) * det; 388 389 mat[10] = (_data[4]*_data[13]*_data[3] - 390 _data[12]*_data[5]*_data[3] + 391 _data[12]*_data[1]*_data[7] - 392 _data[0]*_data[13]*_data[7] - 393 _data[4]*_data[1]*_data[15] + 394 _data[0]*_data[5]*_data[15]) * det; 395 396 mat[14] = (_data[12]*_data[5]*_data[2] - 397 _data[4]*_data[13]*_data[2] - 398 _data[12]*_data[1]*_data[6] + 399 _data[0]*_data[13]*_data[6] + 400 _data[4]*_data[1]*_data[14] - 401 _data[0]*_data[5]*_data[14]) * det; 402 403 mat[3] = (_data[9]*_data[6]*_data[3] - 404 _data[5]*_data[10]*_data[3] - 405 _data[9]*_data[2]*_data[7] + 406 _data[1]*_data[10]*_data[7] + 407 _data[5]*_data[2]*_data[11] - 408 _data[1]*_data[6]*_data[11]) * det; 409 410 mat[7] = (_data[4]*_data[10]*_data[3] - 411 _data[8]*_data[6]*_data[3] + 412 _data[8]*_data[2]*_data[7] - 413 _data[0]*_data[10]*_data[7] - 414 _data[4]*_data[2]*_data[11] + 415 _data[0]*_data[6]*_data[11]) * det; 416 417 mat[11] = (_data[8]*_data[5]*_data[3] - 418 _data[4]*_data[9]*_data[3] - 419 _data[8]*_data[1]*_data[7] + 420 _data[0]*_data[9]*_data[7] + 421 _data[4]*_data[1]*_data[11] - 422 _data[0]*_data[5]*_data[11]) * det; 423 424 mat[15] = (_data[4]*_data[9]*_data[2] - 425 _data[8]*_data[5]*_data[2] + 426 _data[8]*_data[1]*_data[6] - 427 _data[0]*_data[9]*_data[6] - 428 _data[4]*_data[1]*_data[10] + 429 _data[0]*_data[5]*_data[10]) * det; 430 431 set(mat); 605 432 } 606 433 … … 608 435 609 436 void vrMatrix4x4f::invert(const vrMatrix4x4f& mat) 610 611 { 612 613 float* data = (float*) mat._data; 614 615 616 617 float det = 618 619 data[12] * data[9] * data[6] * data[3]- 620 621 data[8] * data[13] * data[6] * data[3]- 622 623 data[12] * data[5] * data[10] * data[3]+ 624 625 data[4] * data[13] * data[10] * data[3]+ 626 627 data[8] * data[5] * data[14] * data[3]- 628 629 data[4] * data[9] * data[14] * data[3]- 630 631 data[12] * data[9] * data[2] * data[7]+ 632 633 data[8] * data[13] * data[2] * data[7]+ 634 635 data[12] * data[1] * data[10] * data[7]- 636 637 data[0] * data[13] * data[10] * data[7]- 638 639 data[8] * data[1] * data[14] * data[7]+ 640 641 data[0] * data[9] * data[14] * data[7]+ 642 643 data[12] * data[5] * data[2] * data[11]- 644 645 data[4] * data[13] * data[2] * data[11]- 646 647 data[12] * data[1] * data[6] * data[11]+ 648 649 data[0] * data[13] * data[6] * data[11]+ 650 651 data[4] * data[1] * data[14] * data[11]- 652 653 data[0] * data[5] * data[14] * data[11]- 654 655 data[8] * data[5] * data[2] * data[15]+ 656 657 data[4] * data[9] * data[2] * data[15]+ 658 659 data[8] * data[1] * data[6] * data[15]- 660 661 data[0] * data[9] * data[6] * data[15]- 662 663 data[4] * data[1] * data[10] * data[15]+ 664 665 data[0] * data[5] * data[10] * data[15]; 666 667 668 669 if ( det == 0.0f ) return; 670 671 det = 1 / det; 672 673 674 675 float dstData[16]; 676 677 dstData[0] = (data[9]*data[14]*data[7] - 678 679 data[13]*data[10]*data[7] + 680 681 data[13]*data[6]*data[11] - 682 683 data[5]*data[14]*data[11] - 684 685 data[9]*data[6]*data[15] + 686 687 data[5]*data[10]*data[15]) * det; 688 689 dstData[4] = (data[12]*data[10]*data[7] - 690 691 data[8]*data[14]*data[7] - 692 693 data[12]*data[6]*data[11] + 694 695 data[4]*data[14]*data[11] + 696 697 data[8]*data[6]*data[15] - 698 699 data[4]*data[10]*data[15]) * det; 700 701 dstData[8] = (data[8]*data[13]*data[7] - 702 703 data[12]*data[9]*data[7] + 704 705 data[12]*data[5]*data[11] - 706 707 data[4]*data[13]*data[11] - 708 709 data[8]*data[5]*data[15] + 710 711 data[4]*data[9]*data[15]) * det; 712 713 dstData[12] = (data[12]*data[9]*data[6] - 714 715 data[8]*data[13]*data[6] - 716 717 data[12]*data[5]*data[10] + 718 719 data[4]*data[13]*data[10] + 720 721 data[8]*data[5]*data[14] - 722 723 data[4]*data[9]*data[14]) * det; 724 725 dstData[1] = (data[13]*data[10]*data[3] - 726 727 data[9]*data[14]*data[3] - 728 729 data[13]*data[2]*data[11] + 730 731 data[1]*data[14]*data[11] + 732 733 data[9]*data[2]*data[15] - 734 735 data[1]*data[10]*data[15]) * det; 736 737 dstData[5] = (data[8]*data[14]*data[3] - 738 739 data[12]*data[10]*data[3] + 740 741 data[12]*data[2]*data[11] - 742 743 data[0]*data[14]*data[11] - 744 745 data[8]*data[2]*data[15] + 746 747 data[0]*data[10]*data[15]) * det; 748 749 dstData[9] = (data[12]*data[9]*data[3] - 750 751 data[8]*data[13]*data[3] - 752 753 data[12]*data[1]*data[11] + 754 755 data[0]*data[13]*data[11] + 756 757 data[8]*data[1]*data[15] - 758 759 data[0]*data[9]*data[15]) * det; 760 761 dstData[13] = (data[8]*data[13]*data[2] - 762 763 data[12]*data[9]*data[2] + 764 765 data[12]*data[1]*data[10] - 766 767 data[0]*data[13]*data[10] - 768 769 data[8]*data[1]*data[14] + 770 771 data[0]*data[9]*data[14]) * det; 772 773 dstData[2] = (data[5]*data[14]*data[3] - 774 775 data[13]*data[6]*data[3] + 776 777 data[13]*data[2]*data[7] - 778 779 data[1]*data[14]*data[7] - 780 781 data[5]*data[2]*data[15] + 782 783 data[1]*data[6]*data[15]) * det; 784 785 dstData[6] = (data[12]*data[6]*data[3] - 786 787 data[4]*data[14]*data[3] - 788 789 data[12]*data[2]*data[7] + 790 791 data[0]*data[14]*data[7] + 792 793 data[4]*data[2]*data[15] - 794 795 data[0]*data[6]*data[15]) * det; 796 797 dstData[10] = (data[4]*data[13]*data[3] - 798 799 data[12]*data[5]*data[3] + 800 801 data[12]*data[1]*data[7] - 802 803 data[0]*data[13]*data[7] - 804 805 data[4]*data[1]*data[15] + 806 807 data[0]*data[5]*data[15]) * det; 808 809 dstData[14] = (data[12]*data[5]*data[2] - 810 811 data[4]*data[13]*data[2] - 812 813 data[12]*data[1]*data[6] + 814 815 data[0]*data[13]*data[6] + 816 817 data[4]*data[1]*data[14] - 818 819 data[0]*data[5]*data[14]) * det; 820 821 dstData[3] = (data[9]*data[6]*data[3] - 822 823 data[5]*data[10]*data[3] - 824 825 data[9]*data[2]*data[7] + 826 827 data[1]*data[10]*data[7] + 828 829 data[5]*data[2]*data[11] - 830 831 data[1]*data[6]*data[11]) * det; 832 833 dstData[7] = (data[4]*data[10]*data[3] - 834 835 data[8]*data[6]*data[3] + 836 837 data[8]*data[2]*data[7] - 838 839 data[0]*data[10]*data[7] - 840 841 data[4]*data[2]*data[11] + 842 843 data[0]*data[6]*data[11]) * det; 844 845 dstData[11] = (data[8]*data[5]*data[3] - 846 847 data[4]*data[9]*data[3] - 848 849 data[8]*data[1]*data[7] + 850 851 data[0]*data[9]*data[7] + 852 853 data[4]*data[1]*data[11] - 854 855 data[0]*data[5]*data[11]) * det; 856 857 dstData[15] = (data[4]*data[9]*data[2] - 858 859 data[8]*data[5]*data[2] + 860 861 data[8]*data[1]*data[6] - 862 863 data[0]*data[9]*data[6] - 864 865 data[4]*data[1]*data[10] + 866 867 data[0]*data[5]*data[10]) * det; 868 869 870 871 set(dstData); 872 873 } 874 875 437 { 438 float* data = (float*) mat._data; 439 440 float det = 441 data[12] * data[9] * data[6] * data[3]- 442 data[8] * data[13] * data[6] * data[3]- 443 data[12] * data[5] * data[10] * data[3]+ 444 data[4] * data[13] * data[10] * data[3]+ 445 data[8] * data[5] * data[14] * data[3]- 446 data[4] * data[9] * data[14] * data[3]- 447 data[12] * data[9] * data[2] * data[7]+ 448 data[8] * data[13] * data[2] * data[7]+ 449 data[12] * data[1] * data[10] * data[7]- 450 data[0] * data[13] * data[10] * data[7]- 451 data[8] * data[1] * data[14] * data[7]+ 452 data[0] * data[9] * data[14] * data[7]+ 453 data[12] * data[5] * data[2] * data[11]- 454 data[4] * data[13] * data[2] * data[11]- 455 data[12] * data[1] * data[6] * data[11]+ 456 data[0] * data[13] * data[6] * data[11]+ 457 data[4] * data[1] * data[14] * data[11]- 458 data[0] * data[5] * data[14] * data[11]- 459 data[8] * data[5] * data[2] * data[15]+ 460 data[4] * data[9] * data[2] * data[15]+ 461 data[8] * data[1] * data[6] * data[15]- 462 data[0] * data[9] * data[6] * data[15]- 463 data[4] * data[1] * data[10] * data[15]+ 464 data[0] * data[5] * data[10] * data[15]; 465 466 if ( det == 0.0f ) return; 467 det = 1 / det; 468 469 float dstData[16]; 470 471 dstData[0] = (data[9]*data[14]*data[7] - 472 data[13]*data[10]*data[7] + 473 data[13]*data[6]*data[11] - 474 data[5]*data[14]*data[11] - 475 data[9]*data[6]*data[15] + 476 data[5]*data[10]*data[15]) * det; 477 478 dstData[4] = (data[12]*data[10]*data[7] - 479 data[8]*data[14]*data[7] - 480 data[12]*data[6]*data[11] + 481 data[4]*data[14]*data[11] + 482 data[8]*data[6]*data[15] - 483 data[4]*data[10]*data[15]) * det; 484 485 dstData[8] = (data[8]*data[13]*data[7] - 486 data[12]*data[9]*data[7] + 487 data[12]*data[5]*data[11] - 488 data[4]*data[13]*data[11] - 489 data[8]*data[5]*data[15] + 490 data[4]*data[9]*data[15]) * det; 491 492 dstData[12] = (data[12]*data[9]*data[6] - 493 data[8]*data[13]*data[6] - 494 data[12]*data[5]*data[10] + 495 data[4]*data[13]*data[10] + 496 data[8]*data[5]*data[14] - 497 data[4]*data[9]*data[14]) * det; 498 499 dstData[1] = (data[13]*data[10]*data[3] - 500 data[9]*data[14]*data[3] - 501 data[13]*data[2]*data[11] + 502 data[1]*data[14]*data[11] + 503 data[9]*data[2]*data[15] - 504 data[1]*data[10]*data[15]) * det; 505 506 dstData[5] = (data[8]*data[14]*data[3] - 507 data[12]*data[10]*data[3] + 508 data[12]*data[2]*data[11] - 509 data[0]*data[14]*data[11] - 510 data[8]*data[2]*data[15] + 511 data[0]*data[10]*data[15]) * det; 512 513 dstData[9] = (data[12]*data[9]*data[3] - 514 data[8]*data[13]*data[3] - 515 data[12]*data[1]*data[11] + 516 data[0]*data[13]*data[11] + 517 data[8]*data[1]*data[15] - 518 data[0]*data[9]*data[15]) * det; 519 520 dstData[13] = (data[8]*data[13]*data[2] - 521 data[12]*data[9]*data[2] + 522 data[12]*data[1]*data[10] - 523 data[0]*data[13]*data[10] - 524 data[8]*data[1]*data[14] + 525 data[0]*data[9]*data[14]) * det; 526 527 dstData[2] = (data[5]*data[14]*data[3] - 528 data[13]*data[6]*data[3] + 529 data[13]*data[2]*data[7] - 530 data[1]*data[14]*data[7] - 531 data[5]*data[2]*data[15] + 532 data[1]*data[6]*data[15]) * det; 533 534 dstData[6] = (data[12]*data[6]*data[3] - 535 data[4]*data[14]*data[3] - 536 data[12]*data[2]*data[7] + 537 data[0]*data[14]*data[7] + 538 data[4]*data[2]*data[15] - 539 data[0]*data[6]*data[15]) * det; 540 541 dstData[10] = (data[4]*data[13]*data[3] - 542 data[12]*data[5]*data[3] + 543 data[12]*data[1]*data[7] - 544 data[0]*data[13]*data[7] - 545 data[4]*data[1]*data[15] + 546 data[0]*data[5]*data[15]) * det; 547 548 dstData[14] = (data[12]*data[5]*data[2] - 549 data[4]*data[13]*data[2] - 550 data[12]*data[1]*data[6] + 551 data[0]*data[13]*data[6] + 552 data[4]*data[1]*data[14] - 553 data[0]*data[5]*data[14]) * det; 554 555 dstData[3] = (data[9]*data[6]*data[3] - 556 data[5]*data[10]*data[3] - 557 data[9]*data[2]*data[7] + 558 data[1]*data[10]*data[7] + 559 data[5]*data[2]*data[11] - 560 data[1]*data[6]*data[11]) * det; 561 562 dstData[7] = (data[4]*data[10]*data[3] - 563 data[8]*data[6]*data[3] + 564 data[8]*data[2]*data[7] - 565 data[0]*data[10]*data[7] - 566 data[4]*data[2]*data[11] + 567 data[0]*data[6]*data[11]) * det; 568 569 dstData[11] = (data[8]*data[5]*data[3] - 570 data[4]*data[9]*data[3] - 571 data[8]*data[1]*data[7] + 572 data[0]*data[9]*data[7] + 573 data[4]*data[1]*data[11] - 574 data[0]*data[5]*data[11]) * det; 575 576 dstData[15] = (data[4]*data[9]*data[2] - 577 data[8]*data[5]*data[2] + 578 data[8]*data[1]*data[6] - 579 data[0]*data[9]*data[6] - 580 data[4]*data[1]*data[10] + 581 data[0]*data[5]*data[10]) * det; 582 583 set(dstData); 584 } 876 585 877 586 void vrMatrix4x4f::invertFast(const vrMatrix4x4f& mat) 878 879 { 880 881 float* srcData = (float*) mat._data; 882 883 884 885 float det = 886 887 srcData[12] * srcData[9] * srcData[6] * srcData[3]- 888 889 srcData[8] * srcData[13] * srcData[6] * srcData[3]- 890 891 srcData[12] * srcData[5] * srcData[10] * srcData[3]+ 892 893 srcData[4] * srcData[13] * srcData[10] * srcData[3]+ 894 895 srcData[8] * srcData[5] * srcData[14] * srcData[3]- 896 897 srcData[4] * srcData[9] * srcData[14] * srcData[3]- 898 899 srcData[12] * srcData[9] * srcData[2] * srcData[7]+ 900 901 srcData[8] * srcData[13] * srcData[2] * srcData[7]+ 902 903 srcData[12] * srcData[1] * srcData[10] * srcData[7]- 904 905 srcData[0] * srcData[13] * srcData[10] * srcData[7]- 906 907 srcData[8] * srcData[1] * srcData[14] * srcData[7]+ 908 909 srcData[0] * srcData[9] * srcData[14] * srcData[7]+ 910 911 srcData[12] * srcData[5] * srcData[2] * srcData[11]- 912 913 srcData[4] * srcData[13] * srcData[2] * srcData[11]- 914 915 srcData[12] * srcData[1] * srcData[6] * srcData[11]+ 916 917 srcData[0] * srcData[13] * srcData[6] * srcData[11]+ 918 919 srcData[4] * srcData[1] * srcData[14] * srcData[11]- 920 921 srcData[0] * srcData[5] * srcData[14] * srcData[11]- 922 923 srcData[8] * srcData[5] * srcData[2] * srcData[15]+ 924 925 srcData[4] * srcData[9] * srcData[2] * srcData[15]+ 926 927 srcData[8] * srcData[1] * srcData[6] * srcData[15]- 928 929 srcData[0] * srcData[9] * srcData[6] * srcData[15]- 930 931 srcData[4] * srcData[1] * srcData[10] * srcData[15]+ 932 933 srcData[0] * srcData[5] * srcData[10] * srcData[15]; 934 935 936 937 if ( det == 0.0f ) return; 938 939 det = 1 / det; 940 941 942 943 _data[0] = (srcData[9]*srcData[14]*srcData[7] - 944 945 srcData[13]*srcData[10]*srcData[7] + 946 947 srcData[13]*srcData[6]*srcData[11] - 948 949 srcData[5]*srcData[14]*srcData[11] - 950 951 srcData[9]*srcData[6]*srcData[15] + 952 953 srcData[5]*srcData[10]*srcData[15]) * det; 954 955 _data[4] = (srcData[12]*srcData[10]*srcData[7] - 956 957 srcData[8]*srcData[14]*srcData[7] - 958 959 srcData[12]*srcData[6]*srcData[11] + 960 961 srcData[4]*srcData[14]*srcData[11] + 962 963 srcData[8]*srcData[6]*srcData[15] - 964 965 srcData[4]*srcData[10]*srcData[15]) * det; 966 967 _data[8] = (srcData[8]*srcData[13]*srcData[7] - 968 969 srcData[12]*srcData[9]*srcData[7] + 970 971 srcData[12]*srcData[5]*srcData[11] - 972 973 srcData[4]*srcData[13]*srcData[11] - 974 975 srcData[8]*srcData[5]*srcData[15] + 976 977 srcData[4]*srcData[9]*srcData[15]) * det; 978 979 _data[12] = (srcData[12]*srcData[9]*srcData[6] - 980 981 srcData[8]*srcData[13]*srcData[6] - 982 983 srcData[12]*srcData[5]*srcData[10] + 984 985 srcData[4]*srcData[13]*srcData[10] + 986 987 srcData[8]*srcData[5]*srcData[14] - 988 989 srcData[4]*srcData[9]*srcData[14]) * det; 990 991 _data[1] = (srcData[13]*srcData[10]*srcData[3] - 992 993 srcData[9]*srcData[14]*srcData[3] - 994 995 srcData[13]*srcData[2]*srcData[11] + 996 997 srcData[1]*srcData[14]*srcData[11] + 998 999 srcData[9]*srcData[2]*srcData[15] - 1000 1001 srcData[1]*srcData[10]*srcData[15]) * det; 1002 1003 _data[5] = (srcData[8]*srcData[14]*srcData[3] - 1004 1005 srcData[12]*srcData[10]*srcData[3] + 1006 1007 srcData[12]*srcData[2]*srcData[11] - 1008 1009 srcData[0]*srcData[14]*srcData[11] - 1010 1011 srcData[8]*srcData[2]*srcData[15] + 1012 1013 srcData[0]*srcData[10]*srcData[15]) * det; 1014 1015 _data[9] = (srcData[12]*srcData[9]*srcData[3] - 1016 1017 srcData[8]*srcData[13]*srcData[3] - 1018 1019 srcData[12]*srcData[1]*srcData[11] + 1020 1021 srcData[0]*srcData[13]*srcData[11] + 1022 1023 srcData[8]*srcData[1]*srcData[15] - 1024 1025 srcData[0]*srcData[9]*srcData[15]) * det; 1026 1027 _data[13] = (srcData[8]*srcData[13]*srcData[2] - 1028 1029 srcData[12]*srcData[9]*srcData[2] + 1030 1031 srcData[12]*srcData[1]*srcData[10] - 1032 1033 srcData[0]*srcData[13]*srcData[10] - 1034 1035 srcData[8]*srcData[1]*srcData[14] + 1036 1037 srcData[0]*srcData[9]*srcData[14]) * det; 1038 1039 _data[2] = (srcData[5]*srcData[14]*srcData[3] - 1040 1041 srcData[13]*srcData[6]*srcData[3] + 1042 1043 srcData[13]*srcData[2]*srcData[7] - 1044 1045 srcData[1]*srcData[14]*srcData[7] - 1046 1047 srcData[5]*srcData[2]*srcData[15] + 1048 1049 srcData[1]*srcData[6]*srcData[15]) * det; 1050 1051 _data[6] = (srcData[12]*srcData[6]*srcData[3] - 1052 1053 srcData[4]*srcData[14]*srcData[3] - 1054 1055 srcData[12]*srcData[2]*srcData[7] + 1056 1057 srcData[0]*srcData[14]*srcData[7] + 1058 1059 srcData[4]*srcData[2]*srcData[15] - 1060 1061 srcData[0]*srcData[6]*srcData[15]) * det; 1062 1063 _data[10] = (srcData[4]*srcData[13]*srcData[3] - 1064 1065 srcData[12]*srcData[5]*srcData[3] + 1066 1067 srcData[12]*srcData[1]*srcData[7] - 1068 1069 srcData[0]*srcData[13]*srcData[7] - 1070 1071 srcData[4]*srcData[1]*srcData[15] + 1072 1073 srcData[0]*srcData[5]*srcData[15]) * det; 1074 1075 _data[14] = (srcData[12]*srcData[5]*srcData[2] - 1076 1077 srcData[4]*srcData[13]*srcData[2] - 1078 1079 srcData[12]*srcData[1]*srcData[6] + 1080 1081 srcData[0]*srcData[13]*srcData[6] + 1082 1083 srcData[4]*srcData[1]*srcData[14] - 1084 1085 srcData[0]*srcData[5]*srcData[14]) * det; 1086 1087 _data[3] = (srcData[9]*srcData[6]*srcData[3] - 1088 1089 srcData[5]*srcData[10]*srcData[3] - 1090 1091 srcData[9]*srcData[2]*srcData[7] + 1092 1093 srcData[1]*srcData[10]*srcData[7] + 1094 1095 srcData[5]*srcData[2]*srcData[11] - 1096 1097 srcData[1]*srcData[6]*srcData[11]) * det; 1098 1099 _data[7] = (srcData[4]*srcData[10]*srcData[3] - 1100 1101 srcData[8]*srcData[6]*srcData[3] + 1102 1103 srcData[8]*srcData[2]*srcData[7] - 1104 1105 srcData[0]*srcData[10]*srcData[7] - 1106 1107 srcData[4]*srcData[2]*srcData[11] + 1108 1109 srcData[0]*srcData[6]*srcData[11]) * det; 1110 1111 _data[11] = (srcData[8]*srcData[5]*srcData[3] - 1112 1113 srcData[4]*srcData[9]*srcData[3] - 1114 1115 srcData[8]*srcData[1]*srcData[7] + 1116 1117 srcData[0]*srcData[9]*srcData[7] + 1118 1119 srcData[4]*srcData[1]*srcData[11] - 1120 1121 srcData[0]*srcData[5]*srcData[11]) * det; 1122 1123 _data[15] = (srcData[4]*srcData[9]*srcData[2] - 1124 1125 srcData[8]*srcData[5]*srcData[2] + 1126 1127 srcData[8]*srcData[1]*srcData[6] - 1128 1129 srcData[0]*srcData[9]*srcData[6] - 1130 1131 srcData[4]*srcData[1]*srcData[10] + 1132 1133 srcData[0]*srcData[5]*srcData[10]) * det; 1134 1135 } 1136 1137 587 { 588 float* srcData = (float*) mat._data; 589 590 float det = 591 srcData[12] * srcData[9] * srcData[6] * srcData[3]- 592 srcData[8] * srcData[13] * srcData[6] * srcData[3]- 593 srcData[12] * srcData[5] * srcData[10] * srcData[3]+ 594 srcData[4] * srcData[13] * srcData[10] * srcData[3]+ 595 srcData[8] * srcData[5] * srcData[14] * srcData[3]- 596 srcData[4] * srcData[9] * srcData[14] * srcData[3]- 597 srcData[12] * srcData[9] * srcData[2] * srcData[7]+ 598 srcData[8] * srcData[13] * srcData[2] * srcData[7]+ 599 srcData[12] * srcData[1] * srcData[10] * srcData[7]- 600 srcData[0] * srcData[13] * srcData[10] * srcData[7]- 601 srcData[8] * srcData[1] * srcData[14] * srcData[7]+ 602 srcData[0] * srcData[9] * srcData[14] * srcData[7]+ 603 srcData[12] * srcData[5] * srcData[2] * srcData[11]- 604 srcData[4] * srcData[13] * srcData[2] * srcData[11]- 605 srcData[12] * srcData[1] * srcData[6] * srcData[11]+ 606 srcData[0] * srcData[13] * srcData[6] * srcData[11]+ 607 srcData[4] * srcData[1] * srcData[14] * srcData[11]- 608 srcData[0] * srcData[5] * srcData[14] * srcData[11]- 609 srcData[8] * srcData[5] * srcData[2] * srcData[15]+ 610 srcData[4] * srcData[9] * srcData[2] * srcData[15]+ 611 srcData[8] * srcData[1] * srcData[6] * srcData[15]- 612 srcData[0] * srcData[9] * srcData[6] * srcData[15]- 613 srcData[4] * srcData[1] * srcData[10] * srcData[15]+ 614 srcData[0] * srcData[5] * srcData[10] * srcData[15]; 615 616 if ( det == 0.0f ) return; 617 det = 1 / det; 618 619 _data[0] = (srcData[9]*srcData[14]*srcData[7] - 620 srcData[13]*srcData[10]*srcData[7] + 621 srcData[13]*srcData[6]*srcData[11] - 622 srcData[5]*srcData[14]*srcData[11] - 623 srcData[9]*srcData[6]*srcData[15] + 624 srcData[5]*srcData[10]*srcData[15]) * det; 625 626 _data[4] = (srcData[12]*srcData[10]*srcData[7] - 627 srcData[8]*srcData[14]*srcData[7] - 628 srcData[12]*srcData[6]*srcData[11] + 629 srcData[4]*srcData[14]*srcData[11] + 630 srcData[8]*srcData[6]*srcData[15] - 631 srcData[4]*srcData[10]*srcData[15]) * det; 632 633 _data[8] = (srcData[8]*srcData[13]*srcData[7] - 634 srcData[12]*srcData[9]*srcData[7] + 635 srcData[12]*srcData[5]*srcData[11] - 636 srcData[4]*srcData[13]*srcData[11] - 637 srcData[8]*srcData[5]*srcData[15] + 638 srcData[4]*srcData[9]*srcData[15]) * det; 639 640 _data[12] = (srcData[12]*srcData[9]*srcData[6] - 641 srcData[8]*srcData[13]*srcData[6] - 642 srcData[12]*srcData[5]*srcData[10] + 643 srcData[4]*srcData[13]*srcData[10] + 644 srcData[8]*srcData[5]*srcData[14] - 645 srcData[4]*srcData[9]*srcData[14]) * det; 646 647 _data[1] = (srcData[13]*srcData[10]*srcData[3] - 648 srcData[9]*srcData[14]*srcData[3] - 649 srcData[13]*srcData[2]*srcData[11] + 650 srcData[1]*srcData[14]*srcData[11] + 651 srcData[9]*srcData[2]*srcData[15] - 652 srcData[1]*srcData[10]*srcData[15]) * det; 653 654 _data[5] = (srcData[8]*srcData[14]*srcData[3] - 655 srcData[12]*srcData[10]*srcData[3] + 656 srcData[12]*srcData[2]*srcData[11] - 657 srcData[0]*srcData[14]*srcData[11] - 658 srcData[8]*srcData[2]*srcData[15] + 659 srcData[0]*srcData[10]*srcData[15]) * det; 660 661 _data[9] = (srcData[12]*srcData[9]*srcData[3] - 662 srcData[8]*srcData[13]*srcData[3] - 663 srcData[12]*srcData[1]*srcData[11] + 664 srcData[0]*srcData[13]*srcData[11] + 665 srcData[8]*srcData[1]*srcData[15] - 666 srcData[0]*srcData[9]*srcData[15]) * det; 667 668 _data[13] = (srcData[8]*srcData[13]*srcData[2] - 669 srcData[12]*srcData[9]*srcData[2] + 670 srcData[12]*srcData[1]*srcData[10] - 671 srcData[0]*srcData[13]*srcData[10] - 672 srcData[8]*srcData[1]*srcData[14] + 673 srcData[0]*srcData[9]*srcData[14]) * det; 674 675 _data[2] = (srcData[5]*srcData[14]*srcData[3] - 676 srcData[13]*srcData[6]*srcData[3] + 677 srcData[13]*srcData[2]*srcData[7] - 678 srcData[1]*srcData[14]*srcData[7] - 679 srcData[5]*srcData[2]*srcData[15] + 680 srcData[1]*srcData[6]*srcData[15]) * det; 681 682 _data[6] = (srcData[12]*srcData[6]*srcData[3] - 683 srcData[4]*srcData[14]*srcData[3] - 684 srcData[12]*srcData[2]*srcData[7] + 685 srcData[0]*srcData[14]*srcData[7] + 686 srcData[4]*srcData[2]*srcData[15] - 687 srcData[0]*srcData[6]*srcData[15]) * det; 688 689 _data[10] = (srcData[4]*srcData[13]*srcData[3] - 690 srcData[12]*srcData[5]*srcData[3] + 691 srcData[12]*srcData[1]*srcData[7] - 692 srcData[0]*srcData[13]*srcData[7] - 693 srcData[4]*srcData[1]*srcData[15] + 694 srcData[0]*srcData[5]*srcData[15]) * det; 695 696 _data[14] = (srcData[12]*srcData[5]*srcData[2] - 697 srcData[4]*srcData[13]*srcData[2] - 698 srcData[12]*srcData[1]*srcData[6] + 699 srcData[0]*srcData[13]*srcData[6] + 700 srcData[4]*srcData[1]*srcData[14] - 701 srcData[0]*srcData[5]*srcData[14]) * det; 702 703 _data[3] = (srcData[9]*srcData[6]*srcData[3] - 704 srcData[5]*srcData[10]*srcData[3] - 705 srcData[9]*srcData[2]*srcData[7] + 706 srcData[1]*srcData[10]*srcData[7] + 707 srcData[5]*srcData[2]*srcData[11] - 708 srcData[1]*srcData[6]*srcData[11]) * det; 709 710 _data[7] = (srcData[4]*srcData[10]*srcData[3] - 711 srcData[8]*srcData[6]*srcData[3] + 712 srcData[8]*srcData[2]*srcData[7] - 713 srcData[0]*srcData[10]*srcData[7] - 714 srcData[4]*srcData[2]*srcData[11] + 715 srcData[0]*srcData[6]*srcData[11]) * det; 716 717 _data[11] = (srcData[8]*srcData[5]*srcData[3] - 718 srcData[4]*srcData[9]*srcData[3] - 719 srcData[8]*srcData[1]*srcData[7] + 720 srcData[0]*srcData[9]*srcData[7] + 721 srcData[4]*srcData[1]*srcData[11] - 722 srcData[0]*srcData[5]*srcData[11]) * det; 723 724 _data[15] = (srcData[4]*srcData[9]*srcData[2] - 725 srcData[8]*srcData[5]*srcData[2] + 726 srcData[8]*srcData[1]*srcData[6] - 727 srcData[0]*srcData[9]*srcData[6] - 728 srcData[4]*srcData[1]*srcData[10] + 729 srcData[0]*srcData[5]*srcData[10]) * det; 730 } 1138 731 1139 732 void vrMatrix4x4f::transpose() 1140 1141 { 1142 1143 float m[16]; 1144 1145 1146 1147 m[0] = _data[0]; 1148 1149 m[1] = _data[4]; 1150 1151 m[2] = _data[8]; 1152 1153 m[3] = _data[12]; 1154 1155 1156 1157 m[4] = _data[1]; 1158 1159 m[5] = _data[5]; 1160 1161 m[6] = _data[9]; 1162 1163 m[7] = _data[13]; 1164 1165 1166 1167 m[8] = _data[2]; 1168 1169 m[9] = _data[6]; 1170 1171 m[10] = _data[10]; 1172 1173 m[11] = _data[14]; 1174 1175 1176 1177 m[12] = _data[3]; 1178 1179 m[13] = _data[7]; 1180 1181 m[14] = _data[11]; 1182 1183 m[15] = _data[15]; 1184 1185 1186 1187 set(m); 1188 1189 } 1190 1191 733 { 734 float m[16]; 735 736 m[0] = _data[0]; 737 m[1] = _data[4]; 738 m[2] = _data[8]; 739 m[3] = _data[12]; 740 741 m[4] = _data[1]; 742 m[5] = _data[5]; 743 m[6] = _data[9]; 744 m[7] = _data[13]; 745 746 m[8] = _data[2]; 747 m[9] = _data[6]; 748 m[10] = _data[10]; 749 m[11] = _data[14]; 750 751 m[12] = _data[3]; 752 m[13] = _data[7]; 753 m[14] = _data[11]; 754 m[15] = _data[15]; 755 756 set(m); 757 } 1192 758 1193 759 void vrMatrix4x4f::transposeFast(const vrMatrix4x4f& mat) 1194 1195 { 1196 1197 _data[0] = mat._data[0]; 1198 1199 _data[1] = mat._data[4]; 1200 1201 _data[2] = mat._data[8]; 1202 1203 _data[3] = mat._data[12]; 1204 1205 1206 1207 _data[4] = mat._data[1]; 1208 1209 _data[5] = mat._data[5]; 1210 1211 _data[6] = mat._data[9]; 1212 1213 _data[7] = mat._data[13]; 1214 1215 1216 1217 _data[8] = mat._data[2]; 1218 1219 _data[9] = mat._data[6]; 1220 1221 _data[10] = mat._data[10]; 1222 1223 _data[11] = mat._data[14]; 1224 1225 1226 1227 _data[12] = mat._data[3]; 1228 1229 _data[13] = mat._data[7]; 1230 1231 _data[14] = mat._data[11]; 1232 1233 _data[15] = mat._data[15]; 1234 1235 } 1236 1237 1238 1239 760 { 761 _data[0] = mat._data[0]; 762 _data[1] = mat._data[4]; 763 _data[2] = mat._data[8]; 764 _data[3] = mat._data[12]; 765 766 _data[4] = mat._data[1]; 767 _data[5] = mat._data[5]; 768 _data[6] = mat._data[9]; 769 _data[7] = mat._data[13]; 770 771 _data[8] = mat._data[2]; 772 _data[9] = mat._data[6]; 773 _data[10] = mat._data[10]; 774 _data[11] = mat._data[14]; 775 776 _data[12] = mat._data[3]; 777 _data[13] = mat._data[7]; 778 _data[14] = mat._data[11]; 779 _data[15] = mat._data[15]; 780 } 1240 781 1241 782 void vrMatrix4x4f::transpose(const vrMatrix4x4f& mat) 1242 1243 { 1244 1245 float m[16]; 1246 1247 1248 1249 m[0] = mat._data[0]; 1250 1251 m[1] = mat._data[4]; 1252 1253 m[2] = mat._data[8]; 1254 1255 m[3] = mat._data[12]; 1256 1257 1258 1259 m[4] = mat._data[1]; 1260 1261 m[5] = mat._data[5]; 1262 1263 m[6] = mat._data[9]; 1264 1265 m[7] = mat._data[13]; 1266 1267 1268 1269 m[8] = mat._data[2]; 1270 1271 m[9] = mat._data[6]; 1272 1273 m[10] = mat._data[10]; 1274 1275 m[11] = mat._data[14]; 1276 1277 1278 1279 m[12] = mat._data[3]; 1280 1281 m[13] = mat._data[7]; 1282 1283 m[14] = mat._data[11]; 1284 1285 m[15] = mat._data[15]; 1286 1287 1288 1289 set(m); 1290 783 { 784 float m[16]; 785 786 m[0] = mat._data[0]; 787 m[1] = mat._data[4]; 788 m[2] = mat._data[8]; 789 m[3] = mat._data[12]; 790 791 m[4] = mat._data[1]; 792 m[5] = mat._data[5]; 793 m[6] = mat._data[9]; 794 m[7] = mat._data[13]; 795 796 m[8] = mat._data[2]; 797 m[9] = mat._data[6]; 798 m[10] = mat._data[10]; 799 m[11] = mat._data[14]; 800 801 m[12] = mat._data[3]; 802 m[13] = mat._data[7]; 803 m[14] = mat._data[11]; 804 m[15] = mat._data[15]; 805 806 set(m); 1291 807 } 1292 808 1293 809 void vrMatrix4x4f::set(double* m) 1294 810 { 1295 for (int i = 0; i < 16; ++i) 1296 { 1297 _data[i] = (float) m[i]; 1298 } 811 for (int i = 0; i < 16; ++i) { 812 _data[i] = (float) m[i]; 813 } 1299 814 } 1300 815 1301 816 void vrMatrix4x4f::multiply(const vrMatrix4x4f& mat1, const vrVector3f& position) 1302 817 { 1303 1304 1305 818 vrMatrix4x4f mat; 819 mat.makeTranslation(position); 820 multiply(mat1, mat); 1306 821 } 1307 822 1308 823 void vrMatrix4x4f::multiply(const vrMatrix4x4f& mat1, const vrRotation& rotation) 1309 824 { 1310 1311 1312 825 vrMatrix4x4f mat; 826 mat.makeRotation(rotation); 827 multiply(mat1, mat); 1313 828 } 1314 829 1315 830 void vrMatrix4x4f::multiply(const vrVector3f& position, const vrMatrix4x4f& mat1) 1316 831 { 1317 1318 1319 832 vrMatrix4x4f mat; 833 mat.makeTranslation(position); 834 multiply(mat, mat1); 1320 835 } 1321 836 1322 837 void vrMatrix4x4f::multiply(const vrRotation& rotation, const vrMatrix4x4f& mat1) 1323 838 { 1324 1325 1326 839 vrMatrix4x4f mat; 840 mat.makeRotation(rotation); 841 multiply(mat, mat1); 1327 842 } 1328 843 1329 844 void vrMatrix4x4f::makeVecRotVec(const vrVector3f& vec1, const vrVector3f& vec2) 1330 845 { 1331 vrVector3f axis; 1332 axis.cross(vec1, vec2); 1333 1334 float angle = atan2(axis.length(), vec1.dot(vec2)); 1335 if (axis.normalize() == 0.0f) 1336 { 1337 makeIdentity(); 1338 } 1339 else 1340 { 1341 makeRotation(axis.x, axis.y, axis.z, angle); 1342 } 846 vrVector3f axis; 847 axis.cross(vec1, vec2); 848 849 float angle = atan2(axis.length(), vec1.dot(vec2)); 850 if (axis.normalize() == 0.0f) { 851 makeIdentity(); 852 } else { 853 makeRotation(axis.x, axis.y, axis.z, angle); 854 } 1343 855 } 1344 856 1345 857 void vrMatrix4x4f::multiplyScale(const vrMatrix4x4f& mat1, const vrVector3f& scale) 1346 858 { 1347 1348 1349 859 vrMatrix4x4f mat; 860 mat.makeScale(scale); 861 multiply(mat1, mat); 1350 862 } 1351 863 1352 864 void vrMatrix4x4f::multiplyScale(const vrVector3f& scale, const vrMatrix4x4f& mat1) 1353 865 { 1354 vrMatrix4x4f mat; 1355 mat.makeScale(scale); 1356 multiply(mat, mat1); 1357 } 1358 866 vrMatrix4x4f mat; 867 mat.makeScale(scale); 868 multiply(mat, mat1); 869 } -
trunk/packages/vizservers/nanovis/vrmath/vrPlane.cpp
r2798 r2840 8 8 9 9 normal.set(m[0]*v.x + m[1]*v.y + m[2]*v.z + m[3]*v.w, 10 11 10 m[4]*v.x + m[5]*v.y + m[6]*v.z + m[7]*v.w, 11 m[8]*v.x + m[9]*v.y + m[10]*v.z + m[11]*v.w); 12 12 13 13 distance = m[12]*v.x + m[13]*v.y + m[14]*v.z + m[15]*v.w; -
trunk/packages/vizservers/nanovis/vrmath/vrPlane2.cpp
r2798 r2840 2 2 #include <vrmath/vrPlane2.h> 3 3 4 void vrPlane2::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) { 4 void vrPlane2::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) 5 { 6 normal.cross(p2 - p1, p3 - p1); 7 normal.normalize(); 5 8 6 normal.cross(p2 - p1, p3 - p1); 7 normal.normalize(); 8 9 point = p1; 10 9 point = p1; 11 10 } 12 11 13 void vrPlane2::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) { 14 normal = norm; 15 point = pos; 12 void vrPlane2::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) 13 { 14 normal = norm; 15 point = pos; 16 16 } 17 17 18 18 bool vrPlane2::intersect(const vrLineSegment &seg, float &d) const 19 19 { 20 21 20 // STEVE 21 // 2005-09-07 22 22 23 23 float tu, td; 24 24 25 26 25 tu = normal.x * (point.x - seg.pos.x) + normal.y * (point.y - seg.pos.y) 26 + normal.z * (point.z - seg.pos.z); 27 27 28 28 td = normal.x * seg.dir.x + normal.y * seg.dir.y + normal.z * seg.dir.z; 29 29 30 30 if ( td == 0.0f ) return false; 31 31 32 32 d = tu / td; 33 33 34 34 return true; 35 35 } 36 36 37 37 float vrPlane2::distance(const vrVector3f& pos) const 38 38 { 39 vrVector3f plane_point = crossPoint( pos ); 39 40 40 vrVector3f plane_point = crossPoint( pos ); 41 42 return pos.distance( plane_point ); 41 return pos.distance( plane_point ); 43 42 } 44 43 45 vrVector3f vrPlane2::crossPoint(const vrVector3f& pos) const { 44 vrVector3f vrPlane2::crossPoint(const vrVector3f& pos) const 45 { 46 vrLineSegment seg; 46 47 47 vrLineSegment seg; 48 seg.pos = pos; 49 seg.dir = normal; 48 50 49 seg.pos = pos;50 seg.dir = normal;51 float t = 0; 52 intersect(seg, t); 51 53 52 float t = 0; 53 intersect(seg, t); 54 55 return seg.getPoint(t); 54 return seg.getPoint(t); 56 55 } -
trunk/packages/vizservers/nanovis/vrmath/vrQuaternion.cpp
r2798 r2840 18 18 #endif 19 19 20 vrQuaternion::vrQuaternion() 21 :x(1.0f), y(0.0f), z(0.0f), w(0.0f)20 vrQuaternion::vrQuaternion() : 21 x(1.0f), y(0.0f), z(0.0f), w(0.0f) 22 22 { 23 23 } … … 25 25 vrQuaternion::vrQuaternion(const vrRotation& rot) 26 26 { 27 27 set(rot); 28 28 } 29 29 30 vrQuaternion::vrQuaternion(float x1, float y1, float z1, float w1) 31 :x(x1), y(y1), z(z1), w(w1)30 vrQuaternion::vrQuaternion(float x1, float y1, float z1, float w1) : 31 x(x1), y(y1), z(z1), w(w1) 32 32 { 33 33 } … … 35 35 const vrQuaternion& vrQuaternion::normalize() 36 36 { 37 float norme = sqrt(w*w + x*x + y*y + z*z); 38 if (norme == 0.0) 39 { 40 w = 1.0; 41 x = y = z = 0.0f; 42 } 43 else 44 { 45 float recip = 1.0f/norme; 46 w *= recip; 47 x *= recip; 48 y *= recip; 49 z *= recip; 50 } 37 float norme = sqrt(w*w + x*x + y*y + z*z); 38 if (norme == 0.0) { 39 w = 1.0; 40 x = y = z = 0.0f; 41 } else { 42 float recip = 1.0f/norme; 43 w *= recip; 44 x *= recip; 45 y *= recip; 46 z *= recip; 47 } 51 48 52 49 return *this; 53 50 } 54 51 55 52 const vrQuaternion& vrQuaternion::set(const vrRotation& rot) 56 53 { 57 /* 58 54 #if 0 55 float omega, s, c; 59 56 60 s = sqrt(rot.x*rot.x + rot.y*rot.y + rot.z*rot.z); 61 62 if (fabs(s) > FLT_EPSILON) 63 { 64 c = 1.0/s; 65 float rot_x = rot.x * c; 66 float rot_y = rot.y * c; 67 float rot_z = rot.z * c; 57 s = sqrt(rot.x*rot.x + rot.y*rot.y + rot.z*rot.z); 68 58 69 omega = -0.5f * rot.angle; 70 s = (float)sin(omega); 71 x = s*rot_x; 72 y = s*rot_y; 73 z = s*rot_z; 74 w = (float)cos(omega); 75 } 76 else 77 { 78 x = y = 0.0f; 79 z = 0.0f; 80 w = 1.0f; 81 } 59 if (fabs(s) > FLT_EPSILON) { 60 c = 1.0/s; 61 float rot_x = rot.x * c; 62 float rot_y = rot.y * c; 63 float rot_z = rot.z * c; 82 64 83 normalize();84 85 return *this;86 */ 87 vrVector3f q(rot.x, rot.y, rot.z);88 q.normalize();89 float s = (float)sin(rot.angle * 0.5); 90 x = s * q.x;91 y = s * q.y;92 z = s * q.z;93 w = (float) cos (rot.angle * 0.5f); 65 omega = -0.5f * rot.angle; 66 s = (float)sin(omega); 67 x = s*rot_x; 68 y = s*rot_y; 69 z = s*rot_z; 70 w = (float)cos(omega); 71 } else { 72 x = y = 0.0f; 73 z = 0.0f; 74 w = 1.0f; 75 } 94 76 95 return *this; 77 normalize(); 78 79 return *this; 80 #endif 81 vrVector3f q(rot.x, rot.y, rot.z); 82 q.normalize(); 83 float s = (float)sin(rot.angle * 0.5); 84 x = s * q.x; 85 y = s * q.y; 86 z = s * q.z; 87 w = (float)cos(rot.angle * 0.5f); 88 89 return *this; 96 90 } 97 91 98 92 void vrQuaternion::slerp(const vrQuaternion &a,const vrQuaternion &b, const float t) 99 93 { 100 /* 101 102 94 #if 0 95 float omega, cosom, sinom, sclp, sclq; 96 cosom = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; 103 97 104 if ((1.0f+cosom) > FLT_EPSILON) 105 { 106 if ((1.0f-cosom) > FLT_EPSILON) 107 { 108 omega = acos(cosom); 109 sinom = sin(omega); 110 sclp = sin((1.0f-t)*omega) / sinom; 111 sclq = sin(t*omega) / sinom; 112 } 113 else 114 { 115 sclp = 1.0f - t; 116 sclq = t; 117 } 98 if ((1.0f+cosom) > FLT_EPSILON) { 99 if ((1.0f-cosom) > FLT_EPSILON) { 100 omega = acos(cosom); 101 sinom = sin(omega); 102 sclp = sin((1.0f-t)*omega) / sinom; 103 sclq = sin(t*omega) / sinom; 104 } else { 105 sclp = 1.0f - t; 106 sclq = t; 107 } 118 108 119 x = sclp*a.x + sclq*b.x; 120 y = sclp*a.y + sclq*b.y; 121 z = sclp*a.z + sclq*b.z; 122 w = sclp*a.w + sclq*b.w; 123 } 124 else 125 { 126 x =-a.y; 127 y = a.x; 128 z =-a.w; 129 w = a.z; 109 x = sclp*a.x + sclq*b.x; 110 y = sclp*a.y + sclq*b.y; 111 z = sclp*a.z + sclq*b.z; 112 w = sclp*a.w + sclq*b.w; 113 } else { 114 x =-a.y; 115 y = a.x; 116 z =-a.w; 117 w = a.z; 130 118 131 132 119 sclp = sin((1.0f-t) * PI * 0.5); 120 sclq = sin(t * PI * 0.5); 133 121 134 135 136 137 138 */ 139 140 141 122 x = sclp*a.x + sclq*b.x; 123 y = sclp*a.y + sclq*b.y; 124 z = sclp*a.z + sclq*b.z; 125 } 126 #endif 127 double alpha, beta; 128 double cosom = a.x * b.x + a.y * b.y + 129 a.z * b.z + a.w * b.w; 142 130 143 bool flip = (cosom < 0.0); 144 if (flip) cosom = -cosom; 145 if ((1.0 - cosom) > 0.00001f){ 146 double omega = acos(cosom); 147 double sinom = sin(omega); 148 alpha = sin((1.0 - t) * omega) / sinom; 149 beta = sin(t * omega) / sinom; 150 } 151 else { 152 alpha = 1.0f - t; 153 beta = t; 154 } 131 bool flip = (cosom < 0.0); 132 if (flip) cosom = -cosom; 133 if ((1.0 - cosom) > 0.00001f) { 134 double omega = acos(cosom); 135 double sinom = sin(omega); 136 alpha = sin((1.0 - t) * omega) / sinom; 137 beta = sin(t * omega) / sinom; 138 } else { 139 alpha = 1.0f - t; 140 beta = t; 141 } 155 142 156 157 158 159 160 143 if (flip) beta = -beta; 144 x = (float) (alpha * a.x + beta * b.x); 145 y = (float) (alpha * a.y + beta * b.y); 146 z = (float) (alpha * a.z + beta * b.z); 147 w = (float) (alpha * a.w + beta * b.w); 161 148 } 162 -
trunk/packages/vizservers/nanovis/vrmath/vrRotation.cpp
r2798 r2840 6 6 void vrRotation::set(const vrVector3f &vec1, const vrVector3f &vec2) 7 7 { 8 if ( vec1 == vec2 ) 9 { 10 x = 0.0f; 11 y = 0.0f; 12 z = 1.0f; 13 angle = 0.0f; 14 return; 15 } 8 if (vec1 == vec2) { 9 x = 0.0f; 10 y = 0.0f; 11 z = 1.0f; 12 angle = 0.0f; 13 return; 14 } 16 15 17 18 16 vrVector3f cross; 17 cross.cross(vec1, vec2); 19 18 20 19 float ang = atan2( cross.length(), vec1.dot(vec2) ); 21 20 22 21 cross.normalize(); 23 22 24 25 26 27 23 x = cross.x; 24 y = cross.y; 25 z = cross.z; 26 angle = ang; 28 27 } 29 28 30 29 void vrRotation::set(const vrQuaternion& quat) 31 30 { 32 31 //if (quat.w > 1) quat.normalize(); 33 32 34 angle = acos(quat.w) * 2.0f; 35 float scale = sqrt(1 - quat.w * quat.w); 36 if (scale < 0.001) 37 { 38 x = quat.x; 39 y = quat.y; 40 z = quat.z; 41 } 42 else 43 { 44 x = quat.x / scale; 45 y = quat.y / scale; 46 z = quat.z / scale; 47 } 48 /* 49 // http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Quaternion_to_axis-angle 50 float scale = sqrt(quat.x * quat.x + quat.y * quat.y + quat.z * quat.z); 51 x = quat.x / scale; 52 y = quat.y / scale; 53 z = quat.z / scale; 54 */ 33 angle = acos(quat.w) * 2.0f; 34 float scale = sqrt(1 - quat.w * quat.w); 35 if (scale < 0.001) { 36 x = quat.x; 37 y = quat.y; 38 z = quat.z; 39 } else { 40 x = quat.x / scale; 41 y = quat.y / scale; 42 z = quat.z / scale; 43 } 44 /* 45 // http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Quaternion_to_axis-angle 46 float scale = sqrt(quat.x * quat.x + quat.y * quat.y + quat.z * quat.z); 47 x = quat.x / scale; 48 y = quat.y / scale; 49 z = quat.z / scale; 50 */ 55 51 } -
trunk/packages/vizservers/nanovis/vrmath/vrVector3f.cpp
r2798 r2840 3 3 #include <vrmath/vrMatrix4x4f.h> 4 4 5 6 5 void vrVector3f::transform(const vrMatrix4x4f& m, const vrVector3f& v) 7 6 { 8 const float*mat = m.get();7 const float *mat = m.get(); 9 8 10 11 12 9 set(mat[0] * v.x + mat[4] * v.y + mat[8] * v.z + mat[12], 10 mat[1] * v.x + mat[5] * v.y + mat[9] * v.z + mat[13], 11 mat[2] * v.x + mat[6] * v.y + mat[10] * v.z + mat[14]); 13 12 } 14 15 16 13 17 14 void vrVector3f::transformVec(const vrMatrix4x4f& m, const vrVector3f& v) 18 15 { 19 const float*mat = m.get();16 const float *mat = m.get(); 20 17 21 22 23 18 set(mat[0] * v.x + mat[4] * v.y + mat[8] * v.z, 19 mat[1] * v.x + mat[5] * v.y + mat[9] * v.z, 20 mat[2] * v.x + mat[6] * v.y + mat[10] * v.z); 24 21 } -
trunk/packages/vizservers/nanovis/vrmath/vrVector4f.cpp
r2798 r2840 5 5 void vrVector4f::mult( const vrMatrix4x4f& mat, const vrVector4f& vector) 6 6 { 7 const float *m = mat.get();7 const float *m = mat.get(); 8 8 x = vector.x*m[0]+vector.y*m[4]+vector.z*m[8]+vector.w*m[12]; 9 10 11 9 y = vector.x*m[1]+vector.y*m[5]+vector.z*m[9]+vector.w*m[13]; 10 z = vector.x*m[2]+vector.y*m[6]+vector.z*m[10]+vector.w*m[14]; 11 w = vector.x*m[3]+vector.y*m[7]+vector.z*m[11]+vector.w*m[15]; 12 12 } 13 13 … … 15 15 { 16 16 vrVector4f vector(x, y, z, w); 17 const float *m = mat.get();17 const float *m = mat.get(); 18 18 19 20 21 22 19 x = vector.x*m[0]+vector.y*m[4]+vector.z*m[8]+vector.w*m[12]; 20 y = vector.x*m[1]+vector.y*m[5]+vector.z*m[9]+vector.w*m[13]; 21 z = vector.x*m[2]+vector.y*m[6]+vector.z*m[10]+vector.w*m[14]; 22 w = vector.x*m[3]+vector.y*m[7]+vector.z*m[11]+vector.w*m[15]; 23 23 } 24 24 25 25 void vrVector4f::transform(const vrVector4f& v, const vrMatrix4x4f& mat) 26 26 { 27 28 const float*m = mat.get();29 27 vrVector4f vector(x, y, z, w); 28 const float *m = mat.get(); 29 x = vector.x * m[0] + vector.y*m[4]+vector.z*m[8]+vector.w*m[12]; 30 30 y = vector.x * m[1] + vector.y*m[5]+vector.z*m[9]+vector.w*m[13]; 31 31 z = vector.x*m[2]+vector.y*m[6]+vector.z*m[10]+vector.w*m[14];
Note: See TracChangeset
for help on using the changeset viewer.