Morph-SynRJ
view phy_server.cxx @ 0:22de913c2d84
morph-synrj intro
| author | "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>" |
|---|---|
| date | Tue Nov 27 15:23:52 2007 +0100 (2007-11-27) |
| parents | |
| children |
line source
1 /** @file phy_server.cxx
2 *
3 * @brief server for solving physic entity
4 *
5 *****************************************************************************
6 *
7 * @author psc80
8 *
9 * @date Created 2003/11
10 *
11 * @version $Id: phy_server.cxx,v 1.4 2004/01/18 04:06:08 psc80 Exp $
12 *
13 ****************************************************************************/
15 #include "phy_server.h"
17 namespace phy {
19 const int MaxLinks=16384;
20 const int MaxElements=16384*2;
23 typedef SpringDamper_t* SDptr_t;
24 typedef Element_t* Eptr_t;
26 Server_t::Server_t()
27 {
28 links=new SDptr_t[MaxLinks];
29 elements=new Eptr_t[MaxElements];
30 Init();
31 }
33 void Server_t::Init()
34 {
35 nbLinks=0;
36 nbElements=0;
37 }
40 void Server_t::StartForceSession()
41 {
42 mth::Vector3_t gravity(0,-38.81,0);
43 for (int i=0;i<nbElements;i++) {
44 elements[i]->InitForce();
45 elements[i]->ApplyForce(gravity*elements[i]->Mass());
46 }
47 }
50 void Server_t::EndForceSession()
51 {
52 for (int i=0;i<nbLinks;i++)
53 links[i]->Update();
54 }
57 int Server_t::Try1(const double& _dt)
58 {
59 for (int j=0;j<nbElements;j++)
60 if (!elements[j]->IsBlocked())
61 elements[j]->Update(_dt);
63 return 0;
64 }
68 void Server_t::AddElement(Element_t* _element)
69 {
70 elements[nbElements++]=_element;
71 SYS_ASSERT(_element && nbElements<MaxElements && "Too many elements increase MaxElements");
72 }
75 void Server_t::AddLink(SpringDamper_t* _element)
76 {
77 links[nbLinks++]=_element;
78 SYS_ASSERT(_element && nbLinks<MaxLinks && "Too many links increase MaxLinks");
79 }
82 }
