From 342403a02f8063903d0f38327430721d4d0ae331 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 20 Sep 2021 18:15:14 -0500 Subject: do ass1 --- dev/MinGfx/src/color.cc | 260 ++++++++++++++++++++++++------------------------ 1 file changed, 130 insertions(+), 130 deletions(-) (limited to 'dev/MinGfx/src/color.cc') diff --git a/dev/MinGfx/src/color.cc b/dev/MinGfx/src/color.cc index cc5db87..50d8e83 100644 --- a/dev/MinGfx/src/color.cc +++ b/dev/MinGfx/src/color.cc @@ -1,130 +1,130 @@ -/* - Copyright (c) 2017,2018 Regents of the University of Minnesota. - All Rights Reserved. - See corresponding header file for details. - */ - -#include "color.h" - -#include - -namespace mingfx { - -Color::Color() { - c[0] = 0.0; - c[1] = 0.0; - c[2] = 0.0; - c[3] = 1.0; -} - -Color::Color(float red, float green, float blue, float alpha) { - c[0] = red; - c[1] = green; - c[2] = blue; - c[3] = alpha; -} - -Color::Color(float *ptr) { - c[0] = ptr[0]; - c[1] = ptr[1]; - c[2] = ptr[2]; - c[3] = ptr[3]; -} - -Color::Color(const Color& other) { - c[0] = other[0]; - c[1] = other[1]; - c[2] = other[2]; - c[3] = other[3]; -} - -Color::Color(const std::vector &vals) { - c[0] = vals[0]; - c[1] = vals[1]; - c[2] = vals[2]; - if (vals.size() > 3) { - c[3] = vals[3]; - } - else { - c[3] = 1.0; - } -} - - -Color::~Color() { -} - -bool Color::operator==(const Color& other) const { - return ((other[0] == c[0]) && - (other[1] == c[1]) && - (other[2] == c[2]) && - (other[3] == c[3])); -} - -bool Color::operator!=(const Color& other) const { - return ((other[0] != c[0]) || - (other[1] != c[1]) || - (other[2] != c[2]) || - (other[3] != c[3])); -} - -Color& Color::operator=(const Color& other) { - c[0] = other[0]; - c[1] = other[1]; - c[2] = other[2]; - c[3] = other[3]; - return *this; -} - -float Color::operator[](const int i) const { - return c[i]; -} - -float& Color::operator[](const int i) { - return c[i]; -} - - -const float * Color::value_ptr() const { - return c; -} - -std::vector Color::ToVector() const { - std::vector v; - v.push_back(c[0]); - v.push_back(c[1]); - v.push_back(c[2]); - v.push_back(c[3]); - return v; -} - - -Color Color::Lerp(const Color &b, float alpha) const { - float red = (1.0f-alpha)*(*this)[0] + alpha*b[0]; - float grn = (1.0f-alpha)*(*this)[1] + alpha*b[1]; - float blu = (1.0f-alpha)*(*this)[2] + alpha*b[2]; - float alp = (1.0f-alpha)*(*this)[3] + alpha*b[3]; - return Color(red,grn,blu,alp); -} - -Color Color::Lerp(const Color &a, const Color &b, float alpha) { - float red = (1.0f-alpha)*a[0] + alpha*b[0]; - float grn = (1.0f-alpha)*a[1] + alpha*b[1]; - float blu = (1.0f-alpha)*a[2] + alpha*b[2]; - float alp = (1.0f-alpha)*a[3] + alpha*b[3]; - return Color(red,grn,blu,alp); -} - - -std::ostream & operator<< ( std::ostream &os, const Color &c) { - return os << "(" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << ")"; -} - -std::istream & operator>> ( std::istream &is, Color &c) { - // format: (r, g, b, a) - char dummy; - return is >> dummy >> c[0] >> dummy >> c[1] >> dummy >> c[2] >> dummy >> c[3] >> dummy; -} - - -} // end namespace +/* + Copyright (c) 2017,2018 Regents of the University of Minnesota. + All Rights Reserved. + See corresponding header file for details. + */ + +#include "color.h" + +#include + +namespace mingfx { + +Color::Color() { + c[0] = 0.0; + c[1] = 0.0; + c[2] = 0.0; + c[3] = 1.0; +} + +Color::Color(float red, float green, float blue, float alpha) { + c[0] = red; + c[1] = green; + c[2] = blue; + c[3] = alpha; +} + +Color::Color(float *ptr) { + c[0] = ptr[0]; + c[1] = ptr[1]; + c[2] = ptr[2]; + c[3] = ptr[3]; +} + +Color::Color(const Color& other) { + c[0] = other[0]; + c[1] = other[1]; + c[2] = other[2]; + c[3] = other[3]; +} + +Color::Color(const std::vector &vals) { + c[0] = vals[0]; + c[1] = vals[1]; + c[2] = vals[2]; + if (vals.size() > 3) { + c[3] = vals[3]; + } + else { + c[3] = 1.0; + } +} + + +Color::~Color() { +} + +bool Color::operator==(const Color& other) const { + return ((other[0] == c[0]) && + (other[1] == c[1]) && + (other[2] == c[2]) && + (other[3] == c[3])); +} + +bool Color::operator!=(const Color& other) const { + return ((other[0] != c[0]) || + (other[1] != c[1]) || + (other[2] != c[2]) || + (other[3] != c[3])); +} + +Color& Color::operator=(const Color& other) { + c[0] = other[0]; + c[1] = other[1]; + c[2] = other[2]; + c[3] = other[3]; + return *this; +} + +float Color::operator[](const int i) const { + return c[i]; +} + +float& Color::operator[](const int i) { + return c[i]; +} + + +const float * Color::value_ptr() const { + return c; +} + +std::vector Color::ToVector() const { + std::vector v; + v.push_back(c[0]); + v.push_back(c[1]); + v.push_back(c[2]); + v.push_back(c[3]); + return v; +} + + +Color Color::Lerp(const Color &b, float alpha) const { + float red = (1.0f-alpha)*(*this)[0] + alpha*b[0]; + float grn = (1.0f-alpha)*(*this)[1] + alpha*b[1]; + float blu = (1.0f-alpha)*(*this)[2] + alpha*b[2]; + float alp = (1.0f-alpha)*(*this)[3] + alpha*b[3]; + return Color(red,grn,blu,alp); +} + +Color Color::Lerp(const Color &a, const Color &b, float alpha) { + float red = (1.0f-alpha)*a[0] + alpha*b[0]; + float grn = (1.0f-alpha)*a[1] + alpha*b[1]; + float blu = (1.0f-alpha)*a[2] + alpha*b[2]; + float alp = (1.0f-alpha)*a[3] + alpha*b[3]; + return Color(red,grn,blu,alp); +} + + +std::ostream & operator<< ( std::ostream &os, const Color &c) { + return os << "(" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << ")"; +} + +std::istream & operator>> ( std::istream &is, Color &c) { + // format: (r, g, b, a) + char dummy; + return is >> dummy >> c[0] >> dummy >> c[1] >> dummy >> c[2] >> dummy >> c[3] >> dummy; +} + + +} // end namespace -- cgit v1.2.3