JNR
laRect2.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // FILE: laRect2.cpp
32 // Rectangle class
33 //
34 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
35 //
36 #include "stdafx.h"
37 #include "Core.h"
38 #include "Core.h"
39 
40 //Bounding box
41 /*void laRect2::BoundingBox(laPoint2 a, laPoint2 b)
42 {
43  point[0][0] = M_MIN(a.x(), b.x());
44  point[0][1] = M_MIN(a.y(), b.y());
45  point[1][0] = M_MAX(a.x(), b.x());
46  point[1][1] = M_MAX(a.y(), b.y());
47 }*/
48 
49 //Construct a standard M_UNIT rect, engulfing the point (x,y)
50 void laRect2::GridRect(laPoint2 &p)
51 {
52  pt[0].x( floor(p.x()/M_UNIT)*M_UNIT );
53  pt[0].y( floor(p.y()/M_UNIT)*M_UNIT );
54  pt[1].x( pt[0].x() + M_UNIT );
55  pt[1].y( pt[0].y() + M_UNIT );
56 }
57 
58 //Check if the point (x,y) is outwith the rect
59 /*void laRect2::isSafelyOutside(laPoint2 &pt, double delta)
60 {
61  if( (pt.x()<=pt[0].x()) && ((point[0].x()-pt.x())<delta) ) pt[0] = point[0].x() - delta;
62  else if( (pt.y()<=pt[0].y()) && ((point[0].y()-pt.y())<delta) ) pt[1] = point[0].y() - delta;
63 
64  else if( (pt.x()>=point[1].x()) && ((pt.x()-point[1].x())<delta) ) pt[0] = point[1].x() + delta;
65  else if( (pt.y()>=point[1].y()) && ((pt.y()-point[1].y())<delta) ) pt[1] = point[1].y() + delta;
66 }
67 
68 //Check if the point (x,y) is within the rect
69 void laRect2::isSafelyInside(laPoint2 &pt, double delta)
70 {
71  if( M_ABS(point[1].x()2-pt.x())<delta ) pt[0] = point[1].x()-delta;
72  if( M_ABS(point[0].x()1-pt.x())<delta ) pt[0] = point[0].x()+delta;
73 
74  if( M_ABS(point[1].y()-pt.y())<delta ) pt[1] = point[1].y()-delta;
75  if( M_ABS(point[0].y()-pt.y())<delta ) pt[1] = point[0].y()+delta;
76 }*/
77 
78 //Check if two rects are interecting
79 /*M_BOOL laRect2::intersecting(laRect2 r)
80 {
81  if(r.x()1 > point[1].x()) return M_FALSE;
82  if(point[0].x() > r.x()2) return M_FALSE;
83 
84  if(r.y()1 > point[1].y()) return M_FALSE;
85  if(point[0].y() > r.y()2) return M_FALSE;
86 
87  return M_TRUE;
88 }*/
89 
90 //draw (for debug purpoces)
92 {
93  r->transPush();
94  r->transTranslate(ptBase);
95 
96  r->drawLine(laPoint2(pt[0].x(), pt[0].y()), laPoint2(pt[1].x(), pt[0].y()));
97  r->drawLine(laPoint2(pt[1].x(), pt[0].y()), laPoint2(pt[1].x(), pt[1].y()));
98  r->drawLine(laPoint2(pt[1].x(), pt[1].y()), laPoint2(pt[0].x(), pt[1].y()));
99  r->drawLine(laPoint2(pt[0].x(), pt[1].y()), laPoint2(pt[0].x(), pt[0].y()));
100 
101  r->transPop();
102 }
#define M_UNIT
Unit of 1 meter.
void draw(laRenderer *r, laPoint2 &pt=laPoint2())
Draw rectangle ( primarily for debug purpoces )
Definition: laRect2.cpp:91
2D Point
Definition: laPoint_novec.h:41
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
laPoint2 pt[2]
Rectangle coordinates (upper-left and lower-right point)
Definition: laRect2.h:42