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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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="/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="/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="/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> (<A HREF="/cvs/cvsweb.cgi/~checkout~/code/nel/samples/pacs/object.cpp?rev=1.2&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 "object.h"
// Pacs includes
#include <nel/pacs/u_move_container.h>
#include <nel/pacs/u_move_primitive.h>
// 3d includes
#include <nel/3d/u_scene.h>
#include <nel/3d/u_instance.h>
// Misc includes
#include <nel/misc/vectord.h>
#define BRAKE_FORCE (-0.1) // (m.s-2)
#define GRAVITY_FORCE (-15.0)
#define SHOCK_ABSORB (1.0) //
using namespace NL3D;
using namespace NLNET;
using namespace NLMISC;
using namespace NLPACS;
// ***************************************************************************
CObjectDyn::CObjectDyn (double width, double depth, double height, double orientation, const CVectorD& pos,
const CVectorD& speed, bool obstacle, UMoveContainer &container, UScene &scene,
UMovePrimitive::TReaction reaction, uint8 worldImage, uint8 nbImage, uint8 insertWorldImage)
{
// Create a box instance
_Instance = scene.createInstance ("rectangle.shape");
nlassert (_Instance);
// Setup the instance
_Instance->setScale (CVectorD (width, depth, height));
_Instance->setRotQuat (CQuat (CVectorD (0, 0, 1), (float)orientation));
// Create a collision volume
_MovePrimitive = container.addCollisionablePrimitive (worldImage, nbImage);
_MovePrimitive->insertInWorldImage (insertWorldImage);
// Setup the collision primitive
_MovePrimitive->setPrimitiveType (UMovePrimitive::_2DOrientedBox);
_MovePrimitive->setHeight ((float)height);
_MovePrimitive->setOrientation (orientation, insertWorldImage);
_MovePrimitive->setSize ((float)width, (float)depth);
// This primitive is an obstacle (it blocks others)
_MovePrimitive->setObstacle (obstacle);
// Setup reaction type
_MovePrimitive->setReactionType (reaction);
// Setup absorption value
_MovePrimitive->setAbsorbtion (0.9f);
// Setup user data
_MovePrimitive->UserData=(uint)this;
// Setup trigger type
_MovePrimitive->setTriggerType (UMovePrimitive::EnterTrigger);
// Set pos and speed
setPos (pos);
setSpeed (speed);
_MovePrimitive->setGlobalPosition (pos, insertWorldImage);
}
// ***************************************************************************
CObjectDyn::CObjectDyn (double diameter, double height, const CVectorD& pos, const CVectorD& speed,
bool obstacle, UMoveContainer &container, UScene &scene, UMovePrimitive::TReaction reaction,
uint8 worldImage, uint8 nbImage, uint8 insertWorldImage)
{
// Create a box instance
_Instance = scene.createInstance ("cylinder.shape");
nlassert (_Instance);
// Setup the instance
_Instance->setScale (CVectorD (diameter, diameter, height));
// Create a collision volume
_MovePrimitive = container.addCollisionablePrimitive (worldImage, nbImage);
_MovePrimitive->insertInWorldImage (insertWorldImage);
// Setup the primitive
_MovePrimitive->setPrimitiveType (UMovePrimitive::_2DOrientedCylinder);
_MovePrimitive->setHeight ((float)height);
_MovePrimitive->setRadius ((float)diameter/2.f);
// This primitive is an obstacle (it blocks others)
_MovePrimitive->setObstacle (true);
// Setup reaction type
_MovePrimitive->setReactionType (reaction);
// Setup reaction type
_MovePrimitive->setAbsorbtion (0.9f);
// Setup user data
_MovePrimitive->UserData=(uint)this;
// Setup trigger type
_MovePrimitive->setTriggerType (UMovePrimitive::EnterTrigger);
// Set pos and speed
setPos (pos);
setSpeed (speed);
_MovePrimitive->setGlobalPosition (pos, insertWorldImage);
}
// ***************************************************************************
void CObjectDyn::tryMove (double deltaTime, UMoveContainer &container, uint8 worldImage)
{
// New speed
if ( (_MovePrimitive->getSpeed(worldImage).norm()>0.f) || _Speed.norm()>0.f )
{
// Brake
CVectorD newSpeed=_Speed;
newSpeed.normalize();
newSpeed*=BRAKE_FORCE*deltaTime;
newSpeed+=_Speed;
// Stop ?
if (_Speed*newSpeed<=0)
newSpeed=CVectorD (0,0,0);
// Set speed
setSpeed (newSpeed);
// Try this move
_MovePrimitive->move (_Speed, worldImage);
_TryMove=true;
}
else
_TryMove=false;
}
// ***************************************************************************
void CObjectDyn::doMove (double deltaTime, uint8 worldImage)
{
// New speed
setSpeed (_MovePrimitive->getSpeed(worldImage));
// New position
setPos (_MovePrimitive->getFinalPosition (worldImage));
}
// ***************************************************************************
void CObjectDyn::setPos (const CVectorD& pos)
{
_Position=pos;
if (_Instance)
_Instance->setPos (pos);
}
// ***************************************************************************
void CObjectDyn::setGlobalPos (UGlobalPosition& gpos, CVectorD& pos, uint8 worldimage)
{
// Place the primitive the first time
_MovePrimitive->setGlobalPosition (gpos, worldimage);
setPos (pos);
}
// ***************************************************************************
void CObjectDyn::setSpeed (const CVectorD& speed)
{
_Speed=speed;
}
// ***************************************************************************
void CObjectDyn::remove (NLPACS::UMoveContainer &container, UScene &scene)
{
// Remove from container
container.removePrimitive (_MovePrimitive);
// Remove instance
if (_Instance)
scene.deleteInstance (_Instance);
}
// ***************************************************************************
</PRE>
|