# 2 questions. About the warnings n how to declare rAngle

Page 1 of 1

## 1 Replies - 620 Views - Last Post: 11 February 2012 - 05:07 PMRate Topic: 2 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=266207&amp;s=8b46de0811fbaffed619fe8e41669788&md5check=' + ipb.vars['secure_hash'], cur_rating: 3, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Dooberz09

Reputation: 0
• Posts: 1
• Joined: 10-February 12

# 2 questions. About the warnings n how to declare rAngle

Posted 10 February 2012 - 12:13 PM

Ok im a beginner at prgramming and our teacher gave us this program to modify.

HEre are the instructions.
[b]To do this rotation, you will need to create a rotation matrix, similar to the makeTranslationMatrix() in the source code. The rotation matrix will accept one argument, the rotation angle (in radians). The lecture for this week explains what the rotation matrix does. The matrix multiplication function, called Multiply, can be reused to rotate the center.

Note that in DrawStuff() the declaration
Matrix3 m;
to store the translation matrix. You will need a similar declaration to store your rotation matrix.

The command
m.makeTranslationMatrix(translation.x, translation.y);
sets matrix m to the necessary translation matrix. You will need a similar command to set the rotation matrix.

The command
newCircleCenter = Multiply(m, circleCenter);
transforms the circle center: newCircleCenter = m x circleCenter
Finally, you will then need the Multiply function again to multiply your rotation matrix with circleCenter to rotate the center of the circle.

I add all the extra code but im not sure of how or where to initialize the rAngle.
Also when i uploaded the program it already had four conversion errors that i tried to find a fix but couldnt find where they were.

Here is the code

```/*
translation.cpp

translates a circle in 2D using matrix multiply
*/
#define _USE_MATH_DEFINES

#include <math.h>
#include <stdio.h>
#include <windows.h>

#include "resource.h"

// your path for this include may vary
#include "GraphicsFramework.h"

// Global variable to store the graphics framwork object
GraphicsFramework* PGraphics;

HWND HOutput = 0;  // handle to the output control
HWND HDialog = 0;

const double PI = 3.1415927;

// 2d point or vector
struct Vector2 {
double x, y;        // x, y coordinate
double w;           // homogeneous coordinate, usually = 1

// default constructor set to <0, 0, 1>
Vector2() {
x = 0.0;
y = 0.0;
w = 1.0;
}
};

// 2d matrix 3x3
struct Matrix3 {
double m[3][3];     // 3x3 matrix values
double r[3][3];

// default constructor - initialize matrix to identity
Matrix3() {
m[0][0] = 1.0;  m[0][1] = 0.0;  m[0][2] = 0.0;
m[1][0] = 0.0;  m[1][1] = 1.0;  m[1][2] = 0.0;
m[2][0] = 0.0;  m[2][1] = 0.0;  m[2][2] = 1.0;
}

// make a 2D translation matrix
void makeTranslationMatrix(double dx, double dy) {
m[0][0] = 1.0;  m[0][1] = 0.0;  m[0][2] = dx;
m[1][0] = 0.0;  m[1][1] = 1.0;  m[1][2] = dy;
m[2][0] = 0.0;  m[2][1] = 0.0;  m[2][2] = 1.0;
}

// make a 2D rotation matrix

double rAngle;
void makeRotationMatrix( double dx, double dy){
r[0][0] = cos(rAngle);	r[0][1] = -1 *sin(rAngle);	r[0][2] = 0.0;
r[1][0] = sin(rAngle);	r[1][1] =     cos(rAngle);	r[1][2] = 0.0;
r[2][0] = 0.0;			r[2][1] = 0.0;				r[2][2] = 1.0;
}

};
// mulitplies matrix m by vector v, returns result = m x v
Vector2 Multiply(Matrix3 m, Vector2 v) {
Vector2 result;

result.x = m.m[0][0] * v.x + m.m[0][1] * v.y + m.m[0][2] * v.w;
result.y = m.m[1][0] * v.x + m.m[1][1] * v.y + m.m[1][2] * v.w;
result.w = m.m[2][0] * v.x + m.m[2][1] * v.y + m.m[2][2] * v.w;

return result;
}

void Circle(int xCenter, int yCenter, int r, unsigned int color) {
double d;
int rSquared;
int x, y;

rSquared = r * r;

x = 0;
y = r;

d = rSquared - ((x + 1) * (x + 1) + (y - 0.5) * (y - 0.5));

while (y >= x) {
PGraphics->AddPoint(xCenter + x, yCenter + y, color);
PGraphics->AddPoint(xCenter - x, yCenter + y, color);
PGraphics->AddPoint(xCenter + x, yCenter - y, color);
PGraphics->AddPoint(xCenter - x, yCenter - y, color);
PGraphics->AddPoint(xCenter + y, yCenter + x, color);
PGraphics->AddPoint(xCenter - y, yCenter + x, color);
PGraphics->AddPoint(xCenter + y, yCenter - x, color);
PGraphics->AddPoint(xCenter - y, yCenter - x, color);
if (d > 0) {
}
else {
y--;
}
x++;
d = rSquared - ((x + 1) * (x + 1) + (y - 0.5) * (y - 0.5));
}
}

void DrawStuff() {
COLORREF green = RGB(0, 255, 0);    // green color to draw with
COLORREF purple = RGB(255, 0, 255); // purple color to draw with
Vector2 circleCenter;               // center of circle
Vector2 translation;                // translation amount

Matrix3 m;                          // matrix to store the translation
Matrix3 r;							// matrix to store the rotation
Vector2 newCircleCenter;            // translated circle center

char str[32];                       // string to store user input

// clear the scene and add an axis
PGraphics->ClearScene(RGB(0, 0, 0));

// get the user input from the edit boxes and
// convert string input to double
GetDlgItemText(HDialog, IDC_EDIT_CIRCLEX, str, 32);
circleCenter.x = atof(str);
GetDlgItemText(HDialog, IDC_EDIT_CIRCLEY, str, 32);
circleCenter.y = atof(str);
GetDlgItemText(HDialog, IDC_EDIT_TRANSLATIONX, str, 32);
translation.x = atof(str);
GetDlgItemText(HDialog, IDC_EDIT_TRANSLATIONY, str, 32);
translation.y = atof(str);

// set matrix m to the necessary translation matrix
m.makeTranslationMatrix(translation.x, translation.y);

// set matrix r to the necessary roatation matrix
r.makeRotationMatrix(rAngle);

// transform the circle center  newCircleCenter = m x circleCenter
newCircleCenter = Multiply(m, circleCenter);

//rotate the circle center newCircleCenter = r x circleCenter
newCircleCenter = Multiply(r, circleCenter);

// draw the original and transformed circles

// draw the points
PGraphics->Draw();
}

/*
DialogProc
this is the window event handler for the main dialog
*/
BOOL CALLBACK DialogProc (HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
// dialog is initializing - store the picture box handle in a global variable for later
HOutput = GetDlgItem(hwnd, IDC_PICTURE_OUTPUT);

// instantiate and initialize our graphics framework object
PGraphics = new GraphicsFramework(HOutput);

break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_DRAW:
// draw button was pressed
DrawStuff();
break;
case IDC_BTN_CLEAR:
// clear button was pressed so clear the scene and draw the empty scene
PGraphics->ClearScene(RGB(0, 0, 0));
PGraphics->Draw();
break;
case IDCANCEL:
// user is quitting so release the GraphicsFramework object and quit
delete PGraphics;
PostQuitMessage(0);
break;
}

}
return FALSE;
}

// this is the main function that starts the application
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
// create the main window
// store its handle in a global if needed
HDialog = CreateDialog (GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DIALOG1),
0,
DialogProc);

// make the dialog visible
ShowWindow(HDialog, SW_SHOW);

// standard windows message loop
MSG  msg;
int status;
while ((status = GetMessage (&msg, 0, 0, 0)) != 0)
{
if (status == -1)
return -1;
// avoid processing messages for the dialog
if (!IsDialogMessage (HDialog, & msg))
{
TranslateMessage ( & msg );
DispatchMessage ( & msg );
}
}

return (int)(msg.wParam);
}

```

Is This A Good Question/Topic? 0

## Replies To: 2 questions. About the warnings n how to declare rAngle

### #2 anonymous26

• D.I.C Lover

Reputation: 1
• Posts: 3,638
• Joined: 26-November 10

## Re: 2 questions. About the warnings n how to declare rAngle

Posted 11 February 2012 - 05:07 PM

What have you tried in order to declare rAngle? The type of the single parameter to makeRotationMatrix() should give you a big clue!