root / rgbdslam / external / siftgpu / src / TestWin / GLTransform.h @ 9240aaa3
History | View | Annotate | Download (2.26 KB)
1 |
////////////////////////////////////////////////////////////////////////////
|
---|---|
2 |
// File: GLTransform.h
|
3 |
// Author: Changchang Wu
|
4 |
// Description : GLTransform tookit for opengl display
|
5 |
//
|
6 |
//
|
7 |
//
|
8 |
// Copyright (c) 2007 University of North Carolina at Chapel Hill
|
9 |
// All Rights Reserved
|
10 |
//
|
11 |
// Permission to use, copy, modify and distribute this software and its
|
12 |
// documentation for educational, research and non-profit purposes, without
|
13 |
// fee, and without a written agreement is hereby granted, provided that the
|
14 |
// above copyright notice and the following paragraph appear in all copies.
|
15 |
//
|
16 |
// The University of North Carolina at Chapel Hill make no representations
|
17 |
// about the suitability of this software for any purpose. It is provided
|
18 |
// 'as is' without express or implied warranty.
|
19 |
//
|
20 |
// Please send BUG REPORTS to ccwu@cs.unc.edu
|
21 |
//
|
22 |
////////////////////////////////////////////////////////////////////////////
|
23 |
#if !defined(GL_TRANSFORM_H)
|
24 |
#define GL_TRANSFORM_H
|
25 |
|
26 |
#include <math.h> |
27 |
class GlTransform |
28 |
{ |
29 |
public:
|
30 |
double cx, cy;
|
31 |
double q[4]; |
32 |
double t[3]; |
33 |
double sc, ds;
|
34 |
GlTransform() |
35 |
{ |
36 |
q[0] = 1.0; |
37 |
q[1] = q[2] = q[3] =0; |
38 |
t[0] = t[1] = t[2] =0; |
39 |
sc = 1.0; |
40 |
cx = cy = 0;
|
41 |
} |
42 |
void reset()
|
43 |
{ |
44 |
q[0] = 1.0; |
45 |
q[1] = q[2] = q[3] =0; |
46 |
t[0] = t[1] = t[2] =0; |
47 |
sc = 1.0; |
48 |
} |
49 |
void operator=(GlTransform& v)
|
50 |
{ |
51 |
q[0] = v.q[0]; |
52 |
q[1] = v.q[1]; |
53 |
q[2] = v.q[2]; |
54 |
q[3] = v.q[3]; |
55 |
t[0] = v.t[0]; |
56 |
t[1] = v.t[1]; |
57 |
t[2] = v.t[3]; |
58 |
sc = v.sc; |
59 |
} |
60 |
void operator *=(double scale) |
61 |
{ |
62 |
sc *= scale; |
63 |
t[0]*= scale;
|
64 |
t[1]*= scale;
|
65 |
t[2]*= scale;
|
66 |
} |
67 |
void scaleset(double scale) |
68 |
{ |
69 |
double ds = scale/sc;
|
70 |
t[0]*= ds;
|
71 |
t[1]*= ds;
|
72 |
t[2]*= ds;
|
73 |
sc = scale; |
74 |
} |
75 |
void scaleup()
|
76 |
{ |
77 |
double scale;
|
78 |
if(sc < 6) scale = float(int(sc))+1; |
79 |
else scale = sc * 2.0; |
80 |
scaleset(scale); |
81 |
} |
82 |
void scaledown()
|
83 |
{ |
84 |
double scale;
|
85 |
if(sc >1.0 &&sc < 2.0) scale = 1.0; |
86 |
else scale = sc*0.5; |
87 |
scaleset(scale); |
88 |
} |
89 |
void translate(int dx, int dy, int dz =0) |
90 |
{ |
91 |
t[0] += dx;
|
92 |
t[1] += dy;
|
93 |
t[2] += dz;
|
94 |
} |
95 |
void setcenter(double x, double y) |
96 |
{ |
97 |
cx = x; |
98 |
cy = y; |
99 |
t[0] = t[1] = t[2] = 0; |
100 |
} |
101 |
|
102 |
void transform(double es = 1.0) |
103 |
{ |
104 |
double s = sc* es;
|
105 |
glTranslated(cx*es, cy*es, 0.0); |
106 |
glTranslated(t[0] ,t[1] ,t[2]); |
107 |
glScaled(s,s,s); |
108 |
glTranslated(-cx, - cy, 0);
|
109 |
} |
110 |
}; |
111 |
|
112 |
#endif
|
113 |
|