Newer
Older
cg / hw04 / src / Vertex.h
// Copyright (c) 2021. Pascal Syma <pascal@syma.dev> and Antonio Martinez Casadesus <acasadesus@stud.hs-bremen.de>.
// All rights reserved.

//
// Created by Pascal on 17.05.2021.
//

#ifndef OPENGL_EXAMPLE_VERTEX_H
#define OPENGL_EXAMPLE_VERTEX_H

#include <iostream>
class Mesh;

using namespace std;

class Vertex {
public:

    float p[3]{}; // coordinates
    Mesh *mesh{};  // parent mesh
    int valence;

    /// Base-constructor
    Vertex();

    /// Base-constructor with parent mesh.
    /// \param mesh Parent mesh
    explicit Vertex(Mesh *mesh);

    /// Create new Vertex with three coordinates.
    /// \param mesh Parent mesh
    /// \param point Array of coordinates (x, y, z)
    explicit Vertex(Mesh *mesh, float point[3]);

    /// Create new Vertex with three coordinates.
    /// \param mesh Parent mesh
    /// \param x X-Coordinate
    /// \param y Y-Coordinate
    /// \param z Z-Coordinate
    Vertex(Mesh *mesh, float x, float y, float z);

    void Print() {
        cout << valence << "x " << p[0] << " " << p[1] << " " << p[2] << endl;
    }

    /// Vector scaling. Component wise multiplication.
    /// \param a Scalar
    void operator*=(float a);

    /// Component wise addition.
    /// \param a Addend
    void operator+=(Vertex a);

    /// Deep-copy this vertex.
    /// \param mesh Parent mesh of the new vertex
    /// \return New vertex
    Vertex *copy(Mesh *mesh);

};

/// Vector addition.
/// \param a First addend
/// \param b Second addend
/// \return Sum
Vertex operator+(Vertex a, Vertex b);

/// Vector subtraction.
/// \param a Minuend
/// \param b Subtrahend
/// \return Difference
Vertex operator-(Vertex a, Vertex b);

/// Vector scaling. Component wise.
/// \param a Scalar
/// \param b Vertex
/// \return Product
Vertex operator*(float a, Vertex b);

/// Scalar product
/// \param a First vector
/// \param b Second vector
/// \return Scalar product
float operator*(Vertex a, Vertex b);

/// Cross product
/// \param a First vector
/// \param b Second vector
/// \return Cross product
Vertex operator%(Vertex a, Vertex b);

/// Check equality based on equal coordinates.
/// \param a First vertex
/// \param b Second vertex
/// \return True if both have the same coordinate values
bool operator==(Vertex a, Vertex b);


#endif //OPENGL_EXAMPLE_VERTEX_H