Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "stdafx.h"
- #include "Transform.h"
- #include <math.h>
- mat T;
- void times(mat a, mat b, mat c)
- {
- for (int i = 0; i < M; i++)
- {
- for (int j = 0; j < M; j++)
- {
- float skalaar = 0;
- for (int k = 0; k < M; k++)
- skalaar += a[i][k] * b[k][j];
- c[i][j] = skalaar;
- }
- }
- }
- void timesMatVec(mat a, vec b, vec c)
- {
- for (int i = 0; i < M; i++)
- {
- float skalaar = 0;
- for (int j = 0; j < M; j++)
- skalaar += a[i][j] * b[j];
- c[i] = skalaar;
- }
- }
- void set(mat a, mat b)
- {
- for (int i = 0; i < M; i++)
- for (int j = 0; j < M; j++)
- b[i][j] = a[i][j];
- }
- void point2vec(point a, vec b)
- {
- b[0] = a.x; b[1] = a.y; b[2] = 1;
- }
- void vec2point(vec a, point &b)
- {
- b.x = ((float)a[0]) / a[2];
- b.y = ((float)a[1]) / a[2];
- }
- void makeHomogenVec(float x, float y, vec c)
- {
- c[0] = x; c[1] = y; c[2] = 1;
- }
- void unit(mat a)
- {
- for (int i = 0; i < M; i++)
- {
- for (int j = 0; j < M; j++)
- {
- if (i == j) a[i][j] = 1;
- else a[i][j] = 0;
- }
- }
- }
- void move(float Tx, float Ty, mat c)
- {
- unit(c);
- c[0][M - 1] = Tx;
- c[1][M - 1] = Ty;
- }
- void scale(float S, mat c)
- {
- unit(c);
- c[0][0] = S; c[1][1] = S;
- }
- void rotate(float phi, mat c)
- {
- unit(c);
- c[0][0] = cos(phi); c[0][1] = -sin(phi);
- c[1][0] = sin(phi); c[1][1] = cos(phi);
- }
- void rotate_2(float w, float h, float phi, mat c)
- {
- unit(c);
- c[0][0] = cos(phi); c[0][1] = -sin(phi); c[0][2] = -w/2*(cos(phi)-1) + h/2*sin(phi);
- c[1][0] = sin(phi); c[1][1] = cos(phi) ; c[1][2] = -h/2*(cos(phi)-1) - w/2*sin(phi);
- c[2][0] = 0; c[2][1] = 0; c[2][2] = 1;
- }
- void mirror1(float w, mat c)
- {
- unit(c);
- c[0][0] = -1; c[1][1] = 1; c[0][2] = w;
- }
- void mirror2(float h, mat c)
- {
- unit(c);
- c[0][0] = 1; c[1][1] = -1; c[1][2] = h;
- }
- void scale_2(float S, float n, float m, mat c)
- {
- unit(c);
- c[0][0] = S; c[0][1] = 0; c[0][2] = (1 - S)*m;
- c[1][0] = 0; c[1][1] = S; c[1][2] = (1 - S)*n;
- c[2][0] = 0; c[2][1] = 0; c[2][2] = 1;
- }
- void sdvig_g(float S,float w, mat c)
- {
- unit (c);
- c[0][0] = S; c[0][1] =0 ; c[0][2]=(1 - S)*w;
- c[1][0] =0 ; c[1][1] =S ; c[1][2]=1;
- c[2][0] =0 ; c[2][1] =0 ; c[2][2]=1;
- }
- void sdvig_v(float S,float h, mat c)
- {
- unit (c);
- c[0][0] = S; c[0][1] =0 ; c[0][2]=1;
- c[1][0] =0 ; c[1][1] =S ; c[1][2]=(1 - S)*h;
- c[2][0] =0 ; c[2][1] =0 ; c[2][2]=1;
- }
- void scale_3(float x, float y, float Sx, float Sy, mat c)
- {
- unit(c);
- c[0][0] = Sx;
- c[0][2] = -Sx*x + x;
- c[1][1] = Sy;
- c[1][2] = -Sy*y + y;
- }
- void frame(float Vx, float Vy, float Vcx, float Vcy, float Wx, float Wy, float Wcx, float Wcy, mat c)
- {
- unit(c);
- mat R, T1;
- unit(R);
- move(-Vcx, -Vcy, c);
- scale_3(0, 0, Wx / Vx, Wy / Vy, R);
- times(R, c, T1); set(T1, c);
- unit(R); R[1][1] = -1;
- times(R, c, T1); set(T1, c);
- move(Wcx, Wcy, R);
- times(R, c, T1); set(T1, c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement