Commit f93785b6 by Philipp Adolf

Add Triangle class

parent 3ac32607
......@@ -21,7 +21,8 @@ SOURCES += main.cpp\
texture.cpp \
camera.cpp \
subdivision.cpp \
vertex.cpp
vertex.cpp \
triangle.cpp
HEADERS += mainwindow.h \
mainwidget.h \
......@@ -29,7 +30,8 @@ HEADERS += mainwindow.h \
texture.h \
camera.h \
subdivision.h \
vertex.h
vertex.h \
triangle.h
FORMS +=
......
#include <QDebugStateSaver>
#include "triangle.h"
Triangle::Triangle() {}
Triangle::Triangle(const Triangle &other) {
this->vertex_buffer_ = other.vertex_buffer_;
this->u_ = other.u_;
this->v_ = other.v_;
this->w_ = other.w_;
}
Triangle::Triangle(const QVector<Vertex> &vertex_buffer, int u, int v, int w) {
this->vertex_buffer_ = vertex_buffer;
this->u_ = u;
this->v_ = v;
this->w_ = w;
}
Vertex Triangle::u() const {
return vertex_buffer_[u_];
}
Vertex Triangle::v() const {
return vertex_buffer_[v_];
}
Vertex Triangle::w() const {
return vertex_buffer_[w_];
}
int Triangle::u_idx() const {
return u_;
}
int Triangle::v_idx() const {
return v_;
}
int Triangle::w_idx() const {
return w_;
}
Triangle &Triangle::operator=(const Triangle &other) {
this->vertex_buffer_ = other.vertex_buffer_;
this->u_ = other.u_;
this->v_ = other.v_;
this->w_ = other.w_;
return *this;
}
QDebug operator<<(QDebug d, const Triangle &triangle) {
QDebugStateSaver saver(d);
d.nospace() << "Triangle(" << triangle.u_idx() << ", " << triangle.v_idx() << ", " << triangle.w_idx() << "; " << triangle.u().pos << ", " << triangle.v().pos << ", " << triangle.w().pos << ")";
return d;
}
#pragma once
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include <QDebug>
#include <QVector>
#include "vertex.h"
class Triangle {
public:
Triangle();
Triangle(const Triangle &other);
Triangle(const QVector<Vertex> &vertex_buffer, int u, int v, int w);
Vertex u() const;
Vertex v() const;
Vertex w() const;
int u_idx() const;
int v_idx() const;
int w_idx() const;
Triangle &operator=(const Triangle &other);
private:
QVector<Vertex> vertex_buffer_;
int u_;
int v_;
int w_;
};
QDebug operator<<(QDebug d, const Triangle &triangle);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment