progress at term deadline
This commit is contained in:
@@ -17,12 +17,47 @@
|
||||
#include "mydrawing.h"
|
||||
using namespace std;
|
||||
|
||||
Image boatScene;
|
||||
|
||||
void buildBoat(){
|
||||
|
||||
cout << "Build Boat" << endl;
|
||||
|
||||
// Boat
|
||||
boatScene.add(new Line(250,500,550,500,GraphicsContext::YELLOW));
|
||||
boatScene.add(new Line(250,500,150,400,GraphicsContext::YELLOW));
|
||||
boatScene.add(new Line(150,400,650,400,GraphicsContext::YELLOW));
|
||||
boatScene.add(new Line(650,400,550,500,GraphicsContext::YELLOW));
|
||||
boatScene.add(new Line(400,400,400,100,GraphicsContext::YELLOW));
|
||||
|
||||
// Sail
|
||||
boatScene.add(new Triangle(400,100,300,150,400,200,GraphicsContext::YELLOW));
|
||||
|
||||
// Waves
|
||||
boatScene.add(new Line(0,550,100,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(100,450,100,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(100,550,200,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(200,450,200,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(200,550,300,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(300,450,300,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(300,550,400,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(400,450,400,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(400,550,500,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(500,450,500,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(500,550,600,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(600,450,600,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(600,550,700,450,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(700,450,700,550,GraphicsContext::BLUE));
|
||||
boatScene.add(new Line(700,550,800,450,GraphicsContext::BLUE));
|
||||
}
|
||||
|
||||
int main(void){
|
||||
|
||||
GraphicsContext* gc = new X11Context(800,600,GraphicsContext::BLACK);
|
||||
gc->setColor(GraphicsContext::GREEN);
|
||||
|
||||
MyDrawing md;
|
||||
md.paint(gc);
|
||||
|
||||
gc->runLoop(&md);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "mydrawing.h"
|
||||
//#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
MyDrawing::MyDrawing()
|
||||
@@ -124,3 +123,4 @@ void setLargePixel(GraphicsContext *gc, int x, int y)
|
||||
gc->setPixel(x - 1, y - 1);
|
||||
gc->setPixel(x, y - 1);
|
||||
gc->setPixel(x + 1, y - 1);
|
||||
}
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "drawbase.h"
|
||||
#include "gcontext.h"
|
||||
#include "image.h"
|
||||
#include "matrix.h"
|
||||
using namespace std;
|
||||
|
||||
class MyDrawing: public DrawingBase{
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#include <iostream>
|
||||
#include "x11context.h"
|
||||
#include "matrix.h"
|
||||
#include "mydrawing.h"
|
||||
//#include "viewcontext.h"
|
||||
#include "viewcontext.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -1,11 +1,72 @@
|
||||
// - ViewContext Class -
|
||||
|
||||
#include <cmath>
|
||||
#include "viewcontext.h"
|
||||
|
||||
ViewContext::ViewContext(){
|
||||
compMatrix = new Matrix(3,3);
|
||||
ViewContext::ViewContext(int width, int height){
|
||||
compMatrix = new Matrix(4,4);
|
||||
prevTransform = new Matrix(4,4);
|
||||
}
|
||||
|
||||
void ViewContext::model_to_device(){
|
||||
void ViewContext::model_to_device(Matrix* coord){
|
||||
(*coord) = (*compMatrix)*(*coord);
|
||||
}
|
||||
|
||||
void ViewContext::rotate(int deg){
|
||||
// Store previous transform
|
||||
*prevTransform = *compMatrix;
|
||||
Matrix temp = Matrix::identity(4);
|
||||
// Input transformation
|
||||
temp[0][0] = cos(deg*M_PI/180);
|
||||
temp[0][1] = sin(deg*M_PI/180);
|
||||
temp[1][0] = -sin(deg*M_PI/180);
|
||||
temp[1][0] = cos(deg*M_PI/180);
|
||||
// Add transformation to comp matrix
|
||||
*compMatrix = temp*(*compMatrix);
|
||||
}
|
||||
|
||||
// Scaling - Around center of screen
|
||||
void ViewContext::scale(int mult){
|
||||
// Store previous transform
|
||||
*prevTransform = *compMatrix;
|
||||
// Create identity matrix
|
||||
Matrix temp = Matrix::identity(4);
|
||||
// Input transformation
|
||||
temp[0][0] = mult;
|
||||
temp[1][1] = mult;
|
||||
temp[2][2] = mult;
|
||||
// Add transformation to comp matrix
|
||||
*compMatrix = temp*(*compMatrix);
|
||||
}
|
||||
|
||||
// Translation
|
||||
void ViewContext::translate(int dx, int dy, int dz){
|
||||
// Store previous transform
|
||||
*prevTransform = *compMatrix;
|
||||
Matrix temp = Matrix::identity(4);
|
||||
// Input transformation
|
||||
temp[0][3] = dx;
|
||||
temp[1][3] = dy;
|
||||
temp[2][3] = dz;
|
||||
// Add transformation to comp matrix
|
||||
*compMatrix = temp*(*compMatrix);
|
||||
}
|
||||
// Reset
|
||||
void ViewContext::reset(){
|
||||
*compMatrix = (Matrix::identity(4))*(*compMatrix);
|
||||
}
|
||||
|
||||
// Undo
|
||||
void ViewContext::undo(Matrix* coord){
|
||||
// Use temp to store current trans
|
||||
Matrix temp = Matrix::identity(4);
|
||||
|
||||
(*coord) = (*prevTransform)*(*coord);
|
||||
*prevTransform = temp;
|
||||
|
||||
}
|
||||
|
||||
// Invert Colors
|
||||
// void ViewContext::invert(){
|
||||
|
||||
// }
|
||||
@@ -5,15 +5,41 @@
|
||||
|
||||
|
||||
class ViewContext{
|
||||
ViewContext();
|
||||
void model_to_device();
|
||||
public:
|
||||
// Contructor - takes in current window width and height to account for origin
|
||||
ViewContext(int width, int height);
|
||||
// Destructor
|
||||
~ViewContext();
|
||||
|
||||
void model_to_device(Matrix* coord);
|
||||
// Rotation - Around center of screen
|
||||
void rotate(int deg);
|
||||
|
||||
// Scaling - Around center of screen
|
||||
void scale(int mult);
|
||||
|
||||
// Translation
|
||||
void translate(int dx, int dy, int dz);
|
||||
|
||||
// Reset
|
||||
void reset();
|
||||
|
||||
// Undo previous transform
|
||||
void undo(Matrix* coord);
|
||||
|
||||
// Invert Colors
|
||||
//void invert();
|
||||
|
||||
private:
|
||||
// Window pixel width
|
||||
int width;
|
||||
// Window pixel height
|
||||
int height;
|
||||
// Matrix containing the composite of all current transformations
|
||||
Matrix* compMatrix;
|
||||
// Matrix containing the previous transformation
|
||||
Matrix* prevTransform;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user