lab 5 part 1 done
This commit is contained in:
@@ -35,28 +35,14 @@ Line::Line(int x0, int y0, int x1, int y1, uint32_t color){
|
||||
|
||||
Line::Line(const Line &from){
|
||||
this->color = from.color;
|
||||
this->coords = new Matrix(4,3);
|
||||
// for (int i = 0; i < 2; i++)
|
||||
// {
|
||||
// for (int j = 0; j < 2; j++)
|
||||
// {
|
||||
// // Needs a look
|
||||
// this->coords[i][j] = from.coords[i][j];
|
||||
// //(*coords)[i][j] = (*from.coords)[i][j];
|
||||
// }
|
||||
// }
|
||||
this->coords[0][0] = from.coords[0][0];
|
||||
this->coords[0][1] = from.coords[0][1];
|
||||
this->coords[0][2] = from.coords[0][2];
|
||||
|
||||
this->coords[1][0] = from.coords[1][0];
|
||||
this->coords[1][1] = from.coords[1][1];
|
||||
this->coords[1][2] = from.coords[1][2];
|
||||
|
||||
this->coords[2][0] = from.coords[2][0];
|
||||
this->coords[2][1] = from.coords[2][1];
|
||||
this->coords[2][2] = from.coords[2][2];
|
||||
|
||||
this->coords = new Matrix(3,3);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
(*coords)[i][j] = (*from.coords)[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Line::~Line(){
|
||||
@@ -73,7 +59,7 @@ Line &Line::operator=(const Line &rhs){
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
this->coords[i][j] = rhs.coords[i][j];
|
||||
(*coords)[i][j] = (*rhs.coords)[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +72,21 @@ void Line::draw(GraphicsContext *gc){
|
||||
(*coords)[1][0], (*coords)[1][1]);
|
||||
}
|
||||
|
||||
void Line::out(std::ostream& os) const{
|
||||
os << "-Line-" << endl;
|
||||
os << "Color: " << color << endl;
|
||||
|
||||
os << "Point 1 - X: " << (*coords)[0][0];
|
||||
os << " Y: " << (*coords)[0][1];
|
||||
os << " Z: " << (*coords)[0][2] << endl;
|
||||
|
||||
os << "Point 2 - X: " << (*coords)[1][0];
|
||||
os << " Y: " << (*coords)[1][1];
|
||||
os << " Z: " << (*coords)[1][2] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Shape* Line::clone(){
|
||||
return new Line(*this);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ class Line: public Shape{
|
||||
~Line();
|
||||
Line& operator=(const Line& rhs);
|
||||
void draw(GraphicsContext *gc);
|
||||
void out(std::ostream& os) const;
|
||||
Shape* clone();
|
||||
};
|
||||
|
||||
|
||||
@@ -23,13 +23,12 @@ int main(void)
|
||||
Shape* T1 = new Triangle(250, 100, 50, 320, 125, 200, GraphicsContext::RED);
|
||||
Shape* L2 = L1->clone();
|
||||
Shape* T2 = T1->clone();
|
||||
Shape* L3(L1);
|
||||
Shape* T3(T1);
|
||||
delete L1;
|
||||
delete T1;
|
||||
(*L3).draw(gc);
|
||||
(*T3).draw(gc);
|
||||
|
||||
(*L2).draw(gc);
|
||||
(*T2).draw(gc);
|
||||
(*L2).out(cout);
|
||||
(*T2).out(cout);
|
||||
|
||||
sleep(5);
|
||||
|
||||
|
||||
@@ -13,17 +13,10 @@
|
||||
Shape::Shape(){
|
||||
this->color = (uint32_t) 0x00FFFFFF;
|
||||
}
|
||||
Shape::Shape(const Shape& from){
|
||||
this->color = from.color;
|
||||
this->coords = from.coords;
|
||||
}
|
||||
Shape::Shape(const Shape& from){};
|
||||
|
||||
Shape::~Shape(){};
|
||||
|
||||
void Shape::draw(GraphicsContext *gc){}
|
||||
|
||||
void Shape::out(std::ostream& os, const Shape& rhs){}
|
||||
|
||||
Shape& Shape::operator=(const Shape& rhs){
|
||||
return *this;
|
||||
}
|
||||
|
||||
16
Lab5/shape.h
16
Lab5/shape.h
@@ -1,5 +1,15 @@
|
||||
#ifndef shape_h
|
||||
#define shape_h
|
||||
/**
|
||||
* @file shape.h
|
||||
* @author Trevor Barnes (barnestr@msoe.edu)
|
||||
* @brief
|
||||
* @version 1.0
|
||||
* @date 2022-04-12
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "x11context.h"
|
||||
#include "matrix.h"
|
||||
@@ -15,9 +25,9 @@ class Shape{
|
||||
// Destructor
|
||||
virtual ~Shape();
|
||||
// Draw shape
|
||||
virtual void draw(GraphicsContext *gc);
|
||||
virtual void draw(GraphicsContext *gc) = 0;
|
||||
// Print to output stream
|
||||
virtual void out(std::ostream& os, const Shape& rhs);
|
||||
virtual void out(std::ostream& os)const = 0;
|
||||
// Virtual Constructor
|
||||
virtual Shape* clone() = 0; // Pure virtual "=0"
|
||||
protected:
|
||||
@@ -26,7 +36,7 @@ class Shape{
|
||||
// RGB color
|
||||
uint32_t color;
|
||||
// Assignment Operator
|
||||
Shape& operator=(const Shape& rhs);
|
||||
virtual Shape& operator=(const Shape& rhs);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -68,6 +68,26 @@ Triangle& Triangle::operator=(const Triangle& rhs){
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Triangle::out(std::ostream& os) const{
|
||||
os << "-Triangle-" << endl;
|
||||
os << "Color: " << color << endl;
|
||||
|
||||
os << "Point 1 - X: " << (*coords)[0][0];
|
||||
os << " Y: " << (*coords)[0][1];
|
||||
os << " Z: " << (*coords)[0][2] << endl;
|
||||
|
||||
|
||||
os << "Point 2 - X: " << (*coords)[1][0];
|
||||
os << " Y: " << (*coords)[1][1];
|
||||
os << " Z: " << (*coords)[1][2] << endl;
|
||||
|
||||
|
||||
os << "Point 3 - X: " << (*coords)[2][0];
|
||||
os << " Y: " << (*coords)[2][1];
|
||||
os << " Z: " << (*coords)[2][2] << endl;
|
||||
}
|
||||
|
||||
|
||||
Shape* Triangle::clone(){
|
||||
return new Triangle(*this);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class Triangle: public Shape{
|
||||
~Triangle();
|
||||
Triangle& operator=(const Triangle& rhs);
|
||||
void draw(GraphicsContext *gc);
|
||||
void out(std::ostream& os) const;
|
||||
Shape* clone();
|
||||
private:
|
||||
Matrix * coords;
|
||||
|
||||
Reference in New Issue
Block a user