Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/physics/physics_interface.cc @ 6528

Last change on this file since 6528 was 5257, checked in by bensch, 19 years ago

orxonox/trunk: bouncy effect with physically based animations… or something like it at least.

File size: 2.9 KB
RevLine 
[3954]1
2
[4555]3/*
[3954]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
[3961]14   main-programmer: Patrick Boenzli
[4375]15   co-programmer: Benjamin Grauer
[4555]16
[4375]17   bensch: renamed the file
[3954]18*/
19
[3961]20#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS
[3954]21
[4375]22#include "physics_interface.h"
[4392]23#include "physics_engine.h"
[4376]24
[4377]25#include "field.h"
[4376]26#include "p_node.h"
27
[4121]28#include "list.h"
29#include "string.h"
[3961]30#include "stdincl.h"
[3954]31
32using namespace std;
33
34
35/**
[4836]36 *  standard constructor
[4597]37 */
[4762]38PhysicsInterface::PhysicsInterface ()
[3954]39{
[4597]40  this->setClassID(CL_PHYSICS_INTERFACE, "PhysicsInterface");
[4397]41
[4597]42  this->mass = 1;
43  this->massChildren = 0;
44  this->forceSum = Vector(0, 0, 0);
45  this->bForceApplied = false;
[3954]46}
47
48/**
[4836]49 *  standard deconstructor
[3954]50*/
[4555]51PhysicsInterface::~PhysicsInterface ()
[3954]52{
53}
[4121]54
[4376]55/**
[4836]56 *  recalculates the total mass of all the children of this node
[4376]57
58   (only availiable for PNodes)
59*/
[4375]60void PhysicsInterface::recalcMass()
[4121]61{
[4440]62  /*
[4836]63    PNode* massCalcPNode = dynamic_cast<PNode*>(this);  //! @todo not sure if this will work ....
[4480]64    float massSum = 0;
[4555]65
[4480]66    tIterator<PNode>* iterator = massCalcPNode->children->getIterator();
[5115]67    PNode* pn = iterator->firstElement();
[4555]68    while( pn != NULL)
69    {
[4480]70    // todo: find out if children are PhysicsInterface in an efficient way
71    if (strcmp( pn->getClassName(), "PhysicsInterface")) {
72    massSum += ((PhysicsInterface*)pn)->getTotalMass();
[4121]73    }
[4480]74    pn = iterator->nextElement();
75    }
76    delete iterator;
[4555]77
[4480]78    if (massSum != this->massChildren ) {
[4376]79    this->massChildren = massSum;
80    if (strcmp( massCalcPNode->parent->getClassName(), "PhysicsInterface"))
[4480]81    ((PhysicsInterface*)massCalcPNode->parent)->recalcMass();
82    } else {
[4376]83    this->massChildren = massSum;
[4480]84    }
[4440]85  */
[4121]86}
[4555]87
[4480]88/**
[4836]89 *  applyes a field to this Object
90 * @param field the field to apply
[5255]91 *
92 * this function is virtual, and !must be reimplemented if the Member is !NOT! a PNode
[4480]93*/
[4395]94void PhysicsInterface::applyField(Field* field)
[4221]95{
[4762]96  PNode* tmp = dynamic_cast<PNode*>((BaseObject*)this);
[4555]97  this->forceSum += field->calcForce(tmp->getAbsCoor());
[4558]98  this->bForceApplied = true;
[4221]99}
100
[5257]101void PhysicsInterface::applyForce(const Vector& force)
102{
103  PNode* tmp = dynamic_cast<PNode*>((BaseObject*)this);
104  this->forceSum += force;
105  this->bForceApplied = true;
106}
107
[4480]108/**
[4836]109 *  ticks the PhysicsEffect
110 * @param dt: the value about which to tick
[4480]111*/
[4376]112void PhysicsInterface::tickPhys( float dt )
[4221]113{
[4397]114  //  Vector acc = this->forceSum / ( this->massChildren + this->mass );
[4762]115  PNode* coorTick =  dynamic_cast<PNode*>((BaseObject*)this);
[5257]116  if (coorTick != NULL )
117    coorTick->shiftCoor((coorTick->getVelocity()+ this->forceSum/this->mass*dt)*dt);
118
119  if (this->bForceApplied)
[4558]120  {
121    this->bForceApplied = false;
[5257]122    this->forceSum = Vector(0,0,0);
[4558]123  }
[4221]124}
Note: See TracBrowser for help on using the repository browser.