Springhead Users Manual Yuichi Tazaki

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Springhead Users Manual Yuichi Tazaki"

Transcription

1 Springhead Users Manual Yuichi Tazaki

2

3 Getting Started SVN Springhead API Base Foundation Collision 35

4 Physics Physics SDK Graphics Graphics SDK FileIO FileIO SDK HumanInterface

5 HumanInterface SDK Spidar Creature Framework Framework SDK Framework Framework Framework

6

7 7 1 Springhead C++ Springhead

8

9 9 2 Getting Started Springhead 2.1 Springhead zip Subversion 2.2 SVN Springhead Subversion Springhead Subversion Springhead Windows, Max, Unix Windows Visual Studio

10 10 2 Getting Started Fig. 2.1 Building the library Windows + Visual Studio Windows Visual Studio Windows XP/Vista/7, Visual Studio 2008/ Springhead Springhead C:\Springhead2 Visual Studio C:\Springhead2\src\Springhead**.sln ** Visual Studio Visual Studio 2010 Springhead10.sln Visual Studio 2008 Springhead9.sln Fig. 2.1 Springhead C:\Springhead2\lib\win32\ Springhead**.lib Table 2.1

11 Table 2.1 Build configurations Release multithread Springhead**.lib Debug multithread, Debug Springhead**D.lib ReleaseDLL multithread, DLL Springhead**M.lib DebugDLL multithread, Debug, DLL Springhead**MD.lib 2.5 C:\Springhead2\src\Samples\All**.sln C:\Springhead2\lib\win32\Springhead**.lib Physics/BoxStack Physics/Joints 2.6 Springhead Visual Studio 2010 Visual C++ Win32 main.cpp

12 12 2 Getting Started Fig. 2.2 Create new project Fig. 2.3 Project configuration main.cpp Table 2.2 Springhead C/C++

13 Fig. 2.4 Create source file Fig. 2.5 Add include path Fig. 2.5 Springhead Fig. 2.6 Springhead Debug C/C++ (/MTd) Springhead10D.lib Release (/MT) Springhead10.lib

14 14 2 Getting Started Fig. 2.6 Add library path Fig. 2.7 Specify library file (F7) (F5) Fig. 2.8

15 Fig. 2.8 Program running

16 16 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; }

17 17 3 Springhead 3.1 Springhead Fig 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 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

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 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 21 4 Base Base 4.1 Table 4.1 f d float double Vec3d x; [] x[0]; // 0-th element Vec[2 3][f d].x,.y,.z TVector<10, float> x; // 10-dimensional float vector VVector<float> x; x.resize(10); // can be resized at any time

22 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. Vec3d a, b, c; double k; c = a + b; a += b; // addition c = a - b; a -= b; // subtraction b = k * a; a *= k; // multiply vector by scalar k = x * y; // scalar product x % y; // vector product (3D vector only) a.size(); a.norm(); a.square(); a.unitize(); b = a.unit(); // number of elements // norm // square of norm // normalize // normalized vector

23 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 VMatrixCol<float> M; M.resize(10, 13); // column-oriented variable matrix. Matrix3d M; Vec3d a, b; b = M * a; // multiplication M.height(); M.width(); // number of rows // number of columns 2x2, 3x3

24 24 4 Base 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 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); // identity transformation // translation // rotation w.r.t. x-axis // one can specify y and z too // rotation w.r.t. arbitrary axis

25 A = Affinef::Scale(x, y, z); // 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 q0, q1; Vec3d r0, r1; q0 * q1; r1 = q * r0; // composition of rotation // rotate r0 by q q.axis(); q.theta(); q.conjugate(); // rotation axis // rotation angle // conjugate (reverse rotation) Quaterniond y; y = q.conjugated(); y = q.inv(); // return conjugated quaternion // return inverse (normalized conjugate) Matrix3d R; q.frommatrix(r); q.tomatrix(r); // conversion from rotation matrix // conversion to rotation matrix

26 26 4 Base Vec3d angle; q.toeuler(angle); q.fromeuler(angle); // to Euler angle // from Euler angle Vec3d r0, r1; q.rotationarc(r0, r1); // rotation that maps r0 to r1 7 Pose[f d] Posed P; Vec3d p = P.Pos(); Quaterniond q = P.Ori(); // position component // orientation component delete UTRefCount Springhead UTRefCount UTRef class A : public UTRefCount{}; UTRef<A> a = new A(); // no need to delete a

27 UTString std::string UTTypeDesc Springhead UTTreeNode

28

29 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 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

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 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 Sleep FRAMEWORK

33 IDLE FWApp CreateTimer FRAMEWORK GLUT IDLE GLUT Framework FWApp FWApp CreateTimer

34

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

36 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 solid->addshape(box); solid->addshape(box); // second box // third box // move first shape 1.0 in x-direction

37 Fig. 6.2 Box geometry 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 CDBoxDesc Vec3f boxsize CDBoxIf Vec3f GetBoxSize() void SetBoxSize(Vec3f)

38 38 6 Collision Fig. 6.3 Sphere geometry (Fig. 6.3) CDSphere CDSphereDesc float radius CDSphereIf float GetRadius() void SetRadius(float) (Fig. 6.4) CDCapsule

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 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

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 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() 6.4

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

44

45 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 46 7 Physics PHSdk 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

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

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

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

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

51 PHSolidIf void AddForce(Vec3d) void AddTorque(Vec3d) void AddForce(Vec3d, Vec3d) Vec3d GetForce() Vec3d 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 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

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 54 7 Physics uppery y x lower plug x socket z Fig. 7.3 Hinge joint 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 ) 1 Fig. 7.3 z y y (x

55 y lower y x socket z x plug z upper Fig. 7.4 Slider joint ) 1 Fig. 7.4 z x y 1 T.B.D. 3 T.B.D. T.B.D.

56 56 7 Physics PHConstraintDesc bool benabled / PHConstraintIf void Enable(bool) bool IsEnabled() 1 PHJoint1DDesc double lower double upper double rangespring double rangedamper PHJoint1DIf void SetRange(double lower, double upper) void GetRange(double& lower, double& upper) void SetRangeSpring(double) double GetRangeSpring() void SetRangeDamper(double) double GetRangeDamper() bool IsLimit() lower upper lower < upper

57 rangespring rangedamper : T.B.D. 1 PHJoint1DDesc double spring double damper double targetposition double targetvelocity double offsetforce double fmax PHJoint1DIf double GetPosition() double GetVelocity() void SetSpring(double) 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()

58 58 7 Physics 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 : T.B.D. 7.6 T.B.D. 7.7 T.B.D. 7.8 T.B.D.

59 59 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

60 60 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

61 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 GRSdk GRSdkIf GRSceneIf* CreateScene() GRSceneIf* GetScene(size t) size t NScene() void MergeScene(GRSceneIf*, GRSceneIf*) FileIO GRScene

62 62 8 Graphics GRSceneIf GRFrameIf* GetWorld() GRCameraIf* GetCamera() void SetCamera(const GRCameraDesc&) GRVisualIf* CreateVisual(const GRVisualDesc&, GRFrameIf*) void Render(GRRenderIf*) Fig 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

63 GRVisual 描画アイテム GRFrame GRMesh GRCamera GRLight GRMaterial フレーム ポリゴンメッシュ カメラ ライト マテリアル Fig. 8.2 Class hierarchy of visual items render->setclearcolor(vec4f(1.0f, 0.0f, 0.0f, 1.0f)); 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 Render(GRRenderIf*) void Rendered(GRRenderIf*) void Enable(bool) bool IsEnabled() Render Rendered Enable / IsEnabled / GRScene CreateVisual

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

65 (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 GetTransform() Affinef GetWorldTransform() void SetTransform(const Affinef&) GetTransform SetTransform / frame->settransform(affinef::trn(1.0, 0.0, 0.0)); x 1.0

66 66 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* GetFrame() void SetFrame(GRFrameIf*) GetFrame SetFrame / Fig. 8.3(a) 8.7 GRLight

67 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 8.9 GRMesh FileIO

68 68 8 Graphics 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) void SetDepthTest(bool) void SetDepthFunc(TDepthFunc) void SetAlphaTest(bool) void SetAlphaMode(TBlendFunc, TBlendFunc) void SetLighting(bool) On/Off On/Off On/Off On/Off

69 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*)

70 70 8 Graphics 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)

71 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) void DrawFont(Vec3f, UTString) 2 3 GRRenderIf void SetMaterial(const GRMaterialDesc&) void SetMaterial(const GRMaterialIf*) void SetMaterial(int) void SetLineWidth(float)

72 72 8 Graphics GRRenderIf void SetCamera(const GRCameraDesc&) const GRCameraDesc& GetCamera() GRRenderIf void PushLight(const GRLightDesc&) void PushLight(const GRLightIf*) void PopLight() int NLights() GRRenderIf void Reshape(Vec2f, Vec2f) void SetViewport(Vec2f, Vec2f) Vec2f GetViewportPos() Vec2f GetViewportSize() Vec2f GetPixelSize() Vec3f ScreenToCamera(int, int, float, bool) void EnterScreenCoordinate() void LeaveScreenCoordinate() 1

73 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)

74

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

76 76 9 FileIO FIFile ファイル FIFileSpr FIFileBinary FIFileX FIFileVRML FIFileCollada Springhead 専用テキストフォーマット Springhead 専用バイナリフォーマット Direct X VRML COLLADA Fig. 9.1 Class hierarchy of file objects FISdkIf FIFileSprIf* CreateFileSpr() FIFileBinaryIf* CreateFileBinary() FIFileXIf* CreateFileX() FIFileVRMLIf* CreateFileVRML() FIFileCOLLADAIf* CreateFileCOLLADA() FIFileIf* CreateFileFromExt(UTString filename) CreateFileFromExt filename 9.3 T.B.D. 9.4 T.B.D. 9.5 T.B.D.

77 77 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 Win32 A/D

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

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

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

81 DVKeyCode ESC F1 - F12 LEFT UP RIGHT DOWN PAGE UP PAGE DOWN HOME END INSERT Page Up Page Down Home End Insert DVKeyMouse DVKeyMouseHandler DVKeyMouseHandler FWApp

82 82 10 HumanInterface DVKeyMouseHandler virtual bool OnMouse(int button, int state, int x, int y) button DVButtonMask state DVButtonSt x y virtual bool OnDoubleClick(int button, int x, int y) button DVButtonMask x y virtual bool OnMouseMove(int state, int x, int y, int zdelta) state DVButtonSt x y zdelta virtual bool OnKey(int state, int key, int x, int y) state DVButtonSt key ascii DVKeyCode x y

83 DVButtonMask LBUTTON RBUTTON MBUTTON SHIFT CONTROL ALT Shift Ctrl Alt DVButtonSt DOWN UP DVKeySt PRESSED TOGGLE ON 10.6 DVJoyStick GLUT DRJoyStickGLUT T.B.D T.B.D Spidar Spidar 3 6

84 84 10 HumanInterface T.B.D.

85 85 11 Creature T.B.D.

86

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

88 88 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 Framework data structure 12.2 Framework SDK Framework SDK FWSdk FWSdk FWSdk FWSdkIf* fwsdk = FWSdkIf::CreateSdk(); FWSdk PHSdk GRSdk FISdk HISdk SDK

89 12.3 Framework 89 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 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 SDK FWSdk FWScene FWObject Fig Physics Graphics

90 90 12 Framework Graphics FWSdk FWSdkIf 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 fwsdk->mergescene(fwscene0, fwscene1); scene1 FWObject scene0

91 12.3 Framework 91 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); PHScene GRScene FWObject fwscene->sync(false);

92 92 12 Framework 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) LoadScene imp true false 12.5 Framework FWObject PHSolid GRFrame

93 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 CreateWin(); // create timer CreateTimer(); } CreateSdk();

94 94 12 Framework 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); // call base Init FWApp::Init(argc, argv); // do extra initialization here } FWApp:Init Init Init

95 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 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

96 96 12 Framework 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(); } } 2 FWApp virtual void Display() Display PostRedisplay

97 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) GUI Framework FWApp 12.8 Framework Framework FWSdkIf void Step() FWSdk Step Step GetScene()->Step()

98 98 12 Framework 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 PHScene FWScene DrawPHScene FWSceneIf void DrawPHScene(GRRenderIf* render)

99 DrawPHScene GRScene GRScene Render GRScene 1 DrawPHScene 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

100 Framework 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

101 Table 12.1 Reserved colors RED (1.00, 0.00, 0.00) GREEN (0.00, 1.00, 0.00) BLUE (0.00, 0.00, 1.00) YELLOW (1.00, 1.00, 0.00) CYAN (0.00, 1.00, 1.00) MAGENTA (1.00, 0.00, 1.00) WHITE (1.00, 1.00, 1.00) GRAY (0.50, 0.50, 0.50) ORANGE (1.00, 0.27, 0.00) BROWN (0.19, 0.00, 0.00) LIGHT BLUE (0.67, 0.84, 0.89) MEDIUM PURPLE (0.57, 0.43, 0.85) DARK GREEN (0.00, 0.39, 0.00) DARK VIOLET (0.57, 0.00, 0.82) DARK CYAN (0.00, 0.54, 0.54) GREEN YELLOW (0.67, 1.00, 0.18) LIME GREEN (0.19, 0.80, 0.19) INDIAN RED (0.80, 0.35, 0.35) INDIGO (0.29, 0.00, 0.50) GREEN INDIGO (0.00, 0.19, 0.19) OLIVE GREEN (0.19, 0.39, 0.00) NAVY BLUE (0.19, 0.39, 0.79) TURQUOISE BLUE (0.39, 1.00, 0.79) EMERALD GREEN (0.59, 1.00, 0.39) 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 GRRenderBaseIf 24 Table 12.1 solid NULL SetWireMaterial

102 Framework SetAxisMaterial x, y, z SetAxisScale SetAxisStyle SetForceMaterial SetForceScale SetContactMaterial SetGridOption SetGridMaterial SetIKMaterial SetIKScale IK

103 Visual Studio Springhead include Springhead Springhead Springhead

104 X 13.5 svn update Springhead (?)Springhead

105 105 Affined, 24 Affinef, 24 Base, 21 CDBox, 33 CDCapsule, 34 CDConvexMesh, 36 CDRoundCone, 36 CDShape, 31 CDSphere, 34 Collision, 31 FIFile, 71 FileIO, 71 FISdk, 71 Foundation, 29 Framework, 77 FWApp, 85 FWObject, 78 FWScene, 78 FWSdk, 77 Graphics, 55 GRCamera, 62 GRDeviceGL, 55 GRFrame, 60 GRLight, 62 GRMaterial, 63 GRMesh, 63 GRRender, 55, 63 GRScene, 56 GRSdk, 55 GRVisual, 59 IfInfo, 29 Matrix2d, 23 Matrix2f, 23 Matrix3d, 23 Matrix3f, 23 Object, 29 PHBallJoint, 51 PHConstraint, 47 PHHingeJoint, 50 PHJoint, 47 PHMaterial, 37 PHPathJoint, 51 PHScene, 42 PHSdk, 41 PHSliderJoint, 51 PHSolid, 44 PHSpring, 51 Physics, 41 Posed, 26 Posef, 26 Quaterionf, 25 Quaterniond, 25 Scene, 29 Springhead, 7 UTRef, 26 UTRefCount, 26 UTString, 27 UTTimer, 29 UTTreeNode, 27 UTTypeDesc, 27 Vec2d, 21 Vec2f, 21 Vec3d, 21 Vec3f, 21 Vec4d, 21 Vec4f, 21, 24, 34, 62, 54, 54, 34, 23, 25, 26, 51

106 106, 54, 49, 29, 33, 55, 36, 51, 51, 50, 71, 37, 49, 60, 21, 26, 51, 63, 36, 63, 62, 55, 63