aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html')
-rw-r--r--cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html229
1 files changed, 229 insertions, 0 deletions
diff --git a/cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html b/cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html
new file mode 100644
index 00000000..68c678e0
--- /dev/null
+++ b/cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?rev=1.2&content-type=text/x-cvsweb-markup&sortby=date/index.html
@@ -0,0 +1,229 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
+<HEAD><style> A { color:black }</style>
+<!-- hennerik CVSweb $Revision: 1.93 $ -->
+<TITLE>code/nel/samples/pacs/object.cpp - view - 1.2</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee">
+<table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#aaaaaa"><tr valign=bottom><td><a href="object.cpp?sortby=date"><IMG SRC="http://www.nevrax.org/inc/img/picto-up.gif" ALT="[BACK]" BORDER="0" WIDTH="14" HEIGHT="13"></a> <b>Return to <A HREF="object.cpp?sortby=date">object.cpp</A>
+ CVS log</b> <IMG SRC="http://www.nevrax.org/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="http://www.nevrax.org/inc/img/picto-dir.gif" ALT="[DIR]" BORDER="0" WIDTH="15" HEIGHT="13"> <b>Up to <a href="/cvs/cvsweb.cgi/?sortby=date">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/?sortby=date">code</a> / <a href="/cvs/cvsweb.cgi/code/nel/?sortby=date">nel</a> / <a href="/cvs/cvsweb.cgi/code/nel/samples/?sortby=date">samples</a> / <a href="/cvs/cvsweb.cgi/code/nel/samples/pacs/?sortby=date">pacs</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File: <a href="/cvs/cvsweb.cgi/?sortby=date">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/?sortby=date">code</a> / <a href="/cvs/cvsweb.cgi/code/nel/?sortby=date">nel</a> / <a href="/cvs/cvsweb.cgi/code/nel/samples/?sortby=date">samples</a> / <a href="/cvs/cvsweb.cgi/code/nel/samples/pacs/?sortby=date">pacs</a> / <a href="/cvs/cvsweb.cgi/code/nel/samples/pacs/object.cpp?sortby=date">object.cpp</a>&nbsp;(<A HREF="/cvs/cvsweb.cgi/~checkout~/code/nel/samples/pacs/object.cpp?rev=1.2&amp;sortby=date" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/nel/samples/pacs/object.cpp?rev=1.2','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>
+Revision <B>1.2</B>, <i>Wed Feb 20 18:07:14 2002 UTC</i> (5 months ago) by <i>lecroart</i>
+<BR>Branch: <b>MAIN</b>
+<BR>CVS Tags: <b>georges_v2, HEAD</b><BR>Changes since <b>1.1: +2 -2
+ lines</b><PRE>
+#FIXED: doxygen warning
+</PRE>
+</td></tr></table><HR noshade><PRE>/** \file net_layer5/object.cpp
+ * Objects for the sample. Link between 3d instance and collision primitives.
+ *
+ * $Id: object.cpp,v 1.2 2002/02/20 18:07:14 lecroart Exp $
+ */
+
+/* Copyright, 2001 Nevrax Ltd.
+ *
+ * This file is part of NEVRAX NEL.
+ * NEVRAX NEL is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+
+ * NEVRAX NEL is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with NEVRAX NEL; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#include &quot;object.h&quot;
+
+// Pacs includes
+#include &lt;nel/pacs/u_move_container.h&gt;
+#include &lt;nel/pacs/u_move_primitive.h&gt;
+
+// 3d includes
+#include &lt;nel/3d/u_scene.h&gt;
+#include &lt;nel/3d/u_instance.h&gt;
+
+// Misc includes
+#include &lt;nel/misc/vectord.h&gt;
+
+#define BRAKE_FORCE (-0.1) // (m.s-2)
+#define GRAVITY_FORCE (-15.0)
+#define SHOCK_ABSORB (1.0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//
+
+using namespace NL3D;
+using namespace NLNET;
+using namespace NLMISC;
+using namespace NLPACS;
+
+// ***************************************************************************
+
+CObjectDyn::CObjectDyn (double width, double depth, double height, double orientation, const CVectorD&amp; pos,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const CVectorD&amp; speed, bool obstacle, UMoveContainer &amp;container, UScene &amp;scene,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UMovePrimitive::TReaction reaction, uint8 worldImage, uint8 nbImage, uint8 insertWorldImage)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// Create a box instance
+ &nbsp; &nbsp; &nbsp; &nbsp;_Instance = scene.createInstance (&quot;rectangle.shape&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_Instance);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup the instance
+ &nbsp; &nbsp; &nbsp; &nbsp;_Instance-&gt;setScale (CVectorD (width, depth, height));
+ &nbsp; &nbsp; &nbsp; &nbsp;_Instance-&gt;setRotQuat (CQuat (CVectorD (0, 0, 1), (float)orientation));
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Create a collision volume
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive = container.addCollisionablePrimitive (worldImage, nbImage);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;insertInWorldImage (insertWorldImage);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup the collision primitive
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setPrimitiveType (UMovePrimitive::_2DOrientedBox);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setHeight ((float)height);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setOrientation (orientation, insertWorldImage);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setSize ((float)width, (float)depth);
+
+ &nbsp; &nbsp; &nbsp; &nbsp; // This primitive is an obstacle (it blocks others)
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setObstacle (obstacle);
+
+ &nbsp; &nbsp; &nbsp; &nbsp; // Setup reaction type
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setReactionType (reaction);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup absorption value
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setAbsorbtion (0.9f);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup user data
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;UserData=(uint)this;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup trigger type
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setTriggerType (UMovePrimitive::EnterTrigger);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Set pos and speed
+ &nbsp; &nbsp; &nbsp; &nbsp;setPos (pos);
+ &nbsp; &nbsp; &nbsp; &nbsp;setSpeed (speed);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setGlobalPosition (pos, insertWorldImage);
+}
+
+// ***************************************************************************
+
+CObjectDyn::CObjectDyn (double diameter, double height, const CVectorD&amp; pos, const CVectorD&amp; speed,
+ &nbsp; &nbsp; &nbsp; &nbsp;bool obstacle, UMoveContainer &amp;container, UScene &amp;scene, UMovePrimitive::TReaction reaction,
+ &nbsp; &nbsp; &nbsp; &nbsp;uint8 worldImage, uint8 nbImage, uint8 insertWorldImage)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// Create a box instance
+ &nbsp; &nbsp; &nbsp; &nbsp;_Instance = scene.createInstance (&quot;cylinder.shape&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_Instance);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup the instance
+ &nbsp; &nbsp; &nbsp; &nbsp;_Instance-&gt;setScale (CVectorD (diameter, diameter, height));
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Create a collision volume
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive = container.addCollisionablePrimitive (worldImage, nbImage);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;insertInWorldImage (insertWorldImage);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup the primitive
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setPrimitiveType (UMovePrimitive::_2DOrientedCylinder);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setHeight ((float)height);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setRadius ((float)diameter/2.f);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// This primitive is an obstacle (it blocks others)
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setObstacle (true);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup reaction type
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setReactionType (reaction);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup reaction type
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setAbsorbtion (0.9f);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup user data
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;UserData=(uint)this;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Setup trigger type
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setTriggerType (UMovePrimitive::EnterTrigger);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Set pos and speed
+ &nbsp; &nbsp; &nbsp; &nbsp;setPos (pos);
+ &nbsp; &nbsp; &nbsp; &nbsp;setSpeed (speed);
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setGlobalPosition (pos, insertWorldImage);
+}
+
+// ***************************************************************************
+
+void CObjectDyn::tryMove (double deltaTime, UMoveContainer &amp;container, uint8 worldImage)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// New speed
+ &nbsp; &nbsp; &nbsp; &nbsp;if ( (_MovePrimitive-&gt;getSpeed(worldImage).norm()&gt;0.f) || _Speed.norm()&gt;0.f )
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Brake
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CVectorD newSpeed=_Speed;
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newSpeed.normalize();
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newSpeed*=BRAKE_FORCE*deltaTime;
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newSpeed+=_Speed;
+
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stop ?
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (_Speed*newSpeed&lt;=0)
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newSpeed=CVectorD (0,0,0);
+
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Set speed
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setSpeed (newSpeed);
+
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Try this move
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;move (_Speed, worldImage);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_TryMove=true;
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp; &nbsp;else
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_TryMove=false;
+
+}
+
+// ***************************************************************************
+
+void CObjectDyn::doMove (double deltaTime, uint8 worldImage)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// New speed
+ &nbsp; &nbsp; &nbsp; &nbsp;setSpeed (_MovePrimitive-&gt;getSpeed(worldImage));
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// New position
+ &nbsp; &nbsp; &nbsp; &nbsp;setPos (_MovePrimitive-&gt;getFinalPosition (worldImage));
+}
+
+// ***************************************************************************
+
+void CObjectDyn::setPos (const CVectorD&amp; pos)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;_Position=pos;
+ &nbsp; &nbsp; &nbsp; &nbsp;if (_Instance)
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_Instance-&gt;setPos (pos);
+}
+
+// ***************************************************************************
+
+void CObjectDyn::setGlobalPos (UGlobalPosition&amp; gpos, CVectorD&amp; pos, uint8 worldimage)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// Place the primitive the first time
+ &nbsp; &nbsp; &nbsp; &nbsp;_MovePrimitive-&gt;setGlobalPosition (gpos, worldimage);
+ &nbsp; &nbsp; &nbsp; &nbsp;setPos (pos);
+}
+
+// ***************************************************************************
+
+void CObjectDyn::setSpeed (const CVectorD&amp; speed)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;_Speed=speed;
+}
+
+// ***************************************************************************
+
+void CObjectDyn::remove (NLPACS::UMoveContainer &amp;container, UScene &amp;scene)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// Remove from container
+ &nbsp; &nbsp; &nbsp; &nbsp;container.removePrimitive (_MovePrimitive);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;// Remove instance
+ &nbsp; &nbsp; &nbsp; &nbsp;if (_Instance)
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scene.deleteInstance (_Instance);
+}
+
+// ***************************************************************************
+
+</PRE> \ No newline at end of file