libigl
v2.5.0
Loading...
Searching...
No Matches
Viewport.h
Go to the documentation of this file.
1
// This file is part of libigl, a simple c++ geometry processing library.
2
//
3
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
//
5
// This Source Code Form is subject to the terms of the Mozilla Public License
6
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
// obtain one at http://mozilla.org/MPL/2.0/.
8
#ifndef IGL_VIEWPORT_H
9
#define IGL_VIEWPORT_H
10
11
namespace
igl
12
{
14
// Simple Viewport class for an opengl context. Handles reshaping and mouse.
15
struct
Viewport
16
{
17
int
x,y,width,height;
18
// Constructors
19
Viewport(
20
const
int
x=0,
21
const
int
y=0,
22
const
int
width=0,
23
const
int
height=0):
24
x(x),
25
y(y),
26
width(width),
27
height(height)
28
{
29
};
30
virtual
~Viewport(){}
31
void
reshape(
32
const
int
x,
33
const
int
y,
34
const
int
width,
35
const
int
height)
36
{
37
this->x = x;
38
this->y = y;
39
this->width = width;
40
this->height = height;
41
};
42
// Given mouse_x,mouse_y on the entire window return mouse_x, mouse_y in
43
// this viewport.
44
//
45
// Inputs:
46
// my mouse y-coordinate
47
// wh window height
48
// Returns y-coordinate in viewport
49
int
mouse_y(
const
int
my,
const
int
wh)
50
{
51
return
my - (wh - height - y);
52
}
53
// Inputs:
54
// mx mouse x-coordinate
55
// Returns x-coordinate in viewport
56
int
mouse_x(
const
int
mx)
57
{
58
return
mx - x;
59
}
60
// Returns whether point (mx,my) is in extend of Viewport
61
bool
inside(
const
int
mx,
const
int
my)
const
62
{
63
return
64
mx >= x && my >= y &&
65
mx < x+width && my < y+height;
66
}
67
};
68
}
69
70
#endif
igl
Definition
AABB.h:17
include
igl
Viewport.h
Generated by
1.9.8