Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

c++ rotate 2D shape

$
0
0
Hay everyone

This is going to be a really basic concept but I am struggling with this immensely and am finding my self getting more and more confused as time goes on so any help with this would be a god send.

Basically I have a list which takes vertices for a shape, print out shape to the screen, such as a triangle and am trying to then implement a function which will rotate the triangle by a give input e.g 20 degrees. I have look over formulas and translating to the origin, perform the rotation and then move back to the centeroid but I an struggling to implement all this, I struggling to to see what the code is doing. Any help would be great thanks.



I have attached some .cpp and header files to the post for anyone to review, thanks. I have renamed the extensions as .txt to allow me to attach them. Had to put main in as code due to upload limit.

Code:

#pragma once

#include "vertex.h"
#include "shape.h"
#include "rhombus.h"
#include "pentagon.h"
#include "triangle.h"
#include "console.h"
#include "shape.h"
#include <iostream>
#include <list>
#include <cmath>

using namespace std;

int main()
{
        list<Shape*> shapes;

        shapes.push_back(new Triangle(Vertex(15, 10),8));


        list<Shape*>::iterator itr = shapes.begin();

        while (itr != shapes.end())
        {
                (*itr)->drawShape();
                // rotate shape by 20 degrees
                itr++;
        }
        Console::gotoXY(0,0);
        system("pause");
        return true;
}


console.h.txtconsole.txtshape.cpp.txtshape.h.txttriangle.cpp.txttriangle.h.txt
Attached Files

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images