Similar documents
Springhead Users Manual Yuichi Tazaki

Springhead Users Manual Yuichi Tazaki and Springhead Development Team.

まずは以下の文章をテキストエディタで作成してみましょう テキストエディタの使用方法は別紙の テキストエディタ (gedit) の使用方法について を参考にしてください ホームページ作成の練習 ファイル名を index.html として保存ができましたら サーバーにアップロードします アップロード方法

untitled

DiMP Users Manual Yuichi Tazaki

AJANコマンドリファレンス(GUIコマンド編)

PYTHON 資料 電脳梁山泊烏賊塾 PYTHON 入門 GUI プログラミング Python/Tkinter(Tcl/Tk) の利用 全般 Tcl/Tk とは GUI(Graphical User Interface) 用のスクリプト言語で 此れを利用すると ウィジェット (widget) と呼ば

1. ホームページ概要 (1) ホームページとは現在インターネット上では 世界中で数億台以上のコンピュータが相互に接続されています このインターネットが爆発的に普及した最大の要因が ホームページ です ホームページ を作成 閲覧するためにパソコンを購入する方が増えてきています ホームページの最大の特

Condition DAQ condition condition 2 3 XML key value

programmingII2019-v01

1. ホームページ 概 要 (1)ホームページとは 現 在 インターネット 上 では 世 界 中 で 数 億 台 以 上 のコンピュータが 相 互 に 接 続 されています このインターネットが 爆 発 的 に 普 及 した 最 大 の 要 因 が ホームページ です ホームページ を 作 成 閲

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

ProVisionaire Control V3.0セットアップガイド

スライド タイトルなし

1 VisBAR edu H 2 O.....

HA8000シリーズ ユーザーズガイド ~BIOS編~ HA8000/RS110/TS10 2013年6月~モデル

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

elem attr value = "..." Scenebuilder XML <elem attr="value"... /> XML XML Scenebuilder body hinge XML Scenebuilder 4 3 Scenebuilder XML C/C++ bool int

OpenCV IS Report No Report Medical Information System Labratry

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

1

C# ++ MASA C# ( ) XNA 1.1 C# ( ) VisualStuio XNA 4.0 VisualStuio XNA 3.1 * * *3 2.1 VisualStuio Windows ( TextGam

# let st1 = {name = "Taro Yamada"; id = };; val st1 : student = {name="taro Yamada"; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n

JavaScript の使い方

r07.dvi

WinDriver PCI Quick Start Guide

ohp07.dvi

2

POV-Ray による CG 作成 秋田工業高等専門学校竹下大樹 引用元釧路工業高等専門学校技術室報告集第 9 号二谷聡志著 オープンソースソフトウェアによる CG 作成および動画作成

TH-42PAS10 TH-37PAS10 TQBA0286

1

Step 1 Feature Extraction Featuer Extraction Feature Extraction Featuer Extraction Image Analysis Start>Programs>Agilent-Life Sciences>Feature Extract

HA8000-bdシリーズ RAID設定ガイド HA8000-bd/BD10X2

Python Speed Learning

~~~~~~~~~~~~~~~~~~ wait Call CPU time 1, latch: library cache 7, latch: library cache lock 4, job scheduler co

HIS-CCBASEver2

ohp03.dvi

Introduction Purpose This training course describes the configuration and session features of the High-performance Embedded Workshop (HEW), a key tool


Complex Lab – Operating Systems - Graphical Console

~/WWW-local/compIID (WWW IID ) $ mkdir WWW-local $ cd WWW-local $ mkdir compiid 3. Emacs index.html n (a) $ cd ~/WWW/compIID

r08.dvi

2008 DS T050049

Lab GPIO_35 GPIO

第3章 OpenGL の基礎

r03.dvi


H8000操作編

2

program.dvi

For_Beginners_CAPL.indd

untitled

1,.,,,., RDBM, SQL. OSS,, SQL,,.

LC304_manual.ai

Z7000操作編_本文.indb

SystemC言語概論

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

ohp08.dvi

double float

fx-9860G Manager PLUS_J

Nios® II HAL API を使用したソフトウェア・サンプル集 「Modular Scatter-Gather DMA Core」

1st-session key

フリーセルプロの使い方

2

2

listings-ext

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

RHEA key

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM

2

第3章 OpenGL の基礎


CudaWaveField

2

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

第5回お試しアカウント付き並列プログラミング講習会

ストラドプロシージャの呼び出し方

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

ProVAL Recent Projects, ProVAL Online 3 Recent Projects ProVAL Online Show Online Content on the Start Page Page 13

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

Isogai, T., Building a dynamic correlation network for fat-tailed financial asset returns, Applied Network Science (7):-24, 206,


(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

AN 100: ISPを使用するためのガイドライン

2

1.3 ( ) ( ) C

19_22_26R9000操作編ブック.indb

BW BW

RR-US470 (RQCA1588).indd

fp.gby

ydkr_manu_v12.PDF


LC-24_22_19K30.indb

6 2 s µ µµµ µµµµ µ µ h µs µ µµµµ µ µ µ s mµµµµµ µµµ µµ µ u m µmµµµµµ µµ µ µ µ µ µ µ µ µ s 1

WinHPC ppt

XMPによる並列化実装2

Introduction Purpose The course describes library configuration and usage in the High Performance Embedded Workshop (HEW), which speeds development of

10-C.._241_266_.Z

. IDE JIVE[1][] Eclipse Java ( 1) Java Platform Debugger Architecture [5] 3. Eclipse GUI JIVE 3.1 Eclipse ( ) 1 JIVE Java [3] IDE c 016 Information Pr

Transcription:

Springhead Users Manual Yuichi Tazaki and Springhead Development Team.

3 1 7 2 Getting Started 9 2.1................................ 9 2.2 SVN............................. 9 2.3.................................. 9 2.4............................ 10 2.5....................... 11 2.6.......................... 11 3 Springhead 17 3.1............................. 17 3.2............................... 17 3.3 API.......................... 17 3.4..................... 18 4 Base 21 4.1............................ 21 4.2............................. 28 4.3................................ 28 5 Foundation 29 5.1................................ 29 5.2................................ 29 5.3.......................... 31 5.4................................... 32 5.5............................. 33

4 6 Collision 35 6.1..................................... 35 6.2................................. 35 6.3................................. 41 6.4............................... 42 7 Physics 45 7.1..................................... 45 7.2 Physics SDK................................ 45 7.3................................... 46 7.4..................................... 48 7.5..................................... 51 7.6............................. 62 7.7..................................... 70 7.8....................... 74 7.9..................................... 74 7.10.......................... 75 8 Graphics 77 8.1..................................... 77 8.2 Graphics SDK............................... 77 8.3................................... 78 8.4................................ 81 8.5.................................. 82 8.6................................... 84 8.7................................... 84 8.8................................. 85 8.9.................................. 86 8.10.................................. 88 9 FileIO 95 9.1..................................... 95 9.2 FileIO SDK................................ 95 9.3........................... 96 9.4......................... 99 9.5........................... 103

5 10 HumanInterface 105 10.1..................................... 105 10.2 HumanInterface SDK........................... 105 10.3.......................... 105 10.4................................. 108 10.5............................ 108 10.6............................. 112 10.7............................... 112 10.8 Spidar................................... 116 11 Creature 117 11.1 Creature........................ 117 12 Framework 119 12.1..................................... 119 12.2 Framework SDK.............................. 120 12.3 Framework............................. 121 12.4.......................... 124 12.5 Framework......................... 125 12.6.......................... 125 12.7................................. 130 12.8 Framework............... 130 12.9................................ 131 12.10............. 133 13 Python 137 13.1................................... 137 13.2 Python Springhead API.................. 147 14 151 14.1..................................... 151 14.2............................ 151 14.3......................... 152 14.4................................ 152 14.5............................. 152

7 1 Springhead Springhead C++ Springhead

9 2 Getting Started Springhead 2.1 Springhead http://springhead.info/wiki/ zip ( ) Subversion 2.2 SVN Springhead Subversion Springhead Subversion http://springhead.info/spr2/springhead2/trunk 2.3 Springhead Windows, Max, Unix Windows Visual Studio ( )

10 2 Getting Started Fig. 2.1 Building the library Windows + Visual Studio Windows Visual Studio Windows XP/Vista/7, Visual Studio 2008/2010/2012/2013 2.4 Springhead C:\Springhead2 Springhead ( ) Visual Studio C:\Springhead2\src\Springhead12.0.sln Visual Studio Visual Studio 2010 Visual Studio 2013 Visual Studio Fig. 2.1 Springhead C:\Springhead2\lib\win32\ C: \Springhead2\lib\win64\ Table 2.1

2.5 11 Table 2.1 Build configurations Release multithread, DLL Springhead12.0##.lib Debug multithread, Debug, DLL Springhead12.0##D.lib Trace multithread, Debug, DLL Springhead12.0##T.lib ## Win32 x86 Trace Release Visual Studio 2008 Static Link Visual Studio 2010 Release / Debug Static Link, ReleaseDll / DebugDll / Trace DLL Visual Studio 2012 DLL Visual Studio 2010 32 Win32 Visual Studio 2010 ReleaseDll DebugDll.lib M MD 2.5 C:\Springhead2\src\Samples\All12.0.sln Physics/BoxStack Physics/Joints 2.6 Springhead Visual Studio 2013

12 2 Getting Started Fig. 2.2 Create new project Fig. 2.3 Project configuration Visual C++ Win32 C: \Experiments Springhead > > C++ (.cpp) main.cpp

2.6 13 Fig. 2.4 Create source file Fig. 2.5 Add include path main.cpp Table 2.2 Springhead ( ) 64 x64

14 2 Getting Started Table 2.2 Simplest program code #include <Springhead.h> #include <Framework/SprFWApp.h> using namespace Spr; class MyApp : public FWApp{ public: virtual void Init(int argc = 0, char* argv[] = 0){ FWApp::Init(argc, argv); PHSdkIf* phsdk = GetSdk()->GetPHSdk(); PHSceneIf* phscene = GetSdk()->GetScene()->GetPHScene(); CDBoxDesc bd; // PHSolidIf* floor = phscene->createsolid(); floor->setdynamical(false); bd.boxsize = Vec3f(5.0f, 1.0f, 5.0f); floor->addshape(phsdk->createshape(bd)); floor->setframeposition(vec3d(0, -1.0, 0)); // PHSolidIf* box = phscene->createsolid(); bd.boxsize = Vec3f(0.2f, 0.2f, 0.2f); box->addshape(phsdk->createshape(bd)); box->setframeposition(vec3d(0.0, 1.0, 0.0)); } } app; GetSdk()->SetDebugMode(true); int main(int argc, char* argv[]){ app.init(argc, argv); app.startmainloop(); return 0; } 2.4 C/C++ > > Fig. 2.5

2.6 15 Fig. 2.6 Add library path Fig. 2.7 Specify library file Springhead > > Fig. 2.6 Springhead (64 win32 win64 ) Debug C/C++ > > DLL (/MDd) > > Springhead12.0DWin32.lib Release DLL (/MD) Springhead12.0Win32.lib

16 2 Getting Started Fig. 2.8 Program running (F7) (F5) Fig. 2.8

17 3 Springhead 3.1 Springhead Fig. 3.1 3.2 Springhead Table 3.1 Table 3.2 Springhead Springhead 3.3 API Table 3.1 ( : Physics PHSolid Collision CDShape) ( : Foundation Object) API( ) API ( + ) PHSolid::SetMass GRSdk::CreateScene

18 3 Springhead Springhead bin doc lib ルートディレクトリ外部ツールドキュメントライブラリディレクトリ win32 Springhead**.lib ライブラリファイル include Springhead.h Base Foundation... インクルードディレクトリ インクルードファイル モジュール別インクルードディレクトリ src Base Foundation... ソースディレクトリ モジュール別ソースディレクトリ tests Samples テストプログラム サンプルプログラム Fig. 3.1 Directory tree of Springhead 3.4 Springhead Springhead Base Foundation Framework Springhead

3.4 19 Table 3.1 Springhead modules Base - Foundation UT Springhead Collision CD Physics PH Graphics GR FileIO FI HumanInterface HI Creature CR Framework FW Table 3.2 Module dependencies Base - - - - - - - - - Foundation - - - - - - - - Collision - - - - - - - Physics - - - - - - Graphics - - - - - - - FileIO - - - - - - - HumanInterface - - - - - - - Creature - - - - - - Framework - - - Physics PHSolid // given PHSolidIf* phscene, PHSolidDesc desc;

20 3 Springhead desc.mass = 1.0; PHSolidIf* solid = phscene->createsolid(desc); PHSolidDesc PHSolid mass CreateSolid CreateSolid PHScene PHScene PHSceneIf CreateSolid PHSolidIf solid->setmass(5.0); Get/Set Springhead delete Create Springhead

21 4 Base Base 4.1 Table 4.1 f d float double double 3 x Vec3d x; [] x[0]; // 0-th element Vec[2 3][f d].x,.y,.z float 10

22 4 Base Table 4.1 Matrix and vector classes Vec[2 3 4][f d] Matrix[2 3 4][f d] Quaternion[f d] Affine[f d] Pose[f d] 3 TVector<10, float> x; // 10-dimensional float vector VVector<float> x; x.resize(10); // can be resized at any time. VVector::resize Vec3d a, b, c; double k; c = a + b; a += b; c = a - b; a -= b; b = k * a; a *= k; k = x * y; x % y; // addition // subtraction // multiply vector by scalar // scalar product // vector product (3D vector only)

4.1 23 a.size(); a.norm(); a.square(); a.unitize(); b = a.unit(); // number of elements // norm // square of norm // normalize // normalized vector double 3 3 A Matrix3d A; [] x[0][1]; // element at 0-th row, 1-th column TMatrixCol<2, 3, float> M; // column-oriented 2x3 matrix TMatrixRow<2, 3, float> M; // row-oriented 2x3 matrix Matrix3d TMatrixCol<3,3,double> VMatrixCol<float> M; M.resize(10, 13); // column-oriented variable matrix

24 4 Base VMatrixCol VMatrixRow Matrix3d M; Vec3d a, b; b = M * a; // multiplication M.height(); M.width(); // number of rows // number of columns 2x2, 3x3 Matrix2d N; Matrix3d M; double theta; Vec3d axis; // methods common to Matrix2[f d] and Matrix3[f d] M = Matrix3d::Zero(); // zero matrix; same as M.clear() M = Matrix3d::Unit(); // identity matrix M = Matrix3d::Diag(x,y,z); // diagonal matrix N = Matrix2d::Rot(theta); // rotation in 2D M = Matrix3d::Rot(theta, x ); M = Matrix3d::Rot(theta, axis); // rotation w.r.t. x-axis // one can specify y and z too // rotation along arbitrary vector Affine[f d] 4x4

4.1 25 Affinef A; Matrix3f R; Vec3f p; R = A.Rot(); p = A.Trn(); // rotation part // translation part A = Affinef::Unit(); A = Affinef::Trn(x, y, z); A = Affinef::Rot(theta, x ); A = Affinef::Rot(theta, axis); A = Affinef::Scale(x, y, z); // identity transformation // translation // rotation w.r.t. x-axis // one can specify y and z too // rotation w.r.t. arbitrary axis // scaling 4 [] Quaterniond q; q.w; q.x; q.y; q.z; q.v(); // same as q[0] // same as q[1] // same as q[2] // same as q[3] // vector composed of x,y,z elements Quaterniond q, q0, q1; q0 = Quaterniond::Rot(Rad(30.0), x ); q1 = Quaterniond::Rot(Rad(-90.0), y ); // 30deg rotation along x-axis // -90deg rotationt along y-axis

26 4 Base q = q1 * q0; 3 Vec3d a(1, 0, 0); Vec3d b = q0 * a; Quaterniond[f d] Vec3d axis = q.axis(); double angle = q.theta(); // rotation axis // rotation angle q.conjugate(); Quaterniond y; y = q.conjugated(); y = q.inv(); // conjugate (reverse rotation) // return conjugated quaternion // return inverse (normalized conjugate) Conjugate Conjugated Inv Conjugated 1 1 Matrix3d R = Matrix3d::Rot(Rad(60.0), z ); q.frommatrix(r); // conversion from rotation matrix q.tomatrix(r); // conversion to rotation matrix

4.1 27 FromMatrix R q ToMatrix R q Vec3d angle; q.toeuler(angle); q.fromeuler(angle); // to Euler angle // from Euler angle 2 2 RotationArc Vec3d r0(1, 0, 0), r1(0, 1, 0); q.rotationarc(r0, r1); // rotation that maps r0 to r1 7 Pose[f d] Pos Ori 2 (Vec3[f d]) (Quaternion[f d]) Posed P; P.Pos() = Vec3d(1, 2, 3); P.Ori() = Quaterniond::Rot(Rad(45.0), x ); Vec3d p = P.Pos(); Quaterniond q = P.Ori(); Vec[2 3 4][f d] Matrix[2 3][f d] Affine[f d] Quaternion[f d]

28 4 Base 4.2 0 delete UTRefCount Springhead UTRefCount UTRef class A : public UTRefCount{}; UTRef<A> a = new A(); // no need to delete a 4.3 UTString std::string UTTypeDesc Springhead UTTreeNode

29 5 Foundation Foundation Springhead Foundation 5.1 Springhead RTTI C++ dynamic cast RTTI IfInfo IfInfo Object 5.2 Springhead Object Springhead Foundation Object Fig. 5.1 Object

30 5 Foundation Object オブジェクト NamedObject 名前付きオブジェクト SceneObject シーンオブジェクト NameManager ネームマネジャ Scene シーン Fig. 5.1 Object class hierarchy ObjectIf size t NChildObject() ObjectIf* GetChildObject(size t pos) pos bool AddChildObject(ObjectIf* o) o true false bool DelChildObject(ObjectIf* o) o true false void Clear(); Springhead

5.3 31 ObjectIf void Print(std::ostream& os) const os Print Print Print NamedObject NamedObject NamedObjectIf const char* GetName() void SetName(const char* n) NameManagerIf* GetNameManager() (PHSolid, GRVisual ) SceneObjectIf SceneIf* GetScene() 5.3

32 5 Foundation NameManagerIf NamedObjectIf* FindObject(UTString name) name NULL Scene (PHScene, GRScene, FWScene ) Scene 5.4 Foundation UTTimer UTTimerIf* timer = UTTimerIf::Create(); UTTimer API [Get Set]Resolution [Get Set]Interval [Get Set]Mode [Get Set]Callback IsStarted IsRunning Start Stop Call SetMode MULTIEDIA THREAD FRAMEWORK IDLE Framework Framework Windows

5.5 33 Sleep FRAMEWORK IDLE FWApp CreateTimer FRAMEWORK GLUT IDLE GLUT Framework FWApp FWApp CreateTimer 5.5 Springhead ObjectStatesIf PHSceneIf* phscene; phscene UTRef<ObjectStatesIf> states; states = ObjectStatesIf::Create(); // ObjectStates states->allocatestate(phscene); // states->savestate(phscene); // phscene->step(); // states->loadstate(phscene); // states->releasestate(); // phscene->step(); // 5.5.1 Springhead (PHScene CRScene) (PHEngine CREngine )

34 5 Foundation 5.5.2 AllocateState(), SaveState(), LoadState() ObjectStatesIf::ReleaseState() ObjectIf::AddChildObject() API

35 6 Collision 6.1 Collision Collision Physics Collision Collision Fig. 6.1 CDShape 6.2 1. 2. 3. // given PHSdkIf* phsdk CDBoxDesc desc; desc.boxsize = Vec3d(1.0, 1.0, 1.0);

36 6 Collision CDShape 凸形状 CDBox CDSphere CDCapsule CDRoundcone CDConvexMesh 直方体球カプセル丸コーン凸メッシュ Fig. 6.1 Class hierarchy of Collision module CDBoxIf* box = phsdk->createshape(desc)->cast(); Physics PHSdk CreateShape PHSdk 7 CDBox 1.0 CreateShape CDShape CDBox Cast // given PHSolidIf* solid solid->addshape(box); // first box PHSolid 7 1 AddShape SetShapePose

6.2 37 Fig. 6.2 Box geometry solid->addshape(box); solid->addshape(box); // second box // third box // move first shape 1.0 in x-direction solid->setshapepose(0, Posed(Vec3d(1.0, 0.0, 0.0), Quaterniond()); // rotate second shape 30 degrees along y-axis solid->setshapepose(1, Posed(Vec3d(), Quaterniond::Rot(Rad(30.0), y ))); SetShapePose 1 AddShape 0 AddShape 1 GetShapePose Springhead (Fig. 6.2) CDBox

38 6 Collision Fig. 6.3 Sphere geometry CDBoxDesc Vec3f boxsize CDBoxIf Vec3f GetBoxSize() void SetBoxSize(Vec3f) (Fig. 6.3) CDSphere CDSphereDesc float radius CDSphereIf float GetRadius() void SetRadius(float) (Fig. 6.4) CDCapsule

6.2 39 Fig. 6.4 Capsule geometry Fig. 6.5 Round cone geometry CDCapsuleDesc float radius float length CDCapsuleIf float GetRadius() void SetRadius(float) float GetLength() void SetLength(float)

40 6 Collision Fig. 6.6 Convex mesh geometry (Fig. 6.5) CDRoundCone CDRoundConeDesc Vec2f radius float length CDRoundConeIf Vec2f GetRadius() void SetRadius(Vec2f) float GetLength() void SetLength(float) void SetWidth(Vec2f) SetWidth (Fig. 6.6) CDConvexMesh

6.3 41 CDConvexMeshDesc vector<vec3f> vertices CDConvexMeshIf Vec3f* GetVertices() int NVertex() CDFaceIf* GetFace(int i) int NFace() i CDConvexMeshDesc::vertices CDFace CDFaceIf int* GetIndices() int NIndex() NIndex 3 4 // given CDConvexMeshIf* mesh CDFaceIf* face = mesh->getface(0); int* idx = face->getindices(); Vec3f v = mesh->getvertices()[idx[0]]; // get 0-th face // get 0-th vertex 6.3 CDShape CDShapeDesc PHMaterial material

42 6 Collision PHMaterial float density float mu0 float mu float e float reflexspring float reflexdamper float frictionspring float frictiondamper CDShapeIf CDShapeIf void SetDensity(float) float GetDensity() void SetStaticFriction(float) float GetStaticFriction() void SetDynamicFriction(float) float GetDynamicFriction() void SetElasticity(float) float GetElasticity() void SetReflexSpring(float) float GetReflexSpring() void SetReflexDamper(float) float GetReflexDamper() void SetFrictionSpring(float) float GetFrictionSpring() void SetFrictionDamper(float) float GetFrictionDamper() 7.7 6.4

6.4 43 CDShapeIf float CalcVolume() Vec3f CalcCenterOfMass() Matrix3f CalcMomentOfInertia() CalcVolume GetDensity CalcCenterOfMass CalcMomentOfInertia 1

45 7 Physics 7.1 Physics 7.2 Physics SDK Physics SDK PHSdk PHSdk PHSdk PHSdkIf* phsdk = PHSdkIf::CreateSdk(); Framework PHSdk PHSdk PHSdkIf CDShapeIf* CreateShape(const CDShapeDesc&) CDShapeIf* GetShape(int) int NShape()

46 7 Physics PHSdk 6 7.3 PHScene PHScene PHSdk PHSdkIf PHSceneIf* CreateScene(const PHSceneDesc& desc) int NScene() PHSceneIf* GetScene(int i) void MergeScene(PHSceneIf* scene0, PHSceneIf* scene1) PHSceneIf* phscene = phsdk->createscene(); MergeScene scene1 scene0 scene1 PHSceneDesc double timestep unsigned count Vec3d gravity double airresistancerate int numiteration LCP

7.3 47 PHSceneIf double void unsigned void void Vec3d void double int void GetTimeStep() SetTimeStep(double) GetCount() SetCount(unsigned) SetGravity(const Vec3d&) GetGravity() SetAirResistanceRate(double) GetAirResistanceRate() GetNumIteration() SetNumIteration() timestep count count timestep gravity airresistancerate airregistancerate 0.95 95% numiteration 1 Step PHSceneIf void Step() 1 Step

48 7 Physics 7.4 PHSolid PHScene PHSceneIf PHSolidIf* CreateSolid(const PHSolidDesc&) int NSolids() PHSolidIf** GetSolids() PHSolidIf* solid = phscene->createsolid(); GetSolids 0 PHSolidIf* solid = phscene->getsolids()[0]; // get 0-th solid PHSolidDesc double mass Matrix3d inertia Vec3d center bool dynamical

7.4 49 PHSolidIf double double void Vec3d void Matrix3d Matrix3d void void void bool GetMass() GetMassInv() SetMass(double) GetCenterOfMass() SetCenterOfMass(const Vec3d&) GetInertia() GetInertiaInv() SetInertia(const Matrix3d&) CompInertia() SetDynamical(bool) IsDynamical() GetMassInv GetInertiaInv CompInertia dynamical dynamical true dynamical false PHSolidDesc Vec3d velocity Vec3d angvelocity Posed pose

50 7 Physics PHSolidIf Vec3d void Vec3d void Posed void Vec3d void Vec3d void Quaterniond void GetVelocity() SetVelocity(const Vec3d&) GetAngularVelocity() SetAngularVelocity(const Vec3d&) GetPose() SetPose(const Posed&) GetFramePosition() SetFramePosition(const Vec3d&) GetCenterPosition() SetCenterPosition(const Vec3d&) GetOrientation() SetOrientation(const Quaterniond&) velocity, angvelocity, pose [Get Set]FramePosition / [Get Set]CenterPosition / [Get Set]Orientation / 3

7.5 51 PHSolidIf void void void Vec3d Vec3d AddForce(Vec3d) AddTorque(Vec3d) AddForce(Vec3d, Vec3d) GetForce() GetTorque() AddForce solid->addforce(vec3d(0.0, -1.0, 0.0)); (0, 1, 0) solid->addtorque(vec3d(1.0, 0.0, 0.0)); (1, 0, 0) solid->addforce(vec3d(0.0, -1.0, 0.0), Vec3d(0.0, 0.0, 1.0)); (0, 1, 0) (0, 0, 1) AddForce AddTorque GetForce GetTorque AddForce 7.5 Fig. 7.1

52 7 Physics PHConstraint 拘束 PHJoint 関節 PHJoint1D 1 自由度関節 PHHingeJoint PHSliderJoint ヒンジスライダ PHPathJoint パスジョイント PHBallJoint ボールジョイント PHSpring バネ PHContactPoint 接触点 Fig. 7.1 Constraint class hierarchy PHSolidIf* solid0 = phscene->getsolids()[0]; PHSolidIf* solid1 = phscene->getsolids()[1]; PHHingeJointDesc desc; desc.posesocket.pos() = Vec3d( 1.0, 0.0, 0.0); desc.poseplug.pos() = Vec3d(-1.0, 0.0, 0.0); PHHingeJointIf* joint = phscene->createjoint(solid0, solid1, desc)->cast(); PHScene CreateJoint CreateJoint PHJointIf* Cast PHScene

7.5 53 (a) before connection (b) after connection Fig. 7.2 Socket and plug PHSceneIf PHJointIf* CreateJoint(PHSolidIf*, PHSolidIf*, const PHJointDesc&) int NJoint() PHJointIf* GetJoint(int i) NJoint GetJoint i Springhead CreateJoint 1 2 posesocket poseplug (1, 0, 0) ( 1, 0, 0) (Fig. 7.2(a)) Fig. 7.2(b) z z

54 7 Physics PHConstraintDesc Posed posesocket Posed poseplug PHConstraintIf PHSolidIf* GetSocketSolid() PHSolidIf* GetPlugSolid() void GetSocketPose(Posed&) void SetSocketPose(const Posed&) void GetPlugPose(Posed&) void SetPlugPose(const Posed&) void GetRelativePose(Posed&) void GetRelativeVelocity(Vec3d&, Vec3d&) void GetConstraintForce(Vec3d&, Vec3d&) GetRelativePose GetRelativeVelocity 1 2 GetConstraintForce ( 1 2 ) Springhead (PHHingeIf) (PHSliderIf) (PHPathJointIf) (PHBallJointIf) (PHSpringIf) 5

7.5 55 Fig. 7.3 Hinge joint 1 Fig 7.3 z y y (x ) API 1 (PH1DJointIf) y position PH1DJointIf double GetPosition() x socket z 1 Fig 7.4 z x y 1 T.B.D.

56 7 Physics Fig. 7.4 Slider joint y y range[0] x socket z x plug z range[1] (a) (b) z socket Fig. 7.5 Ball Joint limitswing[0] limitswing[1] Swing 3 Fig 7.5(a) y Swing-Twist (Fig 7.5(b)) z x x socket z Swing-Dir y position

7.5 57 (Swing) z x-y x (Swing-Dir) z (Twist) Swing-Twist 2 PHBallJoint Quaterniond GetPosition() Vec3d GetAngle() Swing-Twist Fig. 7.6 Spring y y z x socket x socket z

58 7 Physics PHSpringDesc Vec3d spring Vec3d damper double springori double damperori PHConstraintDesc bool benabled / PHConstraintIf void bool Enable(bool) IsEnabled() 1 PHJoint1DDesc double spring double damper double targetposition double targetvelocity double double offsetforce fmax PHJoint1DIf double GetPosition() double GetVelocity() void SetSpring(double)

7.5 59 double GetSpring() void SetDamper(double) double GetDamper() void SetTargetPosition(double) double GetTargetPosition() void SetTargetVelocity(double) double GetTargetVelocity() void SetOffsetForce(double) double GetOffsetForce() void SetTorqueMax(double) double GetTorqueMax() f f = K(p 0 p) + D(v 0 v) + f 0 p v GetPosition GetVelocity K D p 0 v 0 f 0 spring damper targetposition targetvelocity offsetforce PD K D p 0 v 0 K P D D p 0 v 0 f 0 ±fmax PD targetposition targetvelocity

60 7 Physics PHBallJointDesc double spring double damper Quaterniond targetposition Vec3d targetvelocity Vec3d offsetforce double fmax CreateLimit 1 Vec2d range range[0] range[1] range[0] < range[1] range[0] > range[1] spring damper tips spring damper 1 PH1DJointLimitDesc Vec2d range range[0] range[1] double spring double damper

7.5 61 PH1DJointLimitIf IsOnLimit() true true Fig 7.5(b) Swing-Twist 2 ConeLimit SplineLimit z ConeLimit (SplineLimit ) PHBallJointConeLimitDesc Vec2d limitswing ( ) limitswing[0] limitswing[1] limitswing API PHBallJointConeLimitIf::[Set Get]SwingRange(range) limitswing[0] > limitswing[1] limitswing[0] > limitswing[1] Vec2d limittwist limittwist[0] limittwist[1] limittwist API PHBallJointConeLimitIf::[Set Get]TwistRange(range) limittwist[0] > limittwist[1]

62 7 Physics limittwist[0] > limittwist[1] double spring double damper 1 PHBallJointConeLimitIf IsOnLimit() true 1 7.6 (IK) Springhead IK 1 Springhead IK 3 IK IK

7.6 63 // given PHSceneIf* phscene // given PHSolidIf* solid1, solid2, solid3 // given PHHingeJointIf* joint1 (solid1 <-> solid2) // given PHHingeJointIf* joint2 (solid2 <-> solid3) PHIKHingeActuatorDesc descikactuator; PHIKHingeActuatorIf* ikactuator1 = phscene->createikactuator(descikactuator); ikactuator1.addchildobject(joint1); PHIKHingeActuatorIf* ikactuator2 = phscene->createikactuator(descikactuator); ikactuator1.addchildobject(joint2); PHIKHingeActuatorIf PHHingeJointIf ikactuator1.addchildobject(ikactuator2); IK PHIKEndEffectorDesc descendeffector; PHIKEndEffectorIf* ikendeffector1 = phscene->createikendeffector(descendeffector); ikendeffector1.addchildobject(solid3); ikactuator2.addchildobject(ikendeffector1); solid1 -(joint1)-> solid2 -(joint2)-> solid3

64 7 Physics solid3 joint2 ikactuator2 IK IK // solid3 goes to (2, 5, 0) ikendeffector1->settargetposition(vec3d(2, 5, 0)); phscene->getikengine()->enable(true);... phscene->step(); // IK is calculated in physics step... IK IK PHScene IK (PHIKEngine) IK phscene->getikengine()->enable(true); GetIKEngine() PHScene IK API Springhead IK θ

7.6 65 r J r = J θ J r = 1 // 20 iteration per 1 physics step phscene->getikengine()->setnumiter(20); PHSceneIf PHIKEngineIf* GetIKEngine() IK PHIKEngineIf Enable(bool b) IK true false SetNumIter(int n) IK 1 n Springhead IK IK IK IK IK IK

66 7 Physics IK PHIKHingeActuator PHHingeJoint 1 PHIKBallActuator PHBallJoint 3 ( ) 2 ( 2 1 ) // given PHSceneIf* phscene PHIKHingeActuatorDesc descikactuator; PHIKHingeActuatorIf* ikactuator = phscene->createikactuator(descactuator); PHSceneIf CreateIKActuator PHIKHingeActuatorDesc PHIKBallActuatorDesc // given PHHingeJointIf* joint ikactuator->addchildobject(joint);

7.6 67 IK Springhead // given PHIKActuator ikactuator1, ikactuator2 ikactuator1->addchildobject(ikactuator2); AddChildObject IK IK SetTargetVelocity damper damper IK IK IK Springhead IK // given PHIKActuator ikactuator1, ikactuator2 ikactuator1->setbias(2.0); ikactuator2->setbias(1.0);

68 7 Physics SetBias Bias 1.0 IK 1.0 IK PHSceneIf CreateIKEndEffector PHIKEndEffectorDesc // given PHSceneIf* phscene PHIKEndEffectorDesc descendeffector; PHIKEndEffectorIf* ikendeffector = phscene->createikendeffector(descendeffector); AddChildObject // given PHSolidIf* solid ikendeffector.addchildobject(solid); // given PHIKActuatorIf* ikactuatorparent ikactuatorparent.addchildobject(ikendeffector);

7.6 69 IK IK SetTargetPosition // solid3 goes to (2, 5, 0) ikendeffector->settargetposition(vec3d(2, 5, 0)); ikendeffector->settargetorientation( Quaterniond::Rot( x, rad(30)) ); ikendeffector->enableorientationcontrol(true); Quaterniond EnableOrientationControl EnablePositionControl EnableOrientationControl // ikendeffector->enablepositioncontrol(true); ikendeffector->enableorientationcontrol(false); // ikendeffector->enablepositioncontrol(false); ikendeffector->enableorientationcontrol(true); // ikendeffector->enablepositioncontrol(true);

70 7 Physics Fig. 7.7 Contact configuration ikendeffector->enableorientationcontrol(true); 7.7 Springhead 7.3 PHSceneIf::Step 1 Fig. 7.7 x y z x y v x < V th v x V th

7.7 71 v x x V th 1 v x e v x = e v x (7.1) d 1 1 d d = d γmax(d d tol, 0) (7.2) γ d tol x f x f x 0 y f y z f z µ 0 f x f y µ 0 f x if V f v y V f, µf x f y µf x otherwise µ 0 µ V f z CDShapeIf void SetElasticity(float e) float GetElasticity() void SetStaticFriction(float mu0) float GetStaticFriction() void SetDynamicFriction(float mu) float GetDynamicFriction()

72 7 Physics PHSceneIf void SetContactTolerance(double tol) double GetContactTolerance() void SetImpactThreshold(double vth) double GetImpactThreshold() void SetFrictionThreshold(double vf) double GetFrictionThreshold() y z y z Springhead // given PHSceneIf* scene // given PHSolidIf* solid Vec3d fsum; Vec3d tsum; //< sum of contact forces applied to "solid" //< sum of contact torques applied to "solid" int N = scene->ncontacts(); Vec3d f, t; Posed pose; for(int i = 0; i < N; i++){

7.7 73 PHContactPointIf* con = scene->getcontact(i); con->getconstraintforce(f, t); } if(con->getsocketsolid() == solid){ con->getsocketpose(pose); fsum -= pose.ori() * f; tsum -= pose.pos() % pose.ori() * f; } if(con->getplugsolid() == solid){ con->getplugpose(pose); fsum += pose.ori() * f; tsum += pose.pos() % pose.ori() * f; } PHSceneIf::NConstacts for i PHSceneIf::GetContact PHConstraintIf::GetConstraintForce f t 0 / / / Springhead PHSceneIf::SetContactMode PHSceneIf void void void void SetContactMode(PHSolidIf* lhs, PHSolidIf* rhs, int mode) SetContactMode(PHSolidIf** group, size t length, int mode) SetContactMode(PHSolidIf* solid, int mode) SetContactMode(int mode)

74 7 Physics lhs rhs [group, group + length) solid PHSceneDesc::ContactMode MODE NONE MODE LCP MODE PENALTY MODE LCP // given PHSolidIf* floor scene->setcontactmode(phscenedesc::mode_none); scene->setcontactmode(floor, PHSceneDesc::MODE_LCP); 7.8 T.B.D. 7.9 T.B.D.

7.10 75 7.10 PHConstraintEngineIf PHConstraintEngineIf PHConstraintEngineIf void SetVelCorrectionRate(double) double GetVelCorrectionRate() void SetContactCorrectionRate(double) double GetContactCorrectionRate() 1 [0, 1] 1 1 0 PHSceneIf::SetNumIteration 7.3 PHSceneIf::SetContactTolerance PHConstraintEngineIf::SetContactCorrectionRate 7.10

77 8 Graphics 8.1 Graphics 3D 8.2 Graphics SDK Graphics SDK GRSdk GRSdk GRSdk GRSdkIf* grsdk = GRSdkIf::CreateSdk(); Framework GRSdk GRSdk GRRender Springhead OpenGL OpenGL GRDeviceGL GRSdk

78 8 Graphics GRSdkIf GRRenderIf* CreateRender() GRDeviceGLIf* CreateDeviceGL() OpenGL GRRenderIf void SetDevice(GRDeviceIf*) GRDeviceIf* GetDevice() Graphics GRRenderIf* render = grsdk->createrender(); GRDeviceIf* device = grsdk->createdevicegl(); device->init(); render->setdevice(device); GRRender SetDevice Framework 8.3 Graphics GRScene GRSceneIf* grscene = grsdk->createscene(); GRScene Fig. 8.1 GRSdk GRSdk

8.3 79 Graphics SDK (GRSdk) scene 0 (GRScene) world (GRFrame) array of scenes array of visuals light (GRLight) mesh (GRMesh) frame (GRFrame) mesh mesh frame frame (GRFrame) camera (GRCamera) scene 1 (GRScene) scene N (GRScene) Fig. 8.1 Graphics data structure GRSdkIf GRSceneIf* CreateScene() GRSceneIf* GetScene(size t) size t NScene() void MergeScene(GRSceneIf*, GRSceneIf*) FileIO GRScene

80 8 Graphics GRSceneIf GRFrameIf* GetWorld() GRCameraIf* GetCamera() void SetCamera(const GRCameraDesc&) GRVisualIf* CreateVisual(const GRVisualDesc&, GRFrameIf*) void Render(GRRenderIf*) Fig. 8.1 1 1 GetWorld GRScene (Fig. 8.1) SetCamera GetCamera 1 GLUT glutdisplayfunc Framework FWApp Display render->clearbuffer(); render->beginscene(); // clear back buffer // begin rendering grscene->render(render); // render scene render->endscene(); render->swapbuffers(); // end rendering // swap buffers ClearBuffer / GRRender GetClearColor SetClearColor render->setclearcolor(vec4f(1.0f, 0.0f, 0.0f, 1.0f));

8.4 81 GRVisual 描画アイテム GRFrame GRMesh GRCamera GRLight GRMaterial フレーム ポリゴンメッシュ カメラ ライト マテリアル Fig. 8.2 Class hierarchy of visual items render->clearbuffer(); // clear back buffer in red BeginScene EndScene SwapBuffers GRScene Render (GRCamera) Render (GRFrame) Render 8.4 GRVisual GRVisual Fig. 8.2 GRVisualIf void void void bool Render(GRRenderIf*) Rendered(GRRenderIf*) Enable(bool) IsEnabled() Render Rendered Enable / IsEnabled / GRScene CreateVisual

82 8 Graphics 8.5 GRFrame GRFrameDesc desc; GRFrameIf* frame = grscene->createvisual(desc, grscene->getworldframe())->cast(); CreateVisual CreateVisual(desc) GRFrame Render Render GRFrameIf GRFrameIf* void int GRVisualIf** GetParent() SetParent(GRFrameIf*) NChildren() GetChildren() GetParent SetParent NChildren GetChildren

8.6 83 (a) Perspective frustum size.x y camera frame center.y x center.x size.y (b) Front view of screen Fig. 8.3 (c) Top view of screen Camera parameters GRFrameIf Affinef Affinef void GetTransform() GetWorldTransform() SetTransform(const Affinef&) GetTransform SetTransform / frame->settransform(affinef::trn(1.0, 0.0, 0.0)); x 1.0

84 8 Graphics 8.6 GRCameraDesc Vec2f size Vec2f center float front float back Fig. 8.3(b),(c) GRCameraDesc desc; grscene->getcamera()->getdesc(&desc); desc.front = 3.0f; grscene->setcamera(desc); GetDesc front SetCamera GRCamera GRCameraIf GRFrameIf* void GetFrame() SetFrame(GRFrameIf*) GetFrame SetFrame / Fig. 8.3(a) 8.7 GRLight

8.8 85 GRLightDesc Vec4f ambient Vec4f diffuse Vec4f specular Vec4f position OpenGL position 4 position.w 0 (x,y,z) position.w 1 (x,y,z) 8.8 GRMaterial GRMaterial GRMaterialDesc Vec4f ambient Vec4f diffuse Vec4f specular Vec4f emissive float power UTString texname GRMaterialIf Render : GRRender GRRenderIf void SetMaterial(const GRMaterialDesc&) void SetMaterial(const GRMaterialIf*) void SetMaterial(int)

86 8 Graphics 3 // given GRRenderIf* render, GRSceneIf* scene GRMaterialDesc md; md.diffuse = Vec4f(1.0f, 0.0f, 0.0f, 1.0f); // 1. render->setmaterial(md); // 2. GRMaterialIf* mat = scene->createvisual(md)->cast(); mat->render(render); // 3. render->setmaterial(mat); // 4. render->setmaterial(grrenderbaseif::red); X11 web color SprGRRender.h GRRenderBaseIf 24 Table 8.1 8.9 GRMesh FileIO Direct3D X 9 FWObjectIf::LoadMesh

8.9 87 GRMeshDesc vector<vec3f> vertices vector<grmeshface> faces vector<vec3f> normals vector<grmeshface> facenormals vector<vec4f> colors vector<vec2f> texcoords vector<int> materiallist vector C++ vertices faces GRMeshFace GRMeshFace int nvertices int indices[4] nvertices 1 3 4 indices nvertices vertices[faces[i].indices[j]] i j GRMeshDesc vertices faces normals normals[i] vertices[i] normals normals facenormals normals[facenormals[i].indices[j]] i j colors colors[i] i texcoords UV

88 8 Graphics materiallist materiallist[i] i AddChildObject // given GRSceneIf* scene, GRFrameIf* frame GRMeshDesc meshdesc; //... setup discriptor here... // create mesh and attach it to frame GRMeshIf* mesh = scene->createvisual(meshdesc, frame)->cast(); GRMaterialDesc matdesc0, matdesc1; //... setup materials here... GRMaterialIf* mat0 = scene->createvisual(matdesc0, frame)->cast(); GRMaterialIf* mat1 = scene->createvisual(matdesc1, frame)->cast(); // attach materials to mesh mesh->addchildobject(mat0); mesh->addchildobject(mat1); //< material no.0 //< material no.1 0 8.10

8.10 89 8.3 GRRenderIf void GetClearColor(Vec4f&) void SetClearColor(const Vec4f&) void ClearBuffer() void BeginScene() void EndScene() void SwapBuffers() GRMesh GRRenderIf int StartList() void EndList() void DrawList(int) void ReleaseList(int) GRRenderIf void SetDepthWrite(bool) On/Off void SetDepthTest(bool) On/Off void SetDepthFunc(TDepthFunc) void SetAlphaTest(bool) On/Off void SetAlphaMode(TBlendFunc, TBlendFunc) void SetLighting(bool) On/Off

90 8 Graphics GRRenderIf int LoadTexture(UTString) void SetTextureImage(UTString, int, int, int, int, char*) GRRenderIf void InitShader() void SetShaderFormat(ShaderType) bool CreateShader(UTString, UTString, GRHandler&) GRHandler CreateShader() bool ReadShaderSource(GRHandler, UTString) void GetShaderLocation(GRHandler, void*) GRRenderIf void SetVertexFormat(const GRVertexElement*) void SetVertexShader(void*) void DrawDirect(TPrimitiveType, void*, size t, size t) void DrawIndexed(TPrimitiveType, size t*, void*, size t, size t) void DrawArrays(TPrimitiveType, GRVertexArray*, size t) void DrawArrays(TPrimitiveType, size t*, GRVertexArray*, size t)

8.10 91 GRRenderIf void DrawLine(Vec3f, Vec3f) void DrawArrow(Vec3f, Vec3f, float, float, float, int, bool) void DrawBox(float, float, float, bool) void DrawSphere(float, int, int, bool) void DrawCone(float, float, int, bool) void DrawCylinder(float, float, int, bool) void DrawCapsule(float, float, int, bool) void DrawRoundCone(float, float, float, int, bool) void DrawGrid(float, int, float) void SetFont(const GRFont&) void DrawFont(Vec2f, UTString) 2 void DrawFont(Vec3f, UTString) 3 void SetLineWidth(float) GRRenderIf void SetCamera(const GRCameraDesc&) const GRCameraDesc& GetCamera() GRRenderIf void PushLight(const GRLightDesc&) void PushLight(const GRLightIf*) void PopLight() int NLights()

92 8 Graphics GRRenderIf void Reshape(Vec2f, Vec2f) void SetViewport(Vec2f, Vec2f) Vec2f GetViewportPos() Vec2f GetViewportSize() Vec2f GetPixelSize() 1 Vec3f ScreenToCamera(int, int, float, bool) void EnterScreenCoordinate() void LeaveScreenCoordinate() GRRenderIf void SetViewMatrix(const Affinef&) void GetViewMatrix(Affinef&) void SetProjectionMatrix(const Affinef&) void GetProjectionMatrix(Affinef&) void SetModelMatrix(const Affinef&) void GetModelMatrix(Affinef&) void MultModelMatrix(const Affinef&) void PushModelMatrix() void PopModelMatrix() void ClearBlendMatrix() bool SetBlendMatrix(const Affinef&, int)

8.10 93 Table 8.1 Reserved colors INDIANRED (205 92 92) LIGHTCORAL (240 128 128) SALMON (250 128 114) DARKSALMON (233 150 122) LIGHTSALMON (255 160 122) RED (255 0 0) CRIMSON (220 20 60) FIREBRICK (178 34 34) DARKRED (139 0 0) PINK (255 192 203) LIGHTPINK (255 182 193) HOTPINK (255 105 180) DEEPPINK (255 20 147) MEDIUMVIOLETRED (255 21 133) PALEVIOLETRED (255 112 147) CORAL (255 127 80) TOMATO (255 99 71) ORANGERED (255 69 0) DARKORANGE (255 140 0) ORANGE (255 165 0) GOLD (255 215 0) YELLOW (255 255 0) LIGHTYELLOW (255 255 224) LEMONCHIFFON (255 250 205) LIGHTGOLDENRODYELLOW (250 250 210) PAPAYAWHIP (255 239 213) MOCCASIN (255 228 181) PEACHPUFF (255 218 185) PALEGOLDENROD (238 232 170) KHAKI (240 230 140) DARKKHAKI (189 183 107) LAVENDAR (230 230 250) THISTLE (216 191 216) PLUM (221 160 221) VIOLET (238 130 238) ORCHILD (218 112 214) FUCHSIA (255 0 255) MAGENTA (255 0 255) MEDIUMORCHILD (186 85 211) MEDIUMPURPLE (147 112 219) BLUEVIOLET (138 43 226) DARKVIOLET (148 0 211) DARKORCHILD (153 50 204) DARKMAGENTA (139 0 139) PURPLE (128 0 128) INDIGO (75 0 130) DARKSLATEBLUE (72 61 139) SLATEBLUE (106 90 205) MEDIUMSLATEBLUE (123 104 238) GREENYELLOW (173 255 47) CHARTREUSE (127 255 0) LAWNGREEN (124 252 0) LIME (0 255 0) LIMEGREEN (50 205 50) PALEGREEN (152 251 152) LIGHTGREEN (144 238 144) MEDIUMSPRINGGREEN (0 250 154) SPRINGGREEN (0 255 127) MEDIUMSEAGREEN (60 179 113) SEAGREEN (46 139 87) FORESTGREEN (34 139 34) GREEN (0 128 0) DARKGREEN (0 100 0) YELLOWGREEN (154 205 50) OLIVEDRAB (107 142 35) OLIVE (128 128 0) DARKOLIVEGREEN (85 107 47) MEDIUMAQUAMARINE (102 205 170) DARKSEAGREEN (143 188 143) LIGHTSEAGREEN (32 178 170) DARKCYAN (0 139 139) TEAL (0 128 128) AQUA (0 255 255) CYAN (0 255 255) LIGHTCYAN (224 255 255) PALETURQUOISE (175 238 238) AQUAMARINE (127 255 212) TURQUOISE (64 224 208) MEDIUMTURQUOISE (72 209 204) DARKTURQUOISE (0 206 209) CADETBLUE (95 158 160) STEELBLUE (70 130 180) LIGHTSTEELBLUE (176 196 222) POWDERBLUE (176 224 230) LIGHTBLUE (173 216 230) SKYBLUE (135 206 235) LIGHTSKYBLUE (135 206 250) DEEPSKYBLUE (0 191 255) DODGERBLUE (30 144 237) CORNFLOWERBLUE (65 105 225) ROYALBLUE (65 105 225) BLUE (0 0 255) MEDIUMBLUE (0 0 205) DARKBLUE (0 0 139) NAVY (0 0 128) MIDNIGHTBLUE (25 25 112) CORNSILK (255 248 220) BLANCHEDALMOND (255 235 205) BISQUE (255 228 196) NAVAJOWHITE (255 222 173) WHEAT (245 222 179) BURLYWOOD (222 184 135) TAN (210 180 140) ROSYBROWN (188 143 143) SANDYBROWN (244 164 96) GOLDENROD (218 165 32) DARKGOLDENROD (184 134 11) PERU (205 133 63) CHOCOLATE (210 105 30) SADDLEBROWN (139 69 19) SIENNA (160 82 45) BROWN (154 42 42) MAROON (128 0 0) WHITE (255 255 255) SNOW (255 250 250) HONEYDEW (240 255 240) MINTCREAM (245 255 250) AZURE (240 255 255) ALICEBLUE (240 248 255) GHOSTWHITE (248 248 255) WHITESMOKE (245 245 245) SEASHELL (255 245 238) BEIGE (245 245 220) OLDLACE (253 245 230) FLORALWHITE (255 250 240) IVORY (255 255 240) ANTIQUEWHITE (250 235 215) LINEN (250 240 230) LAVENDERBLUSH (255 240 245) MISTYROSE (255 228 225) GAINSBORO (220 220 220) LIGHTGRAY (211 211 211) SILVER (192 192 192) DARKGRAY (169 169 169) GRAY (128 128 128) DIMGRAY (105 105 105) LIGHTSLATEGRAY (119 136 153) SLATEGRAY (112 128 144) DARKSLATEGRAY (47 79 79) BLACK (0 0 0)

95 9 FileIO 9.1 FileIO Framework 9.2 FileIO SDK FileIO SDK FISdk FISdk FISdk FISdkIf* fisdk = FISdkIf::CreateSdk(); Framework FISdk FISdk 2 FIFile (Fig??) FISdk

96 9 FileIO FIFile ファイル FIFileSpr FIFileBinary FIFileX FIFileVRML FIFileCollada Springhead 専用テキストフォーマット Springhead 専用バイナリフォーマット Direct X VRML COLLADA Fig. 9.1 Class hierarchy of file objects FISdkIf FIFileSprIf* FIFileBinaryIf* FIFileXIf* FIFileVRMLIf* FIFileCOLLADAIf* FIFileIf* CreateFileSpr() CreateFileBinary() CreateFileX() CreateFileVRML() CreateFileCOLLADA() CreateFileFromExt(UTString filename) CreateFileFromExt filename 9.3 Springhead 9.3.1 spr.spr Springhead Springhead spr spr PHSdk{ CDSphere sphere{ material = { mu = 0.2 } #PHSdk # CDSphere # CDSphere material(phmaterial ) # mu 0.2

9.3 97 } radius = 0.5 # radius 0.5 } CDBox bigbox{ boxsize = 2.0 1.1 0.9 } Spr?? ) PHSdk sphere(cdsphere ) CDSphereDesc desc; desc.material.mu = 0.2; desc.radius = 0.5; desc Spr BNF spr = node* node = node type, (node id)?, block block = { (node refer data)* } refer = * node id data = field id, =, (block right) right = [ value*, ] value value = bool int real str right right field 9.3.2 X X Direct3D.x XSI 3D Springhead2 X Springhead2 Spr

98 9 FileIO X xof 0302txt 0064 # # # { } # PHScene scene1{ 0.01;0;; # ; 1;0;-9.8;0;; # PHSolid sofloor{ # ( ) } } # # // Springhead2?? SprPHScene.h struct PHSceneState{ double timestep; ///< unsigned count; ///< }; struct PHSceneDesc:PHSceneState{ /// enum ContactMode{ MODE_NONE, MODE_PENALTY, MODE_LCP}; Vec3f gravity; ///< (0.0f, -9.8f,0.0f) }; PHSceneDesc X

9.4 99 PHScene scene1{ 0.01; 0;; #PHSceneState::count ; PHSceneState 1; #PHSceneDesc::ContactMode 0;-9.8;0;;#PHSceneDesc::gravity ; PHSceneDesc } TBU: X Springhead2 X X Frame{ FrameTransfromMatrix{ 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1; } } Sprinhead2 GRFrame PHFrame TBW (pagenodedeflist) 9.4 Fig 9.2

100 9 FileIO Fig. 9.2 Overview of file operation 9.4.1 FIFileSpr FIFileX FIFile LoadImp() boost::spirit Init() FILoadContext fieldits SWIG??Sdk::RegisterSdk() FILoadContext::datas LoadImp() FIFile::Load(FILoadContext*) ( )

9.4 101 FILoadContext::CreateScene() SDK SDK FIFile::Load(ObjectIfs& objs, const char* fn) objs AddChildObject() AddChildObject() 9.4.2 Framework virtual void FWMyApp::Init(int argc, char* argv[]){ UTRef<ImportIf> import = GetSdk()->GetFISdk()->CreateImport(); GetSdk()->LoadScene(fileName, import); // GetSdk()->SaveScene("save.spr", import);// FISdk int main(){ // SDK PHSdkIf::RegisterSdk(); GRSdkIf::RegisterSdk(); FWSdkIf::RegisterSdk(); // UTRef<FISdkIf> fisdk = FISdkIf::CreateSdk(); FIFileIf* file = fisdk->createfilefromext(".spr"); ObjectIfs objs; //

102 9 FileIO fwsdk = FWSdkIf::CreateSdk(); // FWSDK // fwsdk objs.push_back(fwsdk); // FWSDK if (! file->load(objs, "test.spr") ) { DSTR << "Error: Cannot open load file. " << std::endl; exit(-1); } // objs for(unsigned i=0; i<objs.size(); ++i){ objs[i]->print(dstr); }... 9.4.3 FIFile GetDescAddress() GetDesc() 2 2 FiFileSpr FiFile 9.4.4 Framework virtual void FWMyApp::Save(const char* filename){ UTRef<ImportIf> import = GetSdk()->GetFISdk()->CreateImport(); GetSdk()->SaveScene(filename, import); // filename FISdk

9.5 103 void save(const char* filename, ImportIf* ex, ObjectIf* rootnode){ // UTRef<FISdkIf> fisdk = FISdkIf::CreateSdk(); FIFileIf* file = fisdk->createfilefromext(".spr"); ObjectIfs objs; // objs.push_back(rootnode); file->setimport(ex); file->save(*objs, filename); } 9.5 T.B.W. Import Import Import by )

105 10 HumanInterface 10.1 HumanInterface HumanInterface Framework 10.2 HumanInterface SDK HumanInterface SDK HISdk HISdk HISdk HISdkIf* hisdk = HISdkIf::CreateSdk(); Framework HISdk 10.3 HumanInterface Fig. 10.1 Win32 A/D

106 10 HumanInterface Sdk HISdk HumanInterface SDK NamedObject HIBase HIPose ヒューマンインタフェース 6 自由度操作インタフェース HIHaptic 力覚提示インタフェース HIDevice デバイス HIRealDevice HIVirtualDevice 実デバイス 仮想デバイス Fig. 10.1 HumanInterface class hierarchy HISdk HumanInterface SDK ヒューマンインタフェースプール HIBase ヒューマンインタフェース HIVirtualDevice 利用される仮想デバイス デバイスプール HIRealDevice 実デバイス HIVirtualDevice 提供される仮想デバイス Fig. 10.2 HumanInterface module data structure 1 A/D HumanInterface Fig. 10.2 HISdk

10.3 107 1. 2. 2 HISdk HISdkIf HIRealDeviceIf* HIRealDeviceIf* HIRealDeviceIf* AddRealDevice(const IfInfo* ii, const void* desc = NULL) FindRealDevice(const char* name) FindRealDevice(const IfInfo* ii) AddRealDevice ii desc FindRealDevice GLUT hisdk->findrealdevice(drkeymouseglutif::getifinfostatic()); HISdk HIRealDevice 2 HISdkIf HIVirtualDeviceIf* bool RentVirtualDevice(const IfInfo* ii, const char* name, int portno) ReturnVirtualDevice(HIVirtualDeviceIf* dev) RentVirtualDevice name portno ReturnVirtualDevice

108 10 HumanInterface HIRealDeviceIf HIVirtualDeviceIf* bool Rent(const IfInfo* ii, const char* name, int portno) Return(HIVirtualDeviceIf* dev) 10.4 Springhead 10.5 1 DVKeyMouse Win32 API DRKeyMouseWin32 GLUT DRKeyMouseGLUT Ascii DVKeyCode

10.5 109 DVKeyCode ESC F1 - F12 LEFT UP RIGHT DOWN PAGE UP PAGE DOWN HOME END INSERT Page Up Page Down Home End Insert DVKeyMouse DVKeyMouseCallback DVKeyMouseCallback FWApp DVKeyMouseCallback virtual bool OnMouse(int button, int state, int x, int y) / virtual bool OnDoubleClick(int button, int x, int y) virtual bool / OnMouseMove(int button, int x, int y, int zdelta) virtual bool OnKey(int state, int key, int x, int y) /

110 10 HumanInterface OnMouse button DVButtonMask OR state DVButtonSt x y // inside your class definition... virtual bool OnMouse(int button, int state, int x, int y){ if(button & DVButtonMask::LBUTTON && state == DVButtonSt::DOWN){ // do something here } } OnDoubleClick OnMouse OnMouseMove button OnMouse x, y zdelta OnKey state DVKeySt key DVButtonMask LBUTTON RBUTTON MBUTTON SHIFT CONTROL ALT Shift Ctrl Alt DVButtonSt DOWN UP

10.5 111 DVKeySt PRESSED TOGGLE ON API DVKeyMouse DVKeyMouseIf void void int void AddCallback(DVKeyMouseCallback*) RemoveCallback(DVKeyMouseCallback*) GetKeyState(int key) GetMousePosition(int& x, int& y, int& time, int count=0) AddCallback RemoveCallback GetKeyState DVKeyCode DVKeySt GetMousePosition count count 0 63 x, y time OnMouseMove DRKeyMouseWin32 freeglut Springhead DRKeyMouseGLUT OnKey DRKeyMouseWin32 GetKeyState DRKeyMouseWin32 GetMousePosition DRKeyMouseWin32

112 10 HumanInterface Fig. 10.3 Trackball 10.6 DVJoyStick GLUT DRJoyStickGLUT T.B.D. 10.7 6 API API Fig. 10.3

10.7 113 HITrackballDesc Vec3f target float longitude [rad] float latitude [rad] float distance HITrackballIf Vec3f void void void float void GetTarget() SetTarget(Vec3f) GetAngle(float& lon, float& lat) SetAngle(float lon, float lat) GetDistance() SetDistance(float dist) HITrackballDesc Vec2f lonrange Vec2f latrange Vec2f distrange HITrackballIf void void void void void void GetLongitudeRange(float& rmin, float& rmax) SetLongitudeRange(float rmin, float rmax) GetLatitudeRange(float& rmin, float& rmax) SetLatitudeRange(float rmin, float rmax) GetDistanceRange(float& rmin, float& rmax) SetDistanceRange(float rmin, float rmax)

114 10 HumanInterface HITrackballIf DVKeyMouseIf* void void GetKeyMouse() SetKeyMouse(DVKeyMouseIf*) SetCallback(HITrackballCallback*) DVKeyMouse SetKeyMouse GetKeyMouse HITrackballCallback SetCallback HITrackballCallback HITrackballCallback virtual void OnUpdatePose(HITrackballIf* tb) OnUpdatePose tb HITrackball DVKeyMouseCallback SetKeyMouse DVKeyMouse OnMouseMove HITrackballDesc int rotmask int zoommask int trnmask

10.7 115 HITrackballIf void void void SetRotMask(int mask) SetZoomMask(int mask) SetTrnMask(int mask) rotmask, zoommask, trnmask OnMouseMove button button rotmask rotmask zoommask trnmask x trnmask y rotmask zoommask trnmask LBUTTON RBUTTON LBUTTON + ALT [ALT] + HITrackballDesc float rotgain [rad/pixel] float zoomgain [rad/pixel] float trngain

116 10 HumanInterface HITrackballIf float GetRotGain() void SetRotGain(float g) float GetZoomGain() void SetZoomGain(float g) float GetTrnGain() void SetTrnGain(float g) // given GRRenderIf* render render->setviewmatrix(trackball->getaffine().inv()); 10.8 Spidar Spidar 3 6 T.B.D.

117 11 Creature Creature Springhead IK Creature : 11.1 Creature Creature CRCreature +-- CRBody +-- CRBodyPart (CRObject) +-- CREngine +-- CRController CRCreature 1 CRBody

118 11 Creature CRBodyPart 2 IK 4 CREngine CRCreature Step 1 CRCreature CREngine Step CRController CREngine CRController

119 12 Framework 12.1 Framework Framework Fig. 12.1 FWApp FWApp FWApp (FWWin) Framework SDK (FWSdk) (FWGraphicsAdaptee) FWWin GUI FWSdk SDK Framework (FWScene)

120 12 Framework FWApp アプリケーションクラス FWGraphicsAdaptee GRDevice DRKeyMouse DRJoyStick FWWin GRRender FWScene DVKeyMouse DVJoyStick ウィンドウ グラフィクスデバイス キーボード マウスデバイス ジョイスティックデバイス ウィンドウに関連づけられたレンダラ ウィンドウに関連づけられたシーン 仮想キーボード マウス 仮想ジョイスティック FWSdk PHSdk GRSdk FISdk HISdk FWScene PHScene GRScene Framework SDK Physics SDK Graphics SDK FileIO SDK HumanInterface SDK Frameworkシーン Physicsシーン Graphicsシーン HITrackball HIDragger トラックボール ドラッガ Fig. 12.1 Framework data structure 12.2 Framework SDK Framework SDK FWSdk FWSdk FWSdk FWSdkIf* fwsdk = FWSdkIf::CreateSdk(); FWSdk PHSdk GRSdk FISdk HISdk SDK

12.3 Framework 121 Framework SDK (FWSdk) Physics SDK (PHSdk) Graphics SDK (GRSdk) scene (FWScene) object (FWObject) scene (PHScene) solid (PHSolid) scene (GRScene) world (GRFrame) frame (GRFrame) object (FWObject) solid (PHSolid) frame (GRFrame) Fig. 12.2 Data structure of Framework, Physics and Graphics modules FWSdkIf PHSdkIf* GetPHSdk() Physics SDK GRSdkIf* GetGRSdk() Graphics SDK FISdkIf* GetFISdk() FileIO SDK HISdkIf* GetHISdk() HumanInterface SDK 12.3 Framework Framework 1 Physics Graphics Fig. 12.2 3 SDK FWSdk FWScene FWObject Fig. 12.2 Physics Graphics

122 12 Framework Graphics FWSdk HITrackballIf FWSceneIf* CreateScene(const PHSceneDesc&, const GRSceneDesc&) int NScene() FWSceneIf* GetScene(int i) i void MergeScene(FWSceneIf* scene0, FWSceneIf* scene1) scene1 scene0 FWSceneIf* fwscene = fwsdk->createscene(); FWScene PHScene GRScene FWScene CreateScene NScene GetScene GetScene fwsdk->createscene(); fwsdk->createscene(); FWSceneIf *fwscene0, *fwscene1; fwscene0 = fwsdk->getscene(0); fwscene1 = fwsdk->getscene(1); // create two scenes // get 1st scene // get 2nd scene MergeScene 2 1

12.3 Framework 123 fwsdk->mergescene(fwscene0, fwscene1); scene1 FWObject scene0 PHScene GRScene MergeScene FWScene FWSceneIf void SetPHScene(PHSceneIf*) PHSceneIf* GetPHScene() void SetGRScene(GRSceneIf*) GRSceneIf* GetGRScene() FWObjectIf* CreateFWObject() int NObject()const FWObjectIf** GetObjects() void Sync(bool) Physics Physics Graphics Graphics [Set Get][PH GR]Scene PHScene GRScene CreateFWObject FWObject FWObject PHSolid GRFrame 1 FWObjectIf* fwobj = fwscene->createfwobject(); fwobj->setphsolid(fwscene->getphscene()->createsolid()); fwobj->setgrframe( fwscene->getgrscene()->createvisual(grframedesc())->cast); Sync PHScene GRScene fwscene->sync(true);

124 12 Framework PHScene GRScene FWObject fwscene->sync(false); 12.4 FileIO FWSdkIf bool LoadScene(UTString path, ImportIf* imp, const IfInfo* ii, ObjectIfs* objs) path imp Import NULL ii NULL objs true false FWSdk FWSdkIf bool SaveScene(UTString path, ImportIf* imp, const IfInfo* ii, ObjectIfs* objs)

12.5 Framework 125 LoadScene imp true false 12.5 Framework FWObject PHSolid GRFrame 12.6 Springhead FWApp 2.6 FWApp Springhead Create FWApp C++ FWApp FWApp Init FWApp virtual void Init(int argc, char* argv[]) Init void FWApp::Init(int argc, char* argv[]){ // create SDK CreateSdk(); // create a single scene GetSdk()->CreateScene(); // initialize window manager GRInit(argc, argv); // create main window

126 12 Framework } CreateWin(); // create timer CreateTimer(); CreateSdk(); SDK GRInit(argc, argv); GLUT GetSdk()->CreateScene(); FWScene 1 CreateWin(); CreateTimer(); virtual void Init(int argc = 0, char* argv[] = 0){ // select GLUI window manager SetGRAdaptee(TypeGLUI);

12.6 127 // call base Init FWApp::Init(argc, argv); // do extra initialization here } FWApp:Init Init Init MyApp app; int main(int argc, char* argv[]){ app.init(argc, argv); app.startmainloop(); return 0; } MyApp FWApp MyApp main Init StartMainLoop StartMainLoop CreateTimer CreateTimer Init

128 12 Framework FWApp UTTimerIf* CreateTimer(UTTimerIf::Mode mode) mode UTTimer SetMode 5.4 UTTimer 2 UTTimerIf *timersim, *timerdraw; timersim = CreateTimer(MULTIMEDIA); timersim->setinterval(10); timerdraw = CreateTimer(FRAMEWORK); timerdraw->setinterval(50); 10[ms] 50[ms] GLUT FWApp virtual void TimerFunc(int id) id TimerFunc Step PostRedisplay Display TimerFunc void TimerFunc(int id){ // proceed simulation of scene attached to current window if(id == timersim->getid()){ GetCurrentWin()->GetScene()->Step(); } // generate redisplay request else if(id == timerdraw->getid()){ PostRedisplay(); }

12.6 129 } 2 FWApp virtual void Display() Display PostRedisplay FWApp virtual void PostRedisplay() Display Display FWApp DVKeyMouse FWApp virtual bool OnMouse(int button, int state, int x, int y) virtual bool OnDoubleClick(int button, int x, int y) virtual bool OnMouseMove(int state, int x, int y, int zdelta) virtual bool OnKey(int state, int key, int x, int y) 10.5

130 12 Framework 12.7 GUI Framework FWApp 12.8 Framework Framework FWSdkIf void Step() FWSdk Step Step GetScene()->Step() FWScene Step PHScene Step GetPHScene()->Step() Framework 2 1 Graphics 1 Physics FWSdkIf void Draw() void SetDebugMode(bool) bool GetDebugMode() Draw Draw [Set Get]DebugMode (false) (true) Draw Sync(true) GRScene Render

12.9 131 12.9 PHScene FWScene DrawPHScene FWSceneIf void DrawPHScene(GRRenderIf* render) DrawPHScene GRScene GRScene Render GRScene 1 DrawPHScene

132 12 Framework FWSceneIf void DrawSolid(GRRenderIf*, PHSolidIf*, bool) void DrawShape(GRRenderIf*, CDShapeIf*, bool) void DrawConstraint(GRRenderIf*, PHConstraintIf*) void DrawContact(GRRenderIf*, PHContactPointIf*) void DrawIK(GRRenderIf*, PHIKEngineIf*) IK On/Off FWSceneIf void SetRenderMode(bool solid, bool wire) void EnableRender(ObjectIf* obj, bool enable) void EnableRenderAxis(bool world, bool solid, bool con) void EnableRenderForce(bool solid, bool con) void EnableRenderContact(bool enable) void EnableRenderGrid(bool x, bool y, bool z) void EnableRenderIK(bool enable) SetRenderMode On/Off EnableRender On/Off obj (PHSolidIf*) (PHConstraintIf*) EnableRenderAxis world solid con EnableRenderForce solid con EnableRenderGrid EnableRenderIK IK

12.10 133 FWSceneIf void SetSolidMaterial(int mat, PHSolidIf* solid) void SetWireMaterial (int mat, PHSolidIf* solid) void SetAxisMaterial(int matx, int maty, int matz) void SetAxisScale(float world, float solid, float con) void SetAxisStyle(int style) void SetForceMaterial(int matforce, int matmoment) void SetForceScale(float scaleforce, float scalemoment) void SetContactMaterial(int mat) void SetGridOption(char axis, float offset, float size, int slice) void SetGridMaterial(int matx, int maty, int matz) void SetIKMaterial(int mat) void SetIKScale(float scale) SetSolidMaterial mat 8.8 solid NULL SetWireMaterial SetAxisMaterial x, y, z SetAxisScale SetAxisStyle SetForceMaterial SetForceScale SetContactMaterial SetGridOption SetGridMaterial SetIKMaterial SetIKScale IK 12.10 Springhead2 PHHapticEngine Framework

134 12 Framework FWApp Init // given PHSceneIf* phscene, phscene->gethapticengine()->enablehapticengine(true); phscene->gethapticengine()-> SetHapticEngineMode(PHHapticEngineDesc::MULTI_THREAD); SINGLE THREAD MULTI THREAD LOCAL DYNAMICS 3 MULTI THREAD MULTI THREAD LOCAL DYNAMICS

12.10 135 // given PHSceneIf* phscene, int physicstimerid, haptictimerid // ID // FWApp::TimerFunc void MyApp::TimerFunc(int id){ if(haptictimerid == id){ // phscene->stephapticloop(); }else{ // phscene->gethapticengine()->stepphysicssimulation(); PostRedisplay(); // } } PHHapticPointer PHHapticPointer PHScene PHHapticPointer PHSolid PHSolid Spidar-G6 // given PHSceneIf* phscene, // given HISpidarIf* spg, PHHapticPointerIf* pointer = phscene->createhapticpointer(); /* */ pointer->sethumaninterface(spg); PHHapticPointer

136 12 Framework PHHapticPointerIf void SetHumanInterface(HIBaseIf* interface) void SetDefaultPose(Posed pose) void SetPosScale(double scale) void SetReflexSpring(float s) void SetReflexDamper(float s) void EnableFriction(bool b) void EnableVibration(bool b) void SetLocalRange(float s) void SetHapticRenderMode(PHHapticPointerDesc::HapticRenderMode m ) SetHumanInterface SetDefaultPose SetPosScale SetReflexSpring SetReflexDamper EnableFriction EnableVibration SetLocalRange SetHapticRenderMode SetHapticRenderMode PENALTY CONSTRAINT PENALTY CONSTRAINT

137 13 Python EmbPython Python Python Springhead Springhead Python EmbPython Python Springhead API Python Springhead Python Springhead Python 13.1 C++ Springhead Python Springhead Python Python (Python DLL, pyd) Springhead Python Springhead EmbPython Python Springhead Fig 13.1

138 13 Python Fig. 13.1 Python EmbPython Springhead Python Springhead Python Springhead Python Python PythonSpr Python src\samples\embpython\pythonspr PythonSpr.exe PythonSpr Springhead Springhead Application Python Python Python Python Interpreter phsdk fwsdk Springhead Objects Python EmbPython EmbPython Springhead Python Python Springhead Objects Python Interpreter SPRPYTHONPATH Springhead DLL (Spr.pyd) Springheadアプリケーションに Pythonに bin\src\python32\lib Pythonを組み込む場合 Springheadを組み込む場合

13.1 139 Python3.2 c:\python32 C:\Python32\Lib PythonSpr.exe Springhead Python Springhead PythonSpr Python Springhead Python Springhead API 13.2 Python Springhead # >>> fwscene fwscene <Framework.FWScene object at 0x05250A40> >>> phscene = fwscene.getphscene() >>> desc = Spr.PHSolidDesc() >>> desc.mass = 2.0 >>> solid0 = phscene.createsolid(desc) solid0.addshape(box0)

140 13 Python # >>> phscene = fwscene.getphscene() >>> phsdk = phscene.getsdk() >>> descsolid = Spr.PHSolidDesc() >>> solid0 = phscene.createsolid(descsolid) >>> descbox = Spr.CDBoxDesc() >>> descbox.boxsize = Spr.Vec3f(1,2,3) >>> box0 = phsdk.createshape(spr.cdbox.getifinfostatic(), descbox) >>> solid0.addshape(box0) >>> phscene = fwscene.getphscene() >>> phsdk = phscene.getsdk() # >>> descsolid = Spr.PHSolidDesc() >>> solid0 = phscene.createsolid(descsolid) >>> descbox = Spr.CDBoxDesc() >>> descbox.boxsize = Spr.Vec3f(10,2,10) >>> boxifinfo = Spr.CDBox.GetIfInfoStatic() >>> solid0.addshape(phsdk.createshape(boxifinfo, descbox)) >>> solid0.setframeposition(spr.vec3d(0,-1,0)) >>> solid0.setdynamical(false) # >>> solid1 = phscene.createsolid(descsolid) >>> descbox.boxsize = Spr.Vec3f(1,1,1) >>> boxifinfo = Spr.CDBox.GetIfInfoStatic() >>> solid1.addshape(phsdk.createshape(boxifinfo, descbox)) >>> solid1.addforce(spr.vec3d(0,200,0)) Python For While

13.1 141 >>> import time >>> for i in range(0,100): >>> solid1.addforce(spr.vec3d(0,20,0)) >>> time.sleep(0.01) >>> import time >>> for i in range(0,500): >>> y = solid1.getpose().getpos().y >>> dy = solid1.getvelocity().y >>> kp = 20.0 >>> kd = 3.0 >>> solid1.addforce(spr.vec3d(0, (2.0 - y)*kp - dy*kd, 0)) >>> time.sleep(0.01) >>> phscene = fwscene.getphscene() >>> phsdk = phscene.getsdk() >>> descsolid = Spr.PHSolidDesc() >>> solid0 = phscene.createsolid(descsolid) >>> descbox = Spr.CDBoxDesc() >>> descbox.boxsize = Spr.Vec3f(1,1,1) >>> boxifinfo = Spr.CDBox.GetIfInfoStatic() >>> solid0.addshape(phsdk.createshape(boxifinfo, descbox)) >>> solid0.setdynamical(false) >>> solid1 = phscene.createsolid(descsolid) >>> solid1.addshape(phsdk.createshape(boxifinfo, descbox)) >>> descjoint = Spr.PHHingeJointDesc() >>> descjoint.posesocket = Spr.Posed(1,0,0,0, 0,-1,0) >>> descjoint.poseplug = Spr.Posed(1,0,0,0, 0, 1,0) >>> hingeifinfo = Spr.PHHingeJoint.GetIfInfoStatic() >>> joint = phscene.createjoint(solid0, solid1, hingeifinfo, descjoint) PythonSpr.exe python test.py

142 13 Python test.py C:\src\Samples\EmbPython\PythonSpr> Release\PythonSpr.exe test.py >>> Python PythonSpr Python tips Python Springhead Python C API Python/C API 1 *1... http://docs.python.org/py3k/c-api/index.html PythonSpr Python main.cpp Python EmbPython.h #include <EmbPython/EmbPython.h> Python Springhead Python virtual void OnStep(){ UTAutoLock critical(epcriticalsection);... } virtual void OnDraw(GRRenderIf* render) { UTAutoLock critical(epcriticalsection);... } virtual void OnAction(int menu, int id){ UTAutoLock critical(epcriticalsection);

13.1 143 }... EPCriticalSection EPCriticalSection Python Springhead EPCriticalSection OnStep Python Springhead *1 Python void EPLoopInit(void* arg) { PythonSprApp* app = (PythonSprApp*)arg; // Python PyRun_SimpleString("import Spr"); // Python C PyObject *m = PyImport_AddModule(" main "); PyObject *dict = PyModule_GetDict(m); // Python fwscene PyObject* pyobj = (PyObject*)newEPFWSceneIf(app->fwScene); Py_INCREF(pyObj); PyDict_SetItemString(dict, "fwscene", pyobj); // Python if (app->argc == 2) { ostringstream loadfile; loadfile << " mainfilename = "; loadfile << app->argv[1]; loadfile << " "; PyRun_SimpleString("import codecs"); PyRun_SimpleString(loadfile.str().c_str()); PyRun_SimpleString( " mainfile = codecs.open( mainfilename, r, utf-8 )"); PyRun_SimpleString( "exec(compile( mainfile.read(), mainfilename, exec )" ",globals()" ",locals())" ); PyRun_SimpleString(" mainfile.close()"); *1

144 13 Python } } Python Springhead C.py app->fwscene Python #define ACCESS_SPR_FROM_PY(cls, name, obj) \ { \ PyObject* pyobj = (PyObject*)newEP##cls((obj)); \ Py_INCREF(pyObj); \ PyDict_SetItemString(dict, #name, pyobj); \ } \ // : // ACCESS_SPR_FROM_PY(, Python, ) ACCESS_SPR_FROM_PY(FWSceneIf, fwscene, app->fwscene); PythonSpr Python void EPLoop(void* arg) { PyRun_InteractiveLoop(stdin,"SpringheadPython Console"); } main Python EPInterpreter int main(int argc, char *argv[]) { app.init(argc, argv); EPInterpreter* interpreter = EPInterpreter::Create(); interpreter->initialize();

13.1 145 } interpreter->eploopinit = EPLoopInit; interpreter->eploop = EPLoop; interpreter->run(&app); app.startmainloop(); return 0; Python Springhead Python DLL Springhead Python Springhead Spr.pyd DLL Spr.pyd bin\win32\spr.pyd bin\win64\spr.pyd Springhead src\embpython\sprpythondll.sln Spr.pyd Spr.pyd Python DLLs import Python 3.2.2 [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import Spr Springhead PHSdk PHScene PHSolid >>> phsdk = Spr.PHSdk.CreateSdk() >>> phscene = phsdk.createscene(spr.phscenedesc()) >>> solid0 = phscene.createsolid(spr.phsoliddesc()) >>> for i in range(0,10):... print(solid0.getpose().getpos())... phscene.step()

146 13 Python... Vec3d(0.000,0.000,0.000) Vec3d(0.000,-0.000,0.000) Vec3d(0.000,-0.001,0.000)...( )... Vec3d(0.000,-0.011,0.000) >>> API Springhead pyopengl Spr.pyd SprBlender SprBlender 3DCG Blender Springhead Springhead Blender UI Python Python API Blender Python Spr.pyd Blender CG Springhead Python SprBlender Web *2 *2 http://springhead.info/wiki/sprblender