snipt

Ctrl+h for KB shortcuts

VB.net

Управление прозрачности от угла к камере

Dim cur_angle, new_alpha As Double
Dim vector_cam, vector_obj, shift_pos, this_pos As Vertex

sub OnExecPerField()
	this_pos = LocalPosToWorldPos(this.position.xyz)
	shift_pos = this.position.xyz
	shift_pos.z += 1
	shift_pos = LocalPosToWorldPos(shift_pos)
	vector_cam = scene.CurrentCamera.Position.xyz - scene.CurrentCamera.Direction.xyz
	vector_obj = this_pos - shift_pos
	
	vector_cam.Normalize()
	vector_obj.Normalize()
	
	'println("vector_cam = " & vector_cam)
	'println("vector_obj = " & vector_obj)
	cur_angle = 180 * AngleBetweenVectors (vector_cam, vector_obj) / 3.1415926535 - 180
	cur_angle = Abs(cur_angle)
	
	'cur_angle = ((((0))))
	'println(cur_angle)
	If cur_angle > 90 Then
		new_alpha = 0
	Else
		new_alpha = 50 - 50.0 * cur_angle/90.0
	End If
	If new_alpha < 0.001 Then new_alpha = 0.001
	this.Alpha.Value = new_alpha
end sub
https://snipt.net/embed/7de177aa7fb50ab1def89f0f5874b04f/
/raw/7de177aa7fb50ab1def89f0f5874b04f/
7de177aa7fb50ab1def89f0f5874b04f
vb.net
VB.net
30
2019-08-25T18:35:34
True
False
False
Feb 05, 2014 at 07:54 AM
/api/public/snipt/111103/
-11310
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a> <a href="#L-19">19</a> <a href="#L-20">20</a> <a href="#L-21">21</a> <a href="#L-22">22</a> <a href="#L-23">23</a> <a href="#L-24">24</a> <a href="#L-25">25</a> <a href="#L-26">26</a> <a href="#L-27">27</a> <a href="#L-28">28</a> <a href="#L-29">29</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">Dim</span> <span class="n">cur_angle</span><span class="p">,</span> <span class="n">new_alpha</span> <span class="ow">As</span> <span class="kt">Double</span> </span><span id="L-2"><a name="L-2"></a><span class="k">Dim</span> <span class="n">vector_cam</span><span class="p">,</span> <span class="n">vector_obj</span><span class="p">,</span> <span class="n">shift_pos</span><span class="p">,</span> <span class="n">this_pos</span> <span class="ow">As</span> <span class="n">Vertex</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="k">sub</span> <span class="nf">OnExecPerField</span><span class="p">()</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">this_pos</span> <span class="o">=</span> <span class="n">LocalPosToWorldPos</span><span class="p">(</span><span class="n">this</span><span class="p">.</span><span class="n">position</span><span class="p">.</span><span class="n">xyz</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">shift_pos</span> <span class="o">=</span> <span class="n">this</span><span class="p">.</span><span class="n">position</span><span class="p">.</span><span class="n">xyz</span> </span><span id="L-7"><a name="L-7"></a> <span class="n">shift_pos</span><span class="p">.</span><span class="n">z</span> <span class="o">+=</span> <span class="mi">1</span> </span><span id="L-8"><a name="L-8"></a> <span class="n">shift_pos</span> <span class="o">=</span> <span class="n">LocalPosToWorldPos</span><span class="p">(</span><span class="n">shift_pos</span><span class="p">)</span> </span><span id="L-9"><a name="L-9"></a> <span class="n">vector_cam</span> <span class="o">=</span> <span class="n">scene</span><span class="p">.</span><span class="n">CurrentCamera</span><span class="p">.</span><span class="n">Position</span><span class="p">.</span><span class="n">xyz</span> <span class="o">-</span> <span class="n">scene</span><span class="p">.</span><span class="n">CurrentCamera</span><span class="p">.</span><span class="n">Direction</span><span class="p">.</span><span class="n">xyz</span> </span><span id="L-10"><a name="L-10"></a> <span class="n">vector_obj</span> <span class="o">=</span> <span class="n">this_pos</span> <span class="o">-</span> <span class="n">shift_pos</span> </span><span id="L-11"><a name="L-11"></a> </span><span id="L-12"><a name="L-12"></a> <span class="n">vector_cam</span><span class="p">.</span><span class="n">Normalize</span><span class="p">()</span> </span><span id="L-13"><a name="L-13"></a> <span class="n">vector_obj</span><span class="p">.</span><span class="n">Normalize</span><span class="p">()</span> </span><span id="L-14"><a name="L-14"></a> </span><span id="L-15"><a name="L-15"></a> <span class="c">&#39;println(&quot;vector_cam = &quot; &amp; vector_cam)</span> </span><span id="L-16"><a name="L-16"></a> <span class="c">&#39;println(&quot;vector_obj = &quot; &amp; vector_obj)</span> </span><span id="L-17"><a name="L-17"></a> <span class="n">cur_angle</span> <span class="o">=</span> <span class="mi">180</span> <span class="o">*</span> <span class="n">AngleBetweenVectors</span> <span class="p">(</span><span class="n">vector_cam</span><span class="p">,</span> <span class="n">vector_obj</span><span class="p">)</span> <span class="o">/</span> <span class="mf">3.1415926535</span> <span class="o">-</span> <span class="mi">180</span> </span><span id="L-18"><a name="L-18"></a> <span class="n">cur_angle</span> <span class="o">=</span> <span class="n">Abs</span><span class="p">(</span><span class="n">cur_angle</span><span class="p">)</span> </span><span id="L-19"><a name="L-19"></a> </span><span id="L-20"><a name="L-20"></a> <span class="c">&#39;cur_angle = ((((0))))</span> </span><span id="L-21"><a name="L-21"></a> <span class="c">&#39;println(cur_angle)</span> </span><span id="L-22"><a name="L-22"></a> <span class="k">If</span> <span class="n">cur_angle</span> <span class="o">&gt;</span> <span class="mi">90</span> <span class="k">Then</span> </span><span id="L-23"><a name="L-23"></a> <span class="n">new_alpha</span> <span class="o">=</span> <span class="mi">0</span> </span><span id="L-24"><a name="L-24"></a> <span class="k">Else</span> </span><span id="L-25"><a name="L-25"></a> <span class="n">new_alpha</span> <span class="o">=</span> <span class="mi">50</span> <span class="o">-</span> <span class="mf">50.0</span> <span class="o">*</span> <span class="n">cur_angle</span><span class="o">/</span><span class="mf">90.0</span> </span><span id="L-26"><a name="L-26"></a> <span class="k">End</span> <span class="k">If</span> </span><span id="L-27"><a name="L-27"></a> <span class="k">If</span> <span class="n">new_alpha</span> <span class="o">&lt;</span> <span class="mf">0.001</span> <span class="k">Then</span> <span class="n">new_alpha</span> <span class="o">=</span> <span class="mf">0.001</span> </span><span id="L-28"><a name="L-28"></a> <span class="n">this</span><span class="p">.</span><span class="n">Alpha</span><span class="p">.</span><span class="n">Value</span> <span class="o">=</span> <span class="n">new_alpha</span> </span><span id="L-29"><a name="L-29"></a><span class="k">end</span> <span class="k">sub</span> </span></pre></div> </td></tr></table>
vizrt