Skip to content

Commit

Permalink
Deploy preview for PR 10 🛫
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 7, 2024
1 parent 03d2df8 commit 28b8dbc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 76 deletions.
40 changes: 21 additions & 19 deletions pr-preview/pr-10/03-is-here.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,22 @@ <h4>A New Physics Solver <span class="m-text m-dim">(&#64;fallenatlas)</span></h
</section>
<section id="raycasting-diogomsmiranda">
<h4>Raycasting <span class="m-text m-dim">(&#64;diogomsmiranda)</span></h4>
<p>Raycasting is a commonly used tool in game development which we Cubos were lacking until now!</p>
<p>Raycasting is a technique used to determine the intersection of a ray with an object in a scene, right now in Cubos there are 2 shapes of colliders,
the <code>BoxCollisionShape</code> and the <code>CapsuleCollisionShape</code>.</p>
<p>Because of this, the new system argument <code>Raycast</code> implementation can be divided into 2 parts, <strong>collision with boxes</strong> and <strong>collision with capsules</strong> (notice that a sphere is a capsule with no height).</p>
<p><strong>Collision with a Box</strong></p>
<p>The collision with a box is based on the Cyrus-Beck algorithm, which is a line clipping algorithm that is used to find the intersection of a line segment with a convex polygon.</p>
<p>Raycasting is a commonly used tool in game development which Cubos was lacking until now - it is a technique used to determine the intersection of a ray with an object in a scene.
This allows for a wide range of applications, such as shooting mechanics, object selection, and more.</p>
<p>This new utility was implemented as a system argument, which means it can be used in any system, by simply adding it as an argument:</p>
<pre class="m-code"><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="s">&quot;raycast&quot;</span><span class="p">).</span><span class="n">call</span><span class="p">([](</span><span class="n">Raycast</span><span class="w"> </span><span class="n">raycast</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="c1">// raycast from the origin to -50,0,0</span>
<span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">hit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Raycast</span><span class="p">.</span><span class="n">fire</span><span class="p">({{</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">},{</span><span class="mf">-50.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">}});</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hit</span><span class="p">.</span><span class="n">contains</span><span class="p">())</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">CUBOS_INFO</span><span class="p">(</span><span class="s">&quot;Hit entity {} at point {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">hit</span><span class="o">-&gt;</span><span class="n">entity</span><span class="p">,</span><span class="w"> </span><span class="n">hit</span><span class="o">-&gt;</span><span class="n">point</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">});</span></pre>
<p>To implement this, we had to handle the two types of colliders that we currently have in Cubos: boxes and capsules.</p>
<section id="intersection-with-a-box">
<h5>Intersection with a Box</h5>
<p>The intersection test with a box is based on the Cyrus-Beck algorithm, which is a line clipping algorithm that is used to find the intersection of a line segment with a convex polygon.</p>
<p>We can easily define a box by the minimum and maximum values of x,y,z and the ray by its origin and the direction.</p>
<p>A ray is defined then by the line formula:</p>
<div class="m-math">
Expand Down Expand Up @@ -342,8 +352,10 @@ <h4>Raycasting <span class="m-text m-dim">(&#64;diogomsmiranda)</span></h4>

<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">tMin</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mf">0.0F</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="n">tMax</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">tMin</span><span class="p">;</span>
<span class="p">};</span></pre>
<p><strong>Collision with a Capsule</strong></p>
<p>The collision with a capsule is more straight forward than the collision with a box, as we can separate a capsule into 3 parts,
</section>
<section id="intersection-with-a-capsule">
<h5>Intersection with a Capsule</h5>
<p>The intersection with a capsule is more straight forward than the collision with a box, as we can separate a capsule into 3 parts,
a cylinder and the two spheres at the ends.</p>
<p>We then can check for a point of intersection by checking if the ray intersects the cylinder, and if it doesn't, we check if it intersects the spheres.</p>
<p>We can determine both intersections by simply subbing the the ray's equation for x and z in the cylinder and sphere equations, and then solving it for t.</p>
Expand Down Expand Up @@ -389,17 +401,7 @@ <h4>Raycasting <span class="m-text m-dim">(&#64;diogomsmiranda)</span></h4>

<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">t</span><span class="p">;</span>
<span class="p">};</span></pre>
<p>To use the <code>Raycast</code> argument system, you can simply call the system <code>Raycast.fire</code> that takes a <code>Ray</code> as an argument.</p>
<pre class="m-code"><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="s">&quot;raycast&quot;</span><span class="p">).</span><span class="n">call</span><span class="p">([](</span><span class="n">Raycast</span><span class="w"> </span><span class="n">raycast</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="c1">// raycast from the origin to -50,0,0</span>
<span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">hit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Raycast</span><span class="p">.</span><span class="n">fire</span><span class="p">({{</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">},{</span><span class="mf">-50.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">,</span><span class="mf">0.0F</span><span class="p">}});</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hit</span><span class="p">.</span><span class="n">contains</span><span class="p">())</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// hit.point is the point where the ray hit the object</span>
<span class="w"> </span><span class="c1">// hit.entitiy is the entity that was hit</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">});</span></pre>
</section>
</section>
<section id="spot-light-shadows-tomas7770">
<h4>Spot Light Shadows <span class="m-text m-dim">(&#64;tomas7770)</span></h4>
Expand Down
40 changes: 21 additions & 19 deletions pr-preview/pr-10/feeds/all.atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,22 @@ Recently, Erin Catto shared his &lt;a href="https://box2d.org/posts/2024/02/solv
&lt;/section&gt;
&lt;section id="raycasting-diogomsmiranda"&gt;
&lt;h4&gt;Raycasting &lt;span class="m-text m-dim"&gt;(&amp;#64;diogomsmiranda)&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;Raycasting is a commonly used tool in game development which we Cubos were lacking until now!&lt;/p&gt;
&lt;p&gt;Raycasting is a technique used to determine the intersection of a ray with an object in a scene, right now in Cubos there are 2 shapes of colliders,
the &lt;code&gt;BoxCollisionShape&lt;/code&gt; and the &lt;code&gt;CapsuleCollisionShape&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Because of this, the new system argument &lt;code&gt;Raycast&lt;/code&gt; implementation can be divided into 2 parts, &lt;strong&gt;collision with boxes&lt;/strong&gt; and &lt;strong&gt;collision with capsules&lt;/strong&gt; (notice that a sphere is a capsule with no height).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Collision with a Box&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The collision with a box is based on the Cyrus-Beck algorithm, which is a line clipping algorithm that is used to find the intersection of a line segment with a convex polygon.&lt;/p&gt;
&lt;p&gt;Raycasting is a commonly used tool in game development which Cubos was lacking until now - it is a technique used to determine the intersection of a ray with an object in a scene.
This allows for a wide range of applications, such as shooting mechanics, object selection, and more.&lt;/p&gt;
&lt;p&gt;This new utility was implemented as a system argument, which means it can be used in any system, by simply adding it as an argument:&lt;/p&gt;
&lt;pre class="m-code"&gt;&lt;span class="n"&gt;cubos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;raycast&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;([](&lt;/span&gt;&lt;span class="n"&gt;Raycast&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;raycast&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// raycast from the origin to -50,0,0&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fire&lt;/span&gt;&lt;span class="p"&gt;({{&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;},{&lt;/span&gt;&lt;span class="mf"&gt;-50.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;}});&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;CUBOS_INFO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hit entity {} at point {}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;entity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To implement this, we had to handle the two types of colliders that we currently have in Cubos: boxes and capsules.&lt;/p&gt;
&lt;section id="intersection-with-a-box"&gt;
&lt;h5&gt;Intersection with a Box&lt;/h5&gt;
&lt;p&gt;The intersection test with a box is based on the Cyrus-Beck algorithm, which is a line clipping algorithm that is used to find the intersection of a line segment with a convex polygon.&lt;/p&gt;
&lt;p&gt;We can easily define a box by the minimum and maximum values of x,y,z and the ray by its origin and the direction.&lt;/p&gt;
&lt;p&gt;A ray is defined then by the line formula:&lt;/p&gt;
&lt;div class="m-math"&gt;
Expand Down Expand Up @@ -290,8 +300,10 @@ t = (point - ray.origin) / ray.direction

&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tMin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tMax&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tMin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Collision with a Capsule&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The collision with a capsule is more straight forward than the collision with a box, as we can separate a capsule into 3 parts,
&lt;/section&gt;
&lt;section id="intersection-with-a-capsule"&gt;
&lt;h5&gt;Intersection with a Capsule&lt;/h5&gt;
&lt;p&gt;The intersection with a capsule is more straight forward than the collision with a box, as we can separate a capsule into 3 parts,
a cylinder and the two spheres at the ends.&lt;/p&gt;
&lt;p&gt;We then can check for a point of intersection by checking if the ray intersects the cylinder, and if it doesn't, we check if it intersects the spheres.&lt;/p&gt;
&lt;p&gt;We can determine both intersections by simply subbing the the ray's equation for x and z in the cylinder and sphere equations, and then solving it for t.&lt;/p&gt;
Expand Down Expand Up @@ -337,17 +349,7 @@ a cylinder and the two spheres at the ends.&lt;/p&gt;

&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To use the &lt;code&gt;Raycast&lt;/code&gt; argument system, you can simply call the system &lt;code&gt;Raycast.fire&lt;/code&gt; that takes a &lt;code&gt;Ray&lt;/code&gt; as an argument.&lt;/p&gt;
&lt;pre class="m-code"&gt;&lt;span class="n"&gt;cubos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;raycast&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;([](&lt;/span&gt;&lt;span class="n"&gt;Raycast&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;raycast&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// raycast from the origin to -50,0,0&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fire&lt;/span&gt;&lt;span class="p"&gt;({{&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;},{&lt;/span&gt;&lt;span class="mf"&gt;-50.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0F&lt;/span&gt;&lt;span class="p"&gt;}});&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// hit.point is the point where the ray hit the object&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// hit.entitiy is the entity that was hit&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;&lt;/pre&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id="spot-light-shadows-tomas7770"&gt;
&lt;h4&gt;Spot Light Shadows &lt;span class="m-text m-dim"&gt;(&amp;#64;tomas7770)&lt;/span&gt;&lt;/h4&gt;
Expand Down
Loading

0 comments on commit 28b8dbc

Please sign in to comment.