00001
00002
00003
00004
00005 #if !defined(AFX_PHMAGNETICENGINE_H__EB4D369F_EA8F_42D5_94C1_36C5FD8B8E02__INCLUDED_)
00006 #define AFX_PHMAGNETICENGINE_H__EB4D369F_EA8F_42D5_94C1_36C5FD8B8E02__INCLUDED_
00007
00008 #include "PHSolid.h"
00009 #if _MSC_VER > 1000
00010 #pragma once
00011 #endif // _MSC_VER > 1000
00012
00013 #include <FileIO/FIDocScene.h>
00014 #include <SceneGraph/SGScene.h>
00015 #include <Physics/PHSolid.h>
00016 #include <Graphics/GRMesh.h>
00017
00018
00019 namespace Spr{;
00020
00021
00022 typedef Vec3f Vector;
00023 DEF_RECORD(XMagnet,{
00024 GUID Guid(){ return WBGuid("F99E7A61-47F2-4960-A430-F0E45C1B552B"); }
00025 Vector sPos;
00026 Vector nPos;
00027 FLOAT magPow;
00028 });
00029
00030
00031 class PHMagnet : public SGObject
00032 {
00033 public:
00034 void Clear();
00035 XMagnet magn;
00036 PHSolid * solid;
00037 SGOBJECTDEF(PHMagnet);
00038 bool AddChildObject(SGObject* o,SGScene* s);
00039 };
00040
00041 class PHMagnets:public std::vector< UTRef<PHMagnet> >{
00042 public:
00043 UTRef<PHMagnet>* Find(const UTRef<PHMagnet>& s){
00044 iterator it = std::find(begin(), end(), s);
00045 if (it == end()) return NULL;
00046 else return &*it;
00047 }
00048 UTRef<PHMagnet>* Find(const UTRef<PHMagnet>& s) const {
00049 return ((PHMagnets*)this)->Find(s);
00050 }
00051 };
00052
00053
00054
00055
00056 DEF_RECORD(XMagneticEngine,{
00057 GUID Guid(){ return WBGuid("A6217078-938D-4bdc-9AA8-59738B5C0CC6"); }
00058 Vector earthMagnet;
00059 });
00060
00061 class PHMagneticEngine : public SGBehaviorEngine
00062 {
00063 public:
00064 void LineDraw(Vec3f center,SGScene *s);
00065 void EarthPower(PHMagnet *one);
00066 void MagnetForce(PHMagnet *one,PHMagnet *two, SGScene *s);
00067
00068
00069 void AddForce(PHMagnet *one, PHMagnet *two,int flag);
00070 bool AddChildObject(SGObject* o,SGScene* s);
00071 XMagneticEngine mag;
00072 PHMagnets mags;
00073 UTRef<GRMesh> mesh;
00074 void Clear(SGScene* s){
00075 for(PHMagnets::iterator it = mags.begin(); it != mags.end(); ++it){
00076 (*it)->Clear();
00077 }
00078 mags.clear();
00079 }
00080 virtual void Step(SGScene *s);
00081 SGOBJECTDEF(PHMagneticEngine);
00082 PHMagneticEngine();
00083
00084 private:
00085
00086 };
00087
00088 }
00089 #endif // !defined(AFX_PHMAGNETICENGINE_H__EB4D369F_EA8F_42D5_94C1_36C5FD8B8E02__INCLUDED_)