-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbox.html
More file actions
122 lines (100 loc) · 6.54 KB
/
Copy pathbox.html
File metadata and controls
122 lines (100 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Merriweather:300">
<link rel="icon" type="image/png" href="https://android.processing.org/favicon.png">
<link rel="stylesheet" href="../../css/main.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Processing for Android</title>
<!-- Fathom - beautiful, simple website analytics -->
<script src="https://cdn.usefathom.com/script.js" data-site="KCUSYTHO" defer></script>
<!-- / Fathom -->
</head>
<body>
<nav class="topnav">
<ul class="left">
<li><a href="https://processing.org/">Processing</a></li>
<li><a href="https://p5js.org/">p5.js</a></li>
<li><a href="https://py.processing.org/">Processing.py</a></li>
<li><a href="https://pi.processing.org/">Processing for Pi</a></li>
</ul>
<ul class="foundation">
<li><a href="https://processingfoundation.org/">Processing Foundation</a></li>
</ul>
</nav>
<header>
<h1 class="title">Processing for Android</h1>
</header>
<div class="group">
<nav class="site">
<img class="logo" src="../../imgs/logo.png" alt="Processing for Android logo">
<ul class="leftnav">
<li><a href="../../index.html">Home</a></li>
<li><a href="../../install.html">Install</a></li>
<li><a id="selected" href="../../reference/index.html">Reference</a></li>
<li><a href="../../tutorials/index.html">Tutorials</a></li>
<li><a href="../../books/index.html">Books</a></li>
<li><a href="../../gallery/index.html">Gallery</a></li>
<li><a href="https://discourse.processing.org/c/processing-android" target="_black">Forum</a></li>
<li><a href="https://github.com/processing/processing-android" target="_black">GitHub</a></li>
</ul>
</nav>
<section class="container main-text">
<div class="lang">
<a id="selected" href="query.html">EN</a>
<a href="../../es/reference/raycasting/box.html">ES</a>
</div>
<hr style="clear:both;">
<h2>intersectsBox()</h2>
<p>This function returns true if the given ray intersects a box of size s with a placement determined by the current geometry transformations applied to the scene. The ray can be automatically computed from the screen coordinates as in the following example:
</p>
<pre><code>
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>() {
<span style="color: #006699;">fullScreen</span>(<span style="color: #718A62;">P3D</span>);
}
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>draw</b></span>() {
<span style="color: #006699;">background</span>(200, 0, 150);
<span style="color: #006699;">translate</span>(<span style="color: #D94A7A;">width</span>/2, <span style="color: #D94A7A;">height</span>/2);
<span style="color: #669900;">if</span> (<span style="color: #D94A7A;">mousePressed</span> && intersectsSphere(70, 0, 0)) <span style="color: #006699;">fill</span>(0, 0, 255);
<span style="color: #669900;">else</span> <span style="color: #006699;">fill</span>(255, 0, 0);
<span style="color: #006699;">box</span>(70);
}
</code></pre>
<p>A ray with arbitrary origin and direction can also be provided:
</p>
<pre><code>
<span style="color: #E2661A;">PVector</span> origin = <span style="color: #33997E;">new</span> <span style="color: #006699;">PVector</span>();
<span style="color: #E2661A;">PVector</span> direction = <span style="color: #33997E;">new</span> <span style="color: #006699;">PVector</span>();
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>() {
<span style="color: #006699;">fullScreen</span>(<span style="color: #718A62;">P3D</span>);
}
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>draw</b></span>() {
origin.<span style="color: #006699;">set</span>(<span style="color: #D94A7A;">width</span>/2, <span style="color: #D94A7A;">height</span>/2, 0);
direction.<span style="color: #006699;">set</span>(-<span style="color: #D94A7A;">width</span>/2, -<span style="color: #D94A7A;">height</span>/2).<span style="color: #006699;">normalize</span>();
<span style="color: #006699;">background</span>(200, 0, 150);
<span style="color: #006699;">translate</span>(<span style="color: #D94A7A;">width</span>/2, <span style="color: #D94A7A;">height</span>/2);
<span style="color: #669900;">if</span> (<span style="color: #D94A7A;">mousePressed</span> && intersectsSphere(70, origin, direction)) <span style="color: #006699;">fill</span>(0, 0, 255);
<span style="color: #669900;">else</span> <span style="color: #006699;">fill</span>(255, 0, 0);
<span style="color: #006699;">box</span>(70);
}
</code></pre>
<p>The function accepts different width/height/depth values for the box:
</p>
<pre><code>
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>draw</b></span>() {
<span style="color: #666666;">// ...</span>
<span style="color: #006699;">translate</span>(<span style="color: #D94A7A;">width</span>/2, <span style="color: #D94A7A;">height</span>/2);
<span style="color: #669900;">if</span> (<span style="color: #D94A7A;">mousePressed</span> && intersectsBox(100, 120, 80, origin, direction)) <span style="color: #006699;">fill</span>(0, 0, 255);
<span style="color: #669900;">else</span> <span style="color: #006699;">fill</span>(255, 0, 0);
<span style="color: #006699;">box</span>(100, 120, 80);
}
</code></pre>
</section>
</div>
<footer class="footinfo">
<small>© The Processing Foundation. Processing for Android is a <a href=../../team.html>collaborative project</a>.</small>
</footer>
</body>
</html>