Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Anonymous

unregistriert

11

21.09.2005, 15:13

Ach ja und wieso sthet das denn so da???

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

// Verwendete Symbole vordefinieren

class tbMatrix;

// ******************************************************************

// Die 3D-Vektor-Klasse

class TRIBASE_API tbVector3
{
public:
    // Variablen

    union
    {
        struct
        {
            float x;    // Koordinaten

            float y;
            float z;
        };

        struct
        {
            float u;    // Texturkoordinaten

            float v;
            float w;
        };

        float       c[3];       // Array der Koordinaten

        D3DVECTOR   vD3DVector; // Vektor in Form eines Direct3D-Vektors

    };

    // Konstruktoren

    tbVector3()                                                                                     {}
    tbVector3(const tbVector3& v) : x(v.x), y(v.y), z(v.z)                                          {}
    tbVector3(const float f) : x(f), y(f), z(f)                                                     {}
    tbVector3(const float _x, const float _y, const float _z) : x(_x), y(_y), z(_z)                 {}
    tbVector3(const float* pfComponent) : x(pfComponent[0]), y(pfComponent[1]), z(pfComponent[2])   {}
    tbVector3(const D3DVECTOR& v) : vD3DVector(v)                                                   {}

    // Casting-Operatoren

    operator float* ()                  {return (float*)(c);}
    operator D3DVECTOR& ()              {return vD3DVector;}
    operator const D3DVECTOR& () const  {return vD3DVector;}

    // Zuweisungsoperatoren

    tbVector3& operator = (const tbVector3& v)  {x = v.x; y = v.y; z = v.z; return *this;}
    tbVector3& operator += (const tbVector3& v) {x += v.x; y += v.y; z += v.z; return *this;}
    tbVector3& operator -= (const tbVector3& v) {x -= v.x; y -= v.y; z -= v.z; return *this;}
    tbVector3& operator *= (const tbVector3& v) {x *= v.x; y *= v.y; z *= v.z; return *this;}
    tbVector3& operator *= (const float f)      {x *= f; y *= f; z *= f; return *this;}
    tbVector3& operator /= (const tbVector3& v) {x /= v.x; y /= v.y; z /= v.z; return *this;}
    tbVector3& operator /= (const float f)      {x /= f; y /= f; z /= f; return *this;}
};

// Arithmetische Operatoren

inline tbVector3 operator + (const tbVector3& a, const tbVector3& b)    {return tbVector3(a.x + b.x, a.y + b.y, a.z + b.z);}
inline tbVector3 operator - (const tbVector3& a, const tbVector3& b)    {return tbVector3(a.x - b.x, a.y - b.y, a.z - b.z);}
inline tbVector3 operator - (const tbVector3& v)                        {return tbVector3(-v.x, -v.y, -v.z);}
inline tbVector3 operator * (const tbVector3& a, const tbVector3& b)    {return tbVector3(a.x * b.x, a.y * b.y, a.z * b.z);}
inline tbVector3 operator * (const tbVector3& v, const float f)         {return tbVector3(v.x * f, v.y * f, v.z * f);}
inline tbVector3 operator * (const float f, const tbVector3& v)         {return tbVector3(v.x * f, v.y * f, v.z * f);}
inline tbVector3 operator / (const tbVector3& a, const tbVector3& b)    {return tbVector3(a.x / b.x, a.y / b.y, a.z / b.z);}
inline tbVector3 operator / (const tbVector3& v, const float f)         {return tbVector3(v.x / f, v.y / f, v.z / f);}

// Vergleichsoperatoren

inline bool operator == (const tbVector3& a, const tbVector3& b) {if(a.x != b.x) return false; if(a.y != b.y) return false; return a.z == b.z;}
inline bool operator != (const tbVector3& a, const tbVector3& b) {if(a.x != b.x) return true; if(a.y != b.y) return true; return a.z != b.z;}

// ******************************************************************

// Funktionen deklarieren

inline float        tbVector3Length(const tbVector3& v)                                                 {return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);}
inline float        tbVector3LengthSq(const tbVector3& v)                                               {return v.x * v.x + v.y * v.y + v.z * v.z;}
inline tbVector3    tbVector3Normalize(const tbVector3& v)                                              {return v / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);}
inline tbVector3    tbVector3NormalizeEx(const tbVector3& v)                                            {return v / (sqrtf(v.x * v.x + v.y * v.y + v.z * v.z) + 0.0001f);}
inline tbVector3    tbVector3Cross(const tbVector3& v1, const tbVector3& v2)                            {return tbVector3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);}
inline float        tbVector3Dot(const tbVector3& v1, const tbVector3& v2)                              {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;}
inline float        tbVector3Angle(const tbVector3& v1, const tbVector3& v2)                            {return acosf((v1.x * v2.x + v1.y * v2.y + v1.z * v2.z) / sqrtf((v1.x * v1.x + v1.y * v1.y + v1.z * v1.z) * (v2.x * v2.x + v2.y * v2.y + v2.z * v2.z)));}
inline tbVector3    tbVector3InterpolateCoords(const tbVector3& v1, const tbVector3& v2, const float p) {return v1 + p * (v2 - v1);}
inline tbVector3    tbVector3InterpolateNormal(const tbVector3& v1, const tbVector3& v2, const float p) {return tbVector3NormalizeEx(v1 + p * (v2 - v1));}
inline tbVector3    tbVector3Min(const tbVector3& v1, const tbVector3& v2)                              {return tbVector3(TB_MIN(v1.x, v2.x), TB_MIN(v1.y, v2.y), TB_MIN(v1.z, v2.z));}
inline tbVector3    tbVector3Max(const tbVector3& v1, const tbVector3& v2)                              {return tbVector3(TB_MAX(v1.x, v2.x), TB_MAX(v1.y, v2.y), TB_MAX(v1.z, v2.z));}
inline tbVector3    tbVector3Random()                                                                   {return tbVector3NormalizeEx(tbVector3(tbFloatRandom(-1.0f, 1.0f), tbFloatRandom(-1.0f, 1.0f), tbFloatRandom(-1.0f, 1.0f)));}

// ******************************************************************



????
arithmetische und vergleichsoperatoren SIND ausserhalb definiert!!! ;p }>

Nox

Supermoderator

Beiträge: 5 272

Beruf: Student

  • Private Nachricht senden

12

21.09.2005, 16:21

hmmm zum Vergleich meine Datei:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/********************************************************************
     _________        __    _____
    /\___  ___\      /\_\  /\  __\
    \/__/\ \__/ _  __\/_/_ \ \ \_\\   ____    _____      __
        \ \ \  /\`´__\ /\ \ \ \  __\ /\ __\_ /\  __\   /´__`\
         \ \ \ \ \ \/  \ \ \ \ \ \_\\\ \\_\ \\ \____\ /\  __/
          \ \_\ \ \_\   \ \_\ \ \____\\ \___\ \ \____\\ \____\
           \/_/  \/_/    \/_/  \/____/ \/__/   \/____/ \/____/

    tbVector3.h
    ===========
    Diese Datei ist Teil der TriBase-Engine.

    Zweck:
    Rechnen mit 3D-Vektoren

    Autor:
    David Scherfgen

********************************************************************/

// Verwendete Symbole vordefinieren

class tbMatrix;

// ******************************************************************

// Die 3D-Vektor-Klasse

class TRIBASE_API tbVector3
{
public:
    // Variablen

    union
    {
        struct
        {
            float x;    // Koordinaten

            float y;
            float z;
        };

        struct
        {
            float u;    // Texturkoordinaten

            float v;
            float w;
        };

        float       c[3];       // Array der Koordinaten

        D3DVECTOR   vD3DVector; // Vektor in Form eines Direct3D-Vektors

    };

    // Konstruktoren

    inline tbVector3()                                                                                      {}
    inline tbVector3(const float f) : x(f), y(f), z(f)                                                      {}
    inline tbVector3(const float _x, const float _y, const float _z) : x(_x), y(_y), z(_z)                  {}
    inline tbVector3(const float* pfComponent) : x(pfComponent[0]), y(pfComponent[1]), z(pfComponent[2])    {}
    inline tbVector3(const D3DVECTOR& v) : vD3DVector(v)                                                    {}

    // Casting-Operatoren

    inline operator float* ()       {return (float*)(c);}
    inline operator D3DVECTOR& ()   {return vD3DVector;}

    // Arithmetische Operatoren

    inline tbVector3 operator + (const tbVector3& v) const                  {return tbVector3(x + v.x, y + v.y, z + v.z);}
    inline tbVector3 operator - (const tbVector3& v) const                  {return tbVector3(x - v.x, y - v.y, z - v.z);}
    inline tbVector3 operator - () const                                    {return tbVector3(-x, -y, -z);}
    inline tbVector3 operator * (const tbVector3& v) const                  {return tbVector3(x * v.x, y * v.y, z * v.z);}
    inline tbVector3 operator * (const float f) const                       {return tbVector3(x * f, y * f, z * f);}
    inline tbVector3 operator / (const tbVector3& v) const                  {return tbVector3(x / v.x, y / v.y, z / v.z);}
    inline tbVector3 operator / (const float f) const                       {return tbVector3(x / f, y / f, z / f);}
    inline friend tbVector3 operator * (const float f, const tbVector3& v)  {return tbVector3(v.x * f, v.y * f, v.z * f);}

    // Zuweisungsoperatoren

    inline tbVector3 operator = (const tbVector3& v)    {x = v.x; y = v.y; z = v.z; return *this;}
    inline tbVector3 operator += (const tbVector3& v)   {x += v.x; y += v.y; z += v.z; return *this;}
    inline tbVector3 operator -= (const tbVector3& v)   {x -= v.x; y -= v.y; z -= v.z; return *this;}
    inline tbVector3 operator *= (const tbVector3& v)   {x *= v.x; y *= v.y; z *= v.z; return *this;}
    inline tbVector3 operator *= (const float f)        {x *= f; y *= f; z *= f; return *this;}
    inline tbVector3 operator /= (const tbVector3& v)   {x /= v.x; y /= v.y; z /= v.z; return *this;}
    inline tbVector3 operator /= (const float f)        {x /= f; y /= f; z /= f; return *this;}

    // Vergleichsoperatoren

    inline bool operator == (const tbVector3& v) const  {if(x != v.x) return false; if(y != v.y) return false; return z == v.z;}
    inline bool operator != (const tbVector3& v) const  {if(x != v.x) return true; if(y != v.y) return true; return z != v.z;}
};

// ******************************************************************

// Funktionen deklarieren

inline float        tbVector3Length(const tbVector3& v)                                                 {return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);}
inline float        tbVector3LengthSq(const tbVector3& v)                                               {return v.x * v.x + v.y * v.y + v.z * v.z;}
inline tbVector3    tbVector3Normalize(const tbVector3& v)                                              {return v / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);}
inline tbVector3    tbVector3NormalizeEx(const tbVector3& v)                                            {return v / (sqrtf(v.x * v.x + v.y * v.y + v.z * v.z) + 0.0001f);}
inline tbVector3    tbVector3Cross(const tbVector3& v1, const tbVector3& v2)                            {return tbVector3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);}
inline float        tbVector3Dot(const tbVector3& v1, const tbVector3& v2)                              {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;}
inline float        tbVector3Angle(const tbVector3& v1, const tbVector3& v2)                            {return acosf(tbVector3Dot(tbVector3NormalizeEx(v1), tbVector3NormalizeEx(v2)));}
inline tbVector3    tbVector3InterpolateCoords(const tbVector3& v1, const tbVector3& v2, const float p) {return v1 + p * (v2 - v1);}
inline tbVector3    tbVector3InterpolateNormal(const tbVector3& v1, const tbVector3& v2, const float p) {return tbVector3Normalize(v1 + p * (v2 - v1));}
inline tbVector3    tbVector3Min(const tbVector3& v1, const tbVector3& v2)                              {return tbVector3(TB_MIN(v1.x, v2.x), TB_MIN(v1.y, v2.y), TB_MIN(v1.z, v2.z));}
inline tbVector3    tbVector3Max(const tbVector3& v1, const tbVector3& v2)                              {return tbVector3(TB_MAX(v1.x, v2.x), TB_MAX(v1.y, v2.y), TB_MAX(v1.z, v2.z));}
inline tbVector3    tbVector3Random()                                                                   {return tbVector3NormalizeEx(tbVector3(tbFloatRandom(-1.0f, 1.0f), tbFloatRandom(-1.0f, 1.0f), tbFloatRandom(-1.0f, 1.0f)));}

// ******************************************************************

Da sind sie innerhalb ;p
PRO Lernkurs "Wie benutze ich eine Doku richtig"!
CONTRA lasst mal die anderen machen!
networklibbenc - Netzwerklibs im Vergleich | syncsys - Netzwerk lib (MMO-ready) | Schleichfahrt Remake | Firegalaxy | Sammelsurium rund um FPGA&Co.