Index: src/OFMatrix4x4.h ================================================================== --- src/OFMatrix4x4.h +++ src/OFMatrix4x4.h @@ -70,20 +70,14 @@ * @param matrix The matrix to multiply the receiver with */ - (void)multiplyWithMatrix: (OFMatrix4x4 *)matrix; /** - * @brief Transforms the specified 3D vector according to the matrix. - * - * As multiplying a 4x4 matrix with a 3D vector is not defined, this extends - * the 3D vector to a 4D vector with its `w` value being set to 0 and just - * discards the `w` value of the resulting 4D vector for the returned 3D - * vector. This allows reducing the number number of calculations performed and - * is mostly useful for 3D graphics. - * - * @param vector The 3D vector to transform - * @return The transformed 3D vector - */ -- (OFVector3D)transformedVector3D: (OFVector3D)vector; + * @brief Transforms the specified point in 3D space according to the matrix. + * + * @param point The point to transform + * @return The transformed point + */ +- (OFPoint3D)transformedPoint3D: (OFPoint3D)point; @end OF_ASSUME_NONNULL_END Index: src/OFMatrix4x4.m ================================================================== --- src/OFMatrix4x4.m +++ src/OFMatrix4x4.m @@ -182,19 +182,19 @@ matrix->_values[7] * copy[13] + matrix->_values[11] * copy[14] + matrix->_values[15] * copy[15]; } -- (OFVector3D)transformedVector3D: (OFVector3D)vector -{ - return OFMakeVector3D( - _values[0] * vector.x + _values[4] * vector.y + - _values[8] * vector.z, - _values[1] * vector.x + _values[5] * vector.y + - _values[9] * vector.z, - _values[2] * vector.x + _values[6] * vector.y + - _values[10] * vector.z); +- (OFPoint3D)transformedPoint3D: (OFPoint3D)point +{ + return OFMakePoint3D( + _values[0] * point.x + _values[4] * point.y + + _values[8] * point.z + _values[12], + _values[1] * point.x + _values[5] * point.y + + _values[9] * point.z + _values[13], + _values[2] * point.x + _values[6] * point.y + + _values[10] * point.z + _values[14]); } - (OFString *)description { return [OFString stringWithFormat: Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -153,11 +153,11 @@ typedef double OFTimeInterval; /** * @struct OFPoint OFObject.h ObjFW/OFObject.h * - * @brief A point. + * @brief A point in 2D space. */ typedef struct OF_BOXABLE { /** The x coordinate of the point */ float x; /** The y coordinate of the point */ @@ -294,56 +294,56 @@ return true; } /** - * @struct OFVector3D OFObject.h ObjFW/OFObject.h + * @struct OFPoint3D OFObject.h ObjFW/OFObject.h * - * @brief A vector in 3D space. + * @brief A point in 3D space. */ typedef struct OF_BOXABLE { - /** The x coordinate of the vector */ - float x; - /** The y coordinate of the vector */ - float y; - /** The z coordinate of the vector */ - float z; -} OFVector3D; - -/** - * @brief Creates a new OFVector3D. - * - * @param x The x coordinate of the vector - * @param y The x coordinate of the vector - * @param z The z coordinate of the vector - * @return An OFVector3D with the specified coordinates - */ -static OF_INLINE OFVector3D OF_CONST_FUNC -OFMakeVector3D(float x, float y, float z) -{ - OFVector3D vector = { x, y, z }; - - return vector; -} - -/** - * @brief Returns whether the two vectors are equal. - * - * @param vector1 The first vector for the comparison - * @param vector2 The second vector for the comparison - * @return Whether the two vectors are equal + /** The x coordinate of the point */ + float x; + /** The y coordinate of the point */ + float y; + /** The z coordinate of the point */ + float z; +} OFPoint3D; + +/** + * @brief Creates a new OFPoint3D. + * + * @param x The x coordinate of the point + * @param y The x coordinate of the point + * @param z The z coordinate of the point + * @return An OFPoint3D with the specified coordinates + */ +static OF_INLINE OFPoint3D OF_CONST_FUNC +OFMakePoint3D(float x, float y, float z) +{ + OFPoint3D point = { x, y, z }; + + return point; +} + +/** + * @brief Returns whether the two points are equal. + * + * @param point1 The first point for the comparison + * @param point2 The second point for the comparison + * @return Whether the two points are equal */ static OF_INLINE bool -OFEqualVectors3D(OFVector3D vector1, OFVector3D vector2) +OFEqualPoints3D(OFPoint3D point1, OFPoint3D point2) { - if (vector1.x != vector2.x) + if (point1.x != point2.x) + return false; + + if (point1.y != point2.y) return false; - if (vector1.y != vector2.y) - return false; - - if (vector1.z != vector2.z) + if (point1.z != point2.z) return false; return true; } Index: tests/OFMatrix4x4Tests.m ================================================================== --- tests/OFMatrix4x4Tests.m +++ tests/OFMatrix4x4Tests.m @@ -22,11 +22,11 @@ @implementation TestsAppDelegate (OFMatrix4x4Tests) - (void)matrix4x4Tests { void *pool = objc_autoreleasePoolPush(); OFMatrix4x4 *matrix, *matrix2; - OFVector3D vec3; + OFPoint3D point; TEST(@"+[identityMatrix]", memcmp([[OFMatrix4x4 identityMatrix] values], (float [16]){ 1, 0, 0, 0, 0, 1, 0, 0, @@ -85,12 +85,12 @@ 10000, 22800, 35600, 48400, 11000, 25400, 39800, 54200, 12000, 28000, 44000, 60000 }]]) - TEST(@"-[transformedVector3D:]", - R((vec3 = [matrix transformedVector3D: OFMakeVector3D(1, 2, 3)])) && - vec3.x == 14 && vec3.y == 38 && vec3.z == 62) + TEST(@"-[transformedPoint3D:]", + R((point = [matrix transformedPoint3D: OFMakePoint3D(1, 2, 3)])) && + point.x == 18 && point.y == 46 && point.z == 74) objc_autoreleasePoolPop(pool); } @end