9club Forum

9club.com.

You are not logged in.

#1 2020-09-13 22:20:52

KelleyGrov
Member
From: Austria, Zeiselberg
Registered: 2020-09-13
Posts: 1

Click to share on Facebook (Opens in new window)

A simple C++ 3D vector prototype library

Filed under: , Electronic  Games ,  — Leave a comment        July 14, 2018                 Hello people.
I hope you are well.

In this article I would like to present you a simple C++ 3D vector library

This is just a prototype and I am sure you can find other better and more complete  alternatives .
So, .

We are just dealing here with a “Yet Another 3D Vector Library”

I created this library because I wanted to reuse some 3D vector operations in various OpenGL computer graphics exercise programs (from my M.
Sc.
studies).
Of course, I could use an already existing library.
However, I wanted also to understand how some basic 3D vector operations work.
So,  these  two reasons led me to create the library.
The operations the library contains are the following:  add two vectors.
subtract two vectors.
multiple a vector with a scalar value.
divide a vector with a scalar value.
normalize a vector.
calculate the cross product of two vectors.
calculate the inner product of two vectors.
calculate the length of a vector.
calculate the opposite of a vector.
These were the vector operations that I needed for my programs.
Now, let me show you the header of the library: #ifndef _VECTOR_3F_H_ #define _VECTOR_3F_H_  class Vector3f {     private:         float x, y.

Z;      public:         Vector3f();          Vector3f(const float x

const float y, const float z);          float getX() const;          float getY() const;          float getZ() const;          void setX(const float value);          void setY(const float value);          void setZ(const float value);          void setValues(const float x, const float y, const float z);          Vector3f operator + (const Vector3f & vector) const;          Vector3f operator - (const Vector3f & vector) const;          Vector3f operator * (const float scale) const;          Vector3f operator / (const float scale) const;          Vector3f crossProduct(const Vector3f & vector) const;          float innerProduct(const Vector3f & vector) const;          float length() const;          Vector3f operator - () const;          void opposite ();          Vector3f normalized() const;          void normalize(); };  #endif // _VECTOR_3F_H_ Here is the implementation of the library: #include <cmath>  #include "Vector3f.h"  Vector3f::Vector3f() : Vector3f(0, 0, 0) { }  Vector3f::Vector3f(const float x, const float y, const float z) {     setValues(x, y, z); }  float Vector3f::getX() const {     return x; }  float Vector3f::getY() const {     return y; }  float Vector3f::getZ() const {     return z; }  void Vector3f::setX(const float value) {     x = value; }  void Vector3f::setY(const float value) {     y = value; }  void Vector3f::setZ(const float value) {     z = value; }  void Vector3f::setValues(const float x, const float y, const float z) {     setX(x);     setY(y);     setZ(z); }  Vector3f Vector3f::operator + (const Vector3f & vector) const {     return Vector3f(x + vector.getX(), y + vector.getY(), z + vector.getZ()); }  Vector3f Vector3f::operator - (const Vector3f & vector) const {     return Vector3f(x - vector.getX().
Rate this:.
Share this:.
Click to share on Facebook (Opens in new window).

Click to share on LinkedIn (Opens in new window)
Click to share on Twitter (Opens in new window)
Click to print (Opens in new window)
Click to email this to a friend (Opens in new window)

Like this:.
Like   Loading.
Related.
Tags: 3D vector, cross product, Euclidean distance, , inner product, library, normalize, , Pythagorean theorem, .

Vector math    Comments RSS feed                    Leave a Reply Cancel reply

Enter  your comment  here.
Fill in your details below or click an icon to  log in :.
Email  (Address never made public)                 Name                 Website                                                            You are commenting using your  WordPress.com  account.
( Log Out /     )                                                             You are commenting using your Google account.
( Log Out /     )                                                             You are commenting using your Twitter account.
( Log Out /     )                                                             You are commenting using  your Facebook  account.
( Log Out /     )                             Cancel   Connecting to %s             Notify me of new comments via email.
Notify me of new posts via email.

« Generic C++ template functions for reading from / writing to the Arduino EEPROM memory

Arduino: A library for implementing a generic, dynamic stack (array version).
».
(79).
(21).
(15).
(26).
(4).
(7).
(55).
(24).
(4).
(16).
(14).
(4).
(7).
(10).
(78).
(11).
(9).
(1).
July 2018      M  T  W  T  F  S  S           1      2345678      9101112131415      16171819202122      23242526272829      3031           « Jun     Sep ».
(2).
(4).
(1).
(1).
(2).
(1).
(1).
(1).
(2).
(1).
(9).
(1).
(8).
(1).
(1).
(2).
(4).
(7).
(1).
(1).
(1).
(8).
(12).
(1).
(2).
(1).
(2).
(1).
(2).
(1).
(1).
(4).
(20).
(13).
(5).
(2).
(10).
(13).
(10).
(10).
(20).
287,004 hits.
Send to  Email Address           Your Name       Your Email Address                              Cancel       Post was not sent - check your email addresses.
Email check failed.

Please try again          Sorry

your blog cannot share posts by email.
%d  bloggers like this:.

Offline

Board footer

Powered by FluxBB