# HG changeset patch # User tokumoritaichirou@nw0743.st.ie.u-ryukyu.ac.jp # Date 1265135944 -32400 # Node ID 5727d511a13a7d274409adfaeb9f17eaeb8d5f9c # Parent 143f7b9f867d1f5f20ddb9eff179bb0b5b29cbaf add src in Martial Project Xcode. diff -r 143f7b9f867d -r 5727d511a13a src/Avatar.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Avatar.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,57 @@ +/* + * Avatar.h + * Martial + * + * Created by ryoma on 10/01/27. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _AVATAR_H_ +#define _AVATAR_H_ + +#include "Martial.h" +#include "CollisionObject.h" +#include "ControllableObject.h" +#include "SearchMatrixTransformVisitor.h" +#include "SearchGeodeVisitor.h" + +/*! + @class Avatar + @abstract Martial上で、Playerが操作するクラス + @discussion 衝突判定(Collision)、入力処理(Controllable)を行なう。 +*/ + +class Avatar : public CollisionObject, public ControllableObject { + protected: + /*! @var キャラクターの体力 */ + int hitpoint; + /*! @var コマンド入力用のバファ + @discussion コマンドの入力は状態遷移関数でやった方が良いかも + */ + char keyboardInputBuffer[Martial::CONFIG::FRAME_RATE]; + /*! @var Avatarの体内時計。モーションの更新や判定で使用 */ + int motionTime; + /*! @var Avatarの向いてる方向。Player1 -> 1, Player2 -> -1 + @discussion bool (0 or 1)にして、(bool*2) - 1 でもok? */ + int avatarDirection; + enum functionIndex { + RELEASE_HAT, PUSH_UP, PUSH_RIGHT, PUSH_LEFT, PUSH_DOWN, + PUSH_RIGHTUP, PUSH_RIGHTDOWN, PUSH_LEFTUP, PUSH_LEFTDOWN, + PUSH_A, PUSH_B, PUSH_C, PUSH_D, RELEASE_BUTTON + }; + public: + Avatar(char* _name = "Character") : + avatarDirection(1), CollisionObject::CollisionObject(_name) {}; + + Avatar(osg::Node* _node, char* _name = "Character") : + avatarDirection(1), CollisionObject::CollisionObject(_node, _name) {}; + + void printInput(char* format, char* name) { if (Martial::TEST::SHOW_AVATAR_INPUT) Martial::TEST::print(format, name); }; + + void onStage(); + + void setAvatarDirection(int dir) { avatarDirection = dir; }; +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/CollisionDetector.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionDetector.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,71 @@ +/* + * CollisionDetector.cpp + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "CollisionDetector.h" + +void CollisionDetector::addCollisionObject(CollisionObject* cobj) { + collisionObjectList.push_back(cobj); +} + +void CollisionDetector::detectCollision(CollisionNode* cn1, CollisionNode* cn2) { + cn1->setCollision(true); + cn2->setCollision(true); +} + +void CollisionDetector::checkCollision(CollisionObject* co1, CollisionObject* co2) { + std::list collisionNodeList1, collisionNodeList2; + collisionNodeList1 = co1->getCollisionNodeList(); + collisionNodeList2 = co2->getCollisionNodeList(); + osg::NodePath npl1 , npl2; + osg::Matrix m1, m2; + std::list::iterator node1, node2; + for(node1 = collisionNodeList1.begin(); node1 != collisionNodeList1.end(); ++node1) { + for(node2 = collisionNodeList2.begin(); node2 != collisionNodeList2.end(); ++node2) { + npl1 = (*node1)->getNodePath(); + npl2 = (*node2)->getNodePath(); + //衝突判定 + m1 = osg::computeLocalToWorld(npl1); + m2 = osg::computeLocalToWorld(npl2); + if ((*node1)->getBound(m1).intersects((*node2)->getBound(m2))) { + if (Martial::TEST::SHOW_COLLISION) printf("collision!! %s->[%s] & %s->[%s]\n", co1->getName(), (*node1)->getName(), + co2->getName(), (*node2)->getName()); + detectCollision(*node1, *node2); + } + } + } +} + +void CollisionDetector::frame() { + std::list::iterator iter1, iter2; + iter1 = collisionObjectList.begin(); + iter2 = iter1; + float length; + osg::Vec3 v1, v2; + + for(++iter1; iter1 != collisionObjectList.end(); ++iter1) { + length = ((*iter1)->getPos()-(*iter2)->getPos()).length(); + if (length <= 3.0) { + if (Martial::TEST::SHOW_COLLISION) printf("%s close to %s (%.3f), check collision..\n", (*iter2)->getName(), (*iter1)->getName(), length); + checkCollision(*iter1, *iter2); + } + iter2 = iter1; + } +} +/* + startFrameTick = osg::Timer::instance()->tick(); + + //SceneGraphの走査 -> 座標計算, 衝突判定 + //衝突処理はcheckCollision内部で行なう?(未実装) + for(mobIter = movableObjectList.begin(); mobIter != movableObjectList.end(); ++mobIter) { + (*mobIter)->reload(); + //このcheckCollisionは、後に削除 + //CollisionDetectorクラスを定義し、そこでcheckCollsionすることに + (*mobIter)->checkCollision(); + } +*/ \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/CollisionDetector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionDetector.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,29 @@ +/* + * CollisionDetector.h + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _COLLISION_DETECTOR_H_ +#define _COLLISION_DETECTOR_H_ + +#include "Martial.h" +#include "CollisionObject.h" +#include +#include + +class CollisionDetector { + protected: + std::list collisionObjectList; + void searchCloseObject(); + void checkCollision(CollisionObject* co1, CollisionObject* co2); + void detectCollision(CollisionNode* cn1, CollisionNode* cn2); + public: + void frame(); + void addCollisionObject(CollisionObject* cobj); +}; + +#endif diff -r 143f7b9f867d -r 5727d511a13a src/CollisionNode.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionNode.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,71 @@ +/* + * CollisionNode.cpp + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "CollisionNode.h" + +CollisionNode::CollisionNode(char* name, osg::Sphere* shape): + name(name), shape(shape) { + collision = false; + attack = false; + guard = false; + radius = shape->getRadius(); + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode = new osg::Geode(); + collisionNode->addDrawable(drawable); +} + +CollisionNode::CollisionNode(char* name, osg::Cylinder* shape): + name(name), shape(shape) { + collision = false; + attack = false; + guard = false; + radius = shape->getRadius(); + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode = new osg::Geode(); + collisionNode->addDrawable(drawable); +} + +CollisionNode::CollisionNode(char* name, osg::Geode* geode, osg::Shape* shape): + name(name), collisionNode(geode), shape(shape) { + collision = false; + attack = false; + guard = false; + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode->addDrawable(drawable); +} + + +void CollisionNode::setCollision(bool _collision) { + _collision ? drawable->setColor(osg::Vec4f(1,0,0,1)) : drawable->setColor(osg::Vec4f(1,1,1,1)); + collision = _collision; +} + +char* CollisionNode::getName() { + return name; +} + +osg::NodePath CollisionNode::getNodePath() { + return collisionNode->getParentalNodePaths().front(); +} + +osg::Geode* CollisionNode::getGeode() { + return collisionNode; +} + +osg::BoundingSphere CollisionNode::getBound(osg::Matrix localToWorldMatrix) { + osg::Vec3 t = localToWorldMatrix.getTrans(); + osg::BoundingSphere bound = collisionNode->computeBound(); + //printf("[%.3f, %.3f, %.3f]\n", localToWorldMatrix.getTrans().x(), localToWorldMatrix.getTrans().y(), + // localToWorldMatrix.getTrans().z()); + bound.set(bound.center()*localToWorldMatrix, radius*0.01); + return bound; +} diff -r 143f7b9f867d -r 5727d511a13a src/CollisionNode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionNode.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,46 @@ +/* + * CollisionNode.h + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _COLLISION_NODE_H_ +#define _COLLISION_NODE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +class CollisionNode { + protected: + osg::Group* collisionGroup; + osg::Geode* collisionNode; + osg::Shape* shape; + float radius; + osg::ShapeDrawable* drawable; + bool collision; + bool attack; + bool guard; + char* name; + public: + CollisionNode(char* name = "CollisionNode", osg::Sphere* _shape = new osg::Sphere(osg::Vec3(0, 0, 0), 0)); + CollisionNode(char* name = "CollisionNode", osg::Cylinder* _shape = new osg::Cylinder(osg::Vec3(0, 0, 0),0, 0)); + CollisionNode(char* name = "CollisionNode", osg::Geode* geode = NULL, osg::Shape* shape = new osg::Sphere(osg::Vec3(0,0,0),0)); + osg::Geode* getGeode(); + osg::BoundingSphere getBound(osg::Matrix localToWorldMatrix); + osg::NodePath getNodePath(); + //void drawable(); + //void unDrawable(); + void setCollision(bool collision); + char* getName(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/CollisionObject.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionObject.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,14 @@ +/* + * CollisionObject.cpp + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "CollisionObject.h" + +std::list& CollisionObject::getCollisionNodeList() { + return collisionNodeList; +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/CollisionObject.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionObject.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,31 @@ +/* + * CollisionObject.h + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +/*! + @class CollisionObject + @abstract 衝突判定が適用されるクラス。 CollisionNodeをリストで保持している。 +*/ + +#ifndef _COLLISION_OBJECT_H_ +#define _COLLISION_OBJECT_H_ + +#include +#include + +class CollisionObject : public MovableObject { + protected: + osg::NodePath* nodePath; + std::list collisionNodeList; + public: + CollisionObject(char* name = "CollisionObject") : MovableObject::MovableObject(name) {}; + CollisionObject(osg::Node* _node, char* _name = "CollisionObject") : MovableObject::MovableObject(_node, _name) {}; + std::list& getCollisionNodeList(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/ControllableObject.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ControllableObject.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,51 @@ +/* + * ControllableObject.h + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _CONTROLLABLE_OBJECT_H_ +#define _CONTROLLABLE_OBJECT_H_ + +/*! + @class ContorollableObject + @abstract Keyboardのcallbackを設定できるクラス。 + EyePoint, Avatar + @discussion MovableObjectを継承. +*/ + +class ControllableObject { + public: +/*! + @enum + @abstract KeyboardEventHanderでHandle設定できるControllableクラスの関数群(インターフェース) + @discussion Javaでいう interface (でも、純粋仮想関数ではない。デフォルトではなにもしないように) +*/ + virtual void pushLeft() {}; + virtual void releaseLeft() {}; + virtual void pushRight() {}; + virtual void releaseRight() {}; + virtual void pushUp() {}; + virtual void releaseUp() {}; + virtual void pushDown() {}; + virtual void releaseDown() {}; + virtual void pushA() {}; + virtual void releaseA() {}; + virtual void pushB() {}; + virtual void releaseB() {}; + virtual void pushC() {}; + virtual void releaseC() {}; + virtual void pushD() {}; + virtual void releaseHat() {}; + virtual void releaseButton() {}; + virtual void releaseD() {}; + virtual void pushRightUp() {}; + virtual void pushRightDown() {}; + virtual void pushLeftUp() {}; + virtual void pushLeftDown() {}; +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/EyePoint.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EyePoint.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,19 @@ +/* + * eyePoint.cpp + * carRace + * + * Created by ryoma on 09/05/20. + * Copyright 2009 __MyCompanyName__. All rights reserved. + * + */ + +#include "EyePoint.h" + +EyePoint::EyePoint(char* name) : MovableObject(name) { + offset = osg::Vec3(0,0,0); + Tman = new osgGA::TrackballManipulator(); +} + +osgGA::TrackballManipulator* EyePoint::getManpulator() { + return Tman; +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/EyePoint.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EyePoint.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,32 @@ +/* + * eyePoint.h + * carRace + * + * Created by ryoma on 09/05/20. + * Copyright 2009 __MyCompanyName__. All rights reserved. + * + */ + +/** 視点を表すクラス. + * 指定したMovableオブジェクトの視点を描画する + * @see Car + */ +#ifndef EYE_POINT_H +#define EYE_POINT_H + +#include "Martial.h" +#include "MovableObject.h" +#include + +class EyePoint : public MovableObject { + protected: + osgGA::TrackballManipulator* Tman; + osg::Vec3 offset; + public: + EyePoint(char* name = "EyePoint"); + virtual void frame() = 0; + virtual void setTarget(MovableObject* _target) = 0; + osgGA::TrackballManipulator* getManpulator(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/GameManager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/GameManager.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,269 @@ +/* + * GameManager.cpp + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "GameManager.h" + +/** + ここはサブクラスにまかせたい。 +*/ + +GameManager::GameManager() { + //movableObjectList = new std::list(); + /* グラフィックスとジョイスティックを初期化 */ + puts("SDL_INIT_JOYSTICK.. "); + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { + fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); + exit(0); + } else { + puts("success!!"); + } + + int i; + printf("%d joysticks found.\n",SDL_NumJoysticks()); + printf("their names are:\n"); + for(i=0; iaddDrawable(clothGeometry); + //root->addChild(clothGeode); + + float clen; + clen = 100.0; + osg::Vec3Array* clothVertices = new osg::Vec3Array; + clothVertices->push_back (osg::Vec3( clen, clen, 0.0)); + clothVertices->push_back (osg::Vec3( clen, -clen, 0.0)); + clothVertices->push_back (osg::Vec3( -clen, -clen, 0.0)); + clothVertices->push_back (osg::Vec3( -clen, clen, 0.0)); + clothGeometry->setVertexArray(clothVertices); + + osg::DrawElementsUInt* cloth = + new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + cloth->push_back(3); + cloth->push_back(2); + cloth->push_back(1); + cloth->push_back(0); + clothGeometry->addPrimitiveSet(cloth); + + osg::Texture2D* clothTexture = new osg::Texture2D; + clothTexture->setDataVariance(osg::Object::DYNAMIC); + osg::Image* clothImage = osgDB::readImageFile("Cell 23.rgb"); + if (!clothImage) { + printf("Error!!"); + return; + } + clothTexture->setImage(clothImage); + osg::StateSet* stateOne = new osg::StateSet(); + stateOne->setTextureAttributeAndModes(0,clothTexture,osg::StateAttribute::ON); + clothGeometry->setStateSet(stateOne); + osg::AutoTransform* fieldForm = new osg::AutoTransform(); + fieldForm->addChild(clothGeode); + fieldForm->setPosition(osg::Vec3(0,0,-5)); + root->addChild(fieldForm); +} + +void GameManager::gameStart() { + puts("entory gameStart"); + + osg::Timer_t sTick, eTick; + osgViewer::CompositeViewer viewer; + + puts("Initialize Stage..."); + sTick = osg::Timer::instance()->tick(); + + initStage(); + + eTick = osg::Timer::instance()->tick(); + printf("ok.. (%.6f msec)\n",osg::Timer::instance()->delta_s(sTick, eTick)*1000.0); + + puts("Create Avatar.."); + + sTick = osg::Timer::instance()->tick(); + Robot* roboObj1 = new Robot("robo1"); + + roboObj1->setPos(osg::Vec3(10,0,0)); + roboObj1->setDefaultDirection(osg::Vec3(0.0, 0.0, 90.0)); //物体のデフォルトの向き + root->addChild(roboObj1->getForm()); + movableObjectList.push_back(roboObj1); + collisionDetector->addCollisionObject(roboObj1); + + eTick = osg::Timer::instance()->tick(); + printf("%s: created.. (%.6f msec)\n",roboObj1->getName(), osg::Timer::instance()->delta_s(sTick, eTick)*1000.0); + + sTick = osg::Timer::instance()->tick(); + + Robot* movObj = new Robot("robo2"); + //movObj->setPos(osg::Vec3(-10,0,0)); + movObj->setDefaultDirection(osg::Vec3(0.0, 0.0, 90)); + movObj->setAvatarDirection(-1); + root->addChild(movObj->getForm()); + movableObjectList.push_back(movObj); + collisionDetector->addCollisionObject(movObj); + + eTick = osg::Timer::instance()->tick(); + printf("%s: created.. (%.6f msec)\n",movObj->getName(), osg::Timer::instance()->delta_s(sTick, eTick)*1000.0); + + puts("Initialize Window"); + sTick = osg::Timer::instance()->tick(); + + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) { + osg::notify(osg::NOTICE) << "Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->x = 100; + traits->y = 100; + traits->width = Martial::CONFIG::WINDOW_WIDTH; + traits->height = Martial::CONFIG::WINDOW_HEIGHT; + traits->windowDecoration = true; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (gc.valid()) { + osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f)); + gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } else { + osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<tick(); + printf("ok.. (%.6f msec)\n", osg::Timer::instance()->delta_s(sTick, eTick)*1000.0); + + puts("Initialize View"); + eTick = osg::Timer::instance()->tick(); + + EyePoint* globalEyePoint = new GlobalEyePoint(); + globalEyePoint->setTarget(roboObj1); + globalEyePoint->setTarget(movObj); + + //ここは後で書き直す -> + PlayerEyePoint* playerEyePoint = new PlayerEyePoint(roboObj1); + playerEyePoint->setOwner(roboObj1); + + addMovableObject(globalEyePoint); + addMovableObject(playerEyePoint); + + Player* player1 = new Player("Player1", roboObj1, playerEyePoint); + + SDL_Joystick *joy = SDL_JoystickOpen(0); + KeyboardEventHandler* keh = new KeyboardEventHandler(); + + bool canUseJoy = (joy != NULL && SDL_JoystickNumHats(joy)); + canUseJoy = false; // joypad動かないので保留 + + if (canUseJoy) { + player1->registerJOY(joy); + } else { + player1->registerKEH(keh); + } + + // view one + { + osgViewer::View* view = new osgViewer::View; + viewer.addView(view); + + view->setSceneData(root); + view->getCamera()->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); + view->getCamera()->setGraphicsContext(gc.get()); + view->setCameraManipulator(globalEyePoint->getManpulator()); + + // add the state manipulator + osg::ref_ptr statesetManipulator = new osgGA::StateSetManipulator; + statesetManipulator->setStateSet(view->getCamera()->getOrCreateStateSet()); + view->addEventHandler(keh); + } + + // view two + { + osgViewer::View* view = new osgViewer::View; + viewer.addView(view); + view->setSceneData(root); + view->getCamera()->setViewport(new osg::Viewport(0, traits->height/3*2, traits->width/3, traits->height/3)); + view->getCamera()->setGraphicsContext(gc.get()); + view->setCameraManipulator(playerEyePoint->getManpulator()); + } + + viewer.realize(); + //viewer.addEventHandler(keh); + + eTick = osg::Timer::instance()->tick(); + printf("ok.. (%.6f msec)\n", osg::Timer::instance()->delta_s(sTick, eTick)*1000.0); + + osg::Timer_t startFrameTick, moveFrameTick, renderFrameTick; + std::list::iterator mobIter; + + const int SAMPLE_RATE = Martial::CONFIG::FRAME_RATE/2; + int frame; + float frameAverageTime, renderAvarageTime, moveAverageTime, frameTime; + frame = frameAverageTime = renderAvarageTime = moveAverageTime = 0; + + puts("[Game Main Loop]"); + + //メインループ + while (!viewer.done()) { + startFrameTick = osg::Timer::instance()->tick(); + + player1->frame(); + + //SceneGraphの走査 -> 座標計算, 衝突判定 + //衝突処理はcheckCollision内部で行なう?(未実装) + for(mobIter = movableObjectList.begin(); mobIter != movableObjectList.end(); ++mobIter) { + (*mobIter)->frame(); + } + + //衝突判定 - CollisionDetector にまかせる + collisionDetector->frame(); + + //描画 ここで一番時間がかかる + moveFrameTick = osg::Timer::instance()->tick(); + moveAverageTime += osg::Timer::instance()->delta_s(startFrameTick, moveFrameTick); + + viewer.frame(); + + renderFrameTick = osg::Timer::instance()->tick(); + renderAvarageTime += osg::Timer::instance()->delta_s(moveFrameTick, renderFrameTick); + + frameAverageTime += (frameTime = osg::Timer::instance()->delta_s(startFrameTick, renderFrameTick)); + + frame++; + if (Martial::TEST::SHOW_FPS) { + if (frame == SAMPLE_RATE) { + printf("\nfps: %.3f\n (move: %.6f msec, render: %.6f msec)\n\n", (float)SAMPLE_RATE/frameAverageTime, + moveAverageTime*1000.0/(float)SAMPLE_RATE, renderAvarageTime*1000.0/(float)SAMPLE_RATE); + frame = frameAverageTime = renderAvarageTime = moveAverageTime = 0; + } + } + + if (frameTime < Martial::CONFIG::FRAME_MIN_TIME) { + OpenThreads::Thread::microSleep(1000000.0*(Martial::CONFIG::FRAME_MIN_TIME-frameTime)); + } + } + return; +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/GameManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/GameManager.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,65 @@ +/* + * GameManager.h + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +/*! + @class GameManager + @abstract ゲーム全体の処理を司るクラス + @discussion SceneGraph上のノードの操作を行なう + プログラム全体から参照される値(フレーム値)などの定義も +*/ + +#ifndef _GAME_MANAGER_HEADER_ +#define _GAME_MANAGER_HEADER_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "Martial.h" +#include "GlobalEyePoint.h" +#include "PlayerEyePoint.h" +#include "KeyboardEventHandler.h" +#include "Robot.h" +#include "CollisionDetector.h" +#include "Player.h" + +class GameManager { + private: + /*! @var MovableObject + @abstract SceneGraph上の座標演算,衝突判定を行なうMovableObjectのlist + @discussion listより良いデータ構造があるかもしれないけど、とりあえずlistで。*/ + std::list movableObjectList; + + CollisionDetector* collisionDetector; + osg::Group* root; + + void initStage(); + public: + GameManager(); + void gameStart(); + void addMovableObject(MovableObject* mob); + void addEyePoint(EyePoint* eye); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/GlobalEyePoint.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/GlobalEyePoint.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,69 @@ +/* + * GlobalEyePoint.cpp + * Martial + * + * Created by ryoma on 10/01/28. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "GlobalEyePoint.h" + +GlobalEyePoint::GlobalEyePoint(char* name) : EyePoint(name) { + Tman = new osgGA::TrackballManipulator(); + offset = osg::Vec3(0,10,-2); + direction = osg::Vec3(0, 0, 90); +} + +void GlobalEyePoint::setTarget(MovableObject* _target) { + targets.push_back(_target); +} + +void GlobalEyePoint::frame() { + osg::Matrixd myCameraMatrix; + osg::Matrixd cameraRotation; + osg::Matrixd cameraTrans; + osg::Matrixd centerTrans; + + std::list::iterator iter; + + osg::Vec3 center = osg::Vec3(0,0,0), tmp; + float minX, maxX, minY, maxY, minZ, maxZ, length; + + for (iter = targets.begin(); iter != targets.end(); ++iter) { + tmp = (*iter)->getPos(); + + if (tmp.x() < minX) { + minX = tmp.x(); + } else if (tmp.x() > maxX) { + maxX = tmp.x(); + } + + if (tmp.x() < minY) { + minY = tmp.y(); + } else if (tmp.y() > maxY) { + maxY = tmp.y(); + } + + if (tmp.z() < minZ) { + minZ = tmp.z(); + } else if (tmp.z() > maxZ) { + minZ = tmp.z(); + } + + center += tmp; + } + + length = (osg::Vec3(maxX+minX, maxY+minY, maxZ+minZ).length()) * Martial::CONFIG::WINDOW_WIDTH / 500; + + if (length < 10.0) length = 10.0; + + center /= (float)targets.size(); + + position = osg::Vec3(center.x(), length, center.z())+offset; + + cameraRotation.makeRotate(direction.z(), osg::Vec3(0,0,1)); + myCameraMatrix.makeLookAt(position, center, osg::Vec3(0,0,1) * cameraRotation); + + Tman->setByInverseMatrix(myCameraMatrix); +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/GlobalEyePoint.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/GlobalEyePoint.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,25 @@ +/* + * GlobalEyePoint.h + * Martial + * + * Created by ryoma on 10/01/28. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _GLOBAL_EYE_POINT_H_ +#define _GLOBAL_EYE_POINT_H_ + +#include "EyePoint.h" + +class GlobalEyePoint : public EyePoint { + protected: + std::list targets; + public: + GlobalEyePoint(char* name = "GlobalEyePoint"); + void setTarget(MovableObject* _target); + void frame(); + void removeTarget(MovableObject* _target); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Humanoid.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Humanoid.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,55 @@ +/* + * Humanoid.h + * Martial + * + * Created by ryoma on 10/01/27. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _HUMANOID_H_ +#define _HUMANOID_H_ + +#include "Avatar.h" + +/*! + @class Humanoid + @abstract Avatarの実装。人型のキャラクター + @discussion パーツ定義をどうしようか検討中 +*/ + + +class Humanoid : public Avatar { + protected: + osg::Node* humanoidNode; + osg::Node* body; + osg::Node* leftArm; + osg::Node* rightArm; + osg::Node* leftLeg; + osg::Node* rightLeg; + osg::PositionAttitudeTransform* humanoidForm; + osg::MatrixTransform* bodyForm; + osg::MatrixTransform* headForm; + osg::MatrixTransform* leftUpperArmForm; + osg::MatrixTransform* rightUpperArmForm; + osg::MatrixTransform* leftDownArmForm; + osg::MatrixTransform* rightDownArmForm; + osg::MatrixTransform* leftUpperLegForm; + osg::MatrixTransform* rightUpperLegForm; + osg::MatrixTransform* leftDownLegForm; + osg::MatrixTransform* rightDownLegForm; + float moveCount; + virtual void walk() {}; + virtual void turn() {}; + virtual void jump() {}; + virtual void run() {}; + virtual void squat() {}; + virtual void down() {}; + virtual void wait() {}; + virtual void freeze() {}; + virtual void stop() {}; + public: + Humanoid(char* name) : Avatar::Avatar(name) {}; +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/KeyboardEventHandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/KeyboardEventHandler.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,57 @@ +#include "KeyboardEventHandler.h" + +bool KeyboardEventHandler::addFunction (int whatKey, keyStatusType keyPressStatus, functionType newFunction, Player *target) { + keyFunctionMap &FuncMap = (keyPressStatus == KEY_DOWN) ? keyFuncMap : keyUPFuncMap; + + if (FuncMap.end() != FuncMap.find(whatKey)) { + std::cout << "duplicate key '" << whatKey << "' ignored." << std::endl; + return false; + } + else { + FuncMap[whatKey].keyFunction = newFunction; + FuncMap[whatKey].target = target; + return true; + } +} + +bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { + bool newKeyDownEvent = false; + bool newKeyUpEvent = false; + Player *target; + functionType ft; + + switch(ea.getEventType()) { + case(osgGA::GUIEventAdapter::KEYDOWN): { + keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey()); + if (itr != keyFuncMap.end()) { + if ( (*itr).second.keyState == KEY_UP ) { + (*itr).second.keyState = KEY_DOWN; + newKeyDownEvent = true; + } + if (newKeyDownEvent) { + target = (*itr).second.target; + ft = (*itr).second.keyFunction; + (target->*ft)(); + } + return true; + } + return false; + } + case(osgGA::GUIEventAdapter::KEYUP): { + keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey()); + if (itr != keyFuncMap.end()) { + (*itr).second.keyState = KEY_UP; + } + itr = keyUPFuncMap.find(ea.getKey()); + if (itr != keyUPFuncMap.end()) { + target = (*itr).second.target; + ft = (*itr).second.keyFunction; + (target->*ft)(); + return true; + } + return false; + } + default: + return false; + } +} diff -r 143f7b9f867d -r 5727d511a13a src/KeyboardEventHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/KeyboardEventHandler.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,65 @@ +#ifndef KEYBOARD_HANDLER_H +#define KEYBOARD_HANDLER_H +#include +#include + +class Player; + +/*! + @header KeyboardHandler + @abstract Keyboard入力のコールバック関数を司るクラス + @discussion Keyboardの入力とPlayer(インターフェース)を実装したクラスの関数のポインタをハッシュで保持 +*/ + +class KeyboardEventHandler : public osgGA::GUIEventHandler { + public: + + /*! @typedef functionType @abstract Playerの仮想関数へのポインタ */ + typedef void (Player::*functionType)(); + + /*! + @enum keyStatusType + @abstract Key入力の状態 + @constant KEY_UP ボタンを入力 + @constant KEY_UP ボタンを解放 + */ + enum keyStatusType { + KEY_UP, KEY_DOWN + }; + + /*! + @function addFunction + @abstract コールバック関数の登録 + @param whatKey キー入力の値(ascii) + @param newFunction 登録する関数のポインタ + @param target 関数を実行するインスタンス + */ + bool addFunction(int whatKey, functionType newFunction, Player *player); + bool addFunction(int whatKey, keyStatusType keyPressStatus, functionType newFunction, Player *player); + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); + virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }; + + protected: + /*! + @struct functionStatusType + @abstract Playerの関数登録の引数 + @field target 関数を呼び出すPlayerのインスタンス + */ + struct functionStatusType { + functionStatusType() {keyState = KEY_UP; keyFunction = NULL;} + functionType keyFunction; + keyStatusType keyState; + Player* target; + }; + + /*! @typedef keyFunctionMap @abstract コールバック関数とキー入力のハッシュ */ + typedef std::map keyFunctionMap; + + /*! @var keyFunctionMap ボタン押し時のコールバック関数のハッシュ */ + keyFunctionMap keyFuncMap; + + /*! @var keyFunctionMap ボタン押し時のコールバック関数のハッシュ */ + keyFunctionMap keyUPFuncMap; +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Martial.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Martial.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,17 @@ +/* + * Martial.cpp + * Martial + * + * Created by ryoma on 10/01/28. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "Martial.h" + +void Martial::TEST::print(char* format, ...) { + va_list argptr; + va_start(argptr, format); + vprintf(format, argptr); + va_end(argptr); +} diff -r 143f7b9f867d -r 5727d511a13a src/Martial.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Martial.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,48 @@ +/* + * Martial.h + * Martial + * + * Created by ryoma on 10/01/27. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +/*! + @header Martial + @abstract debug, test用の定数を設定 +*/ + +#ifndef _MARTIAL_H_ +#define _MARTIAL_H_ + +#include +#include + +namespace Martial { + + namespace CONFIG { + /*! @const FRAME_RATE @abstract Frames Per Second */ + const int FRAME_RATE = 60.0; + /*! @const FRAME_MIN_TIME @abstract Frame毎の処理時間 */ + const float FRAME_MIN_TIME = 1.0 / FRAME_RATE; + /*! @const WINDOW_WIDTH @abstract Frame毎の処理時間 */ + const int WINDOW_WIDTH = 1000; + /*! @const WINDOW_HEIGHT @abstract Frame毎の処理時間 */ + const int WINDOW_HEIGHT = 800; + } + + namespace TEST { + /*! @const SHOW_FPS fpsの表示 (-> GameManager.cpp) */ + const bool SHOW_FPS = true; + /*! @const SHOW_COLLISION 衝突の表示 (-> GameManager.cpp) */ + const bool SHOW_COLLISION = false; + /*! @const SHOW_AVATAR_INPUT Playerから見た入力の表示 */ + const bool SHOW_PLAYER_INPUT = false; + /*! @const SHOW_AVATAR_INPUT Avatarから見た入力の表示 */ + const bool SHOW_AVATAR_INPUT = false; + + void print(char* format, ...); + } +} + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/MovableObject.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MovableObject.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,151 @@ +/* + * MovableObject.cpp + * Race + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "MovableObject.h" +#include "GameManager.h" + +/** MovableObjectのコンストラクタ. + * osg::Nodeを描画物体として受け取り、動く物体を生成する + * @param _node 描画されるノード, _name ノードの名前 + */ + +MovableObject::MovableObject(char* _name) { + init(); + scale = osg::Vec3(1.0,1.0,1.0); + defaultDirection = osg::Vec3(0.0,0.0,0.0); + name = _name; + mform = new osg::MatrixTransform(); + frame(); +} + +MovableObject::MovableObject(osg::Node* _node, char* _name) { + init(); + name = _name; + node = _node; + mform = new osg::MatrixTransform(); + mform->addChild(node); +} + +void MovableObject::init() { + position = osg::Vec3(0.0,0.0,0.0); + velocity = osg::Vec3(0.0,0.0,0.0); + acceleration = osg::Vec3(0.0,0.0,0.0); + angularVelocity = osg::Vec3(0.0,0.0,0.0); + direction = osg::Vec3(0.0,0.0,0.0); +} + +void MovableObject::move(osg::Vec3 s) { +} + +void MovableObject::rotate(osg::Vec3 r) { +} + +void MovableObject::accelerate(osg::Vec3 a) { + velocity += a; +} + +void MovableObject::setPos(osg::Vec3 p) { + position = p; +} + +void MovableObject::setVel(osg::Vec3 v) { + velocity = v; +} + +void MovableObject::setAcc(osg::Vec3 a) { + acceleration = a; +} + +void MovableObject::setDir(osg::Vec3 r) { + direction = r; +} + +void MovableObject::setDefaultDirection(osg::Vec3 r) { + defaultDirection = r; +} + +void MovableObject::setAngularVelocity(osg::Vec3 r) { + angularVelocity = r; +} + +void MovableObject::setScale(osg::Vec3 s) { + scale = s; +} + +osg::Vec3 MovableObject::getPos() { + return position; +} + +osg::Vec3 MovableObject::getVel() { + return velocity; +} + +osg::Vec3 MovableObject::getAcc() { + return acceleration; +} + +osg::Vec3 MovableObject::getDir() { + return direction; +} + +osg::Vec3 MovableObject::getDefaultDirection() { + return defaultDirection; +} + +char* MovableObject::getName() { + return name; +} + +osg::MatrixTransform* MovableObject::getForm() { + return mform; +} + +void MovableObject::dump() { +} + +/* 位置,体勢の再計算のみ */ +void MovableObject::frame() { + osg::Matrixd roteMatrix; + osg::Matrixd accMatrix; + osg::Matrixd dirMatrix; + + direction += angularVelocity; + accMatrix.makeTranslate(acceleration); + roteMatrix.makeRotate( + osg::Quat( + defaultDirection.x(), osg::Vec3(1,0,0), + defaultDirection.y(), osg::Vec3(0,1,0), + defaultDirection.z(), osg::Vec3(0,0,1) + ) + ); + + velocity += (accMatrix*roteMatrix).getTrans(); + position += velocity; + + /* 3Dモデルが元々正面向きのため、90度補正の再計算 */ + /* 毎回計算が無駄だと思うので、ツール側で補正するべき */ + /*roteMatrix.makeRotate( + osg::Quat( + defaultDirection.x()+direction.x(), osg::Vec3(1,0,0), + defaultDirection.y()+direction.y(), osg::Vec3(0,1,0), + defaultDirection.z()+direction.z(), osg::Vec3(0,0,1) + ) + );*/ + + dirMatrix.makeTranslate(position); + accMatrix.makeScale(scale); + mform->setMatrix(accMatrix*accMatrix*roteMatrix); +} + +void MovableObject::checkCollision() { +} + +void MovableObject::collision(osg::Vec3 pos, osg::Vec3 reaction) { + +} diff -r 143f7b9f867d -r 5727d511a13a src/MovableObject.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MovableObject.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,84 @@ +/* + * MovableObject.h + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +/*! + @class MovableObject + @abstract SceneGraph上の更新が行なわれるオブジェクト + @discussion (キャラクタ,弾丸などSceneGraph上のノード) +*/ + +#ifndef _MOVABLE_OBJECT_H_ +#define _MOVABLE_OBJECT_H_ + +class MovableObject { + protected: + /*! @var name + @abstract 物体の名前 */ + char* name; + /*! @var position + @abstract 物体の座標 */ + osg::Vec3 position; + /*! @var velocity + @abstract 物体の速度 */ + osg::Vec3 velocity; + /*! @var acceleration + @abstract 物体の加速度 */ + osg::Vec3 acceleration; + /*! @var angularVelocity + @abstract 物体の角速度 */ + osg::Vec3 angularVelocity; + /*! @var direction @abstract + 物体の向いてる方向(ラジアン) */ + osg::Vec3 direction; + /*! @var defaultDirection + @abstract 物体のデフォルトの向き(ラジアン) */ + osg::Vec3 defaultDirection; + /*! @var node + @abstract osgで表示するノード */ + osg::Node* node; + /*! @var scale + @abstract ノードのレンダリングスケール */ + osg::Vec3 scale; + /*! @var weight + @abstract ノードの重量(重力処理、衝突処理で使用?) */ + osg::Vec3 weight; + /*! @var mfrom + @abstract osgの描画情報. 位置,スケール,角度を行列で表す */ + osg::MatrixTransform* mform; + public: + MovableObject(char* name = "MovableObject"); + MovableObject(osg::Node* _node = NULL, char* = "MovableObject"); + void move(osg::Vec3 s); + void rotate(osg::Vec3 r); + void accelerate(osg::Vec3 a); + void setPos(osg::Vec3 p); + void setVel(osg::Vec3 v); + void setAcc(osg::Vec3 a); + void setDir(osg::Vec3 r); + void setAngularVelocity(osg::Vec3 r); + void setDefaultDirection(osg::Vec3 r); + void setScale(osg::Vec3 s); + void modifyForm(); + osg::Vec3 getPos(); + osg::Vec3 getVel(); + osg::Vec3 getAcc(); + osg::Vec3 getDir(); + osg::Vec3 getDefaultDirection(); + osg::NodePathList* getNodePath(); + float getRadius(); + char* getName(); + virtual void init(); + virtual void frame(); + virtual void checkCollision(); + virtual void collision(osg::Vec3 pos, osg::Vec3 reaction); + virtual osg::MatrixTransform* getForm(); + virtual void dump(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Player.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Player.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,185 @@ +/* + * Player.cpp + * Martial + * + * Created by ryoma on 10/01/27. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "Player.h" + +void Player::registerKEH(KeyboardEventHandler* keh) { + frameFunc = &Player::frameKEY; + hatFlag[0] = false; hatFlag[1] = false; hatFlag[2] = false; hatFlag[3] = false; + keh->addFunction('i',KeyboardEventHandler::KEY_DOWN, &Player::pushUp, this); + keh->addFunction('i',KeyboardEventHandler::KEY_UP, &Player::releaseUp, this); + keh->addFunction(',',KeyboardEventHandler::KEY_DOWN, &Player::pushDown, this); + keh->addFunction(',',KeyboardEventHandler::KEY_UP, &Player::releaseDown, this); + keh->addFunction('j',KeyboardEventHandler::KEY_DOWN, &Player::pushLeft, this); + keh->addFunction('j',KeyboardEventHandler::KEY_UP, &Player::releaseLeft, this); + keh->addFunction('l',KeyboardEventHandler::KEY_DOWN, &Player::pushRight, this); + keh->addFunction('l',KeyboardEventHandler::KEY_UP, &Player::releaseRight, this); + keh->addFunction('a',KeyboardEventHandler::KEY_DOWN, &Player::pushA, this); + keh->addFunction('a',KeyboardEventHandler::KEY_UP, &Player::releaseA, this); + keh->addFunction('b',KeyboardEventHandler::KEY_DOWN, &Player::pushB, this); + keh->addFunction('b',KeyboardEventHandler::KEY_UP, &Player::releaseB, this); + keh->addFunction('c',KeyboardEventHandler::KEY_DOWN, &Player::pushC, this); + keh->addFunction('c',KeyboardEventHandler::KEY_UP, &Player::releaseC, this); + keh->addFunction('d',KeyboardEventHandler::KEY_DOWN, &Player::pushD, this); + keh->addFunction('d',KeyboardEventHandler::KEY_UP, &Player::releaseD, this); + keh->addFunction('1',KeyboardEventHandler::KEY_DOWN, &Player::push1, this); + keh->addFunction('2',KeyboardEventHandler::KEY_DOWN, &Player::push2, this); +} + +void Player::registerJOY(SDL_Joystick* _joy) { + frameFunc = &Player::frameJOY; + prev = SDL_HAT_CENTERED; + joy = _joy; +} + +void Player::frame() { + (this->*frameFunc)(); +} + +void Player::frameKEY() { + if (Martial::TEST::SHOW_PLAYER_INPUT) printf("[%d,%d,%d,%d]\n",hatFlag[0],hatFlag[1],hatFlag[2],hatFlag[3]); + + if (!(hatFlag[PUSH_UP]||hatFlag[PUSH_DOWN] + ||hatFlag[PUSH_RIGHT]||hatFlag[PUSH_LEFT])) { + avatar->releaseHat(); + }else if (hatFlag[PUSH_RIGHT]) { + if (hatFlag[PUSH_LEFT]) { + avatar->releaseHat(); + } else if (hatFlag[PUSH_UP]) { + avatar->pushRightUp(); + } else if (hatFlag[PUSH_DOWN]) { + avatar->pushRightDown(); + } else { + avatar->pushRight(); + } + } else if (hatFlag[PUSH_UP]) { + if (hatFlag[PUSH_LEFT]) { + avatar->pushLeftUp(); + } else { + avatar->pushUp(); + } + } else if (hatFlag[PUSH_DOWN]) { + if (hatFlag[PUSH_LEFT]) { + avatar->pushLeftDown(); + } else { + avatar->pushDown(); + } + } else { + avatar->pushLeft(); + } +} + +void Player::frameJOY() { + printf("opend?, hatNums = %d\n\n", SDL_JoystickOpened(0), SDL_JoystickNumHats(joy)); + SDL_JoystickUpdate(); + + if (SDL_JoystickGetHat(joy, SDL_HAT_CENTERED) == SDL_PRESSED) { + puts("center"); + if (prev != SDL_HAT_CENTERED) { + avatar->releaseHat(); + } + } else if (SDL_JoystickGetHat(joy, SDL_HAT_UP) == SDL_PRESSED) { + avatar->pushUp(); + } else if (SDL_JoystickGetHat(joy, SDL_HAT_RIGHT) == SDL_PRESSED) { + avatar->pushRight(); + } else if (SDL_JoystickGetHat(joy, SDL_HAT_DOWN) == SDL_PRESSED) { + avatar->pushDown(); + } else if (SDL_JoystickGetHat(joy, SDL_HAT_LEFT) == SDL_PRESSED) { + avatar->pushLeft(); + } else { puts("unknown"); } +} + +void Player::pushLeft() { + hatFlag[PUSH_LEFT] = true; +} + +void Player::releaseLeft() { + hatFlag[PUSH_LEFT] = false; +} + +void Player::pushRight() { + hatFlag[PUSH_RIGHT] = true; +} + +void Player::releaseRight() { + hatFlag[PUSH_RIGHT] = false; +} + +void Player::pushUp() { + hatFlag[PUSH_UP] = true; +} + +void Player::releaseUp() { + hatFlag[PUSH_UP] = false; +} + +void Player::pushDown() { + hatFlag[PUSH_DOWN] = true; +} + +void Player::releaseDown() { + hatFlag[PUSH_DOWN] = false; +} + +void Player::pushA() { + avatar->pushA(); +} + +void Player::releaseA() { + avatar->releaseA(); +} + +void Player::pushB() { + avatar->pushB(); +} + +void Player::releaseB() { + avatar->releaseB(); +} + +void Player::pushC() { + avatar->pushC(); +} + +void Player::releaseC() { + avatar->releaseC(); +} + +void Player::pushD() { + avatar->pushD(); +} + +void Player::releaseD() { + avatar->releaseD(); +} + +void Player::push1() { + +} + +void Player::push2() { +} + +void Player::pushRightUp() { +} + +void Player::pushRightDown() { +} + +void Player::pushLeftUp() { +} + +void Player::pushLeftDown() { +} + +void Player::releaseHat() { +} + +void Player::releaseButton() { +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Player.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Player.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,91 @@ +/* + * Player.h + * Martial + * + * Created by ryoma on 10/01/27. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _PLAYER_H_ +#define _PLAYER_H_ + +#include +#include "Avatar.h" +#include "EyePoint.h" +#include "KeyboardEventHandler.h" + +/*! + @class Player + @abstract ゲームのキャラクター(Avatar),視点(EyePoint)を操作するPlayer + Keyboardからのコールバック関数をhandlerに登録する +*/ + +class Player { + private: + Avatar* avatar; + EyePoint* eyePoint; + SDL_Joystick* joy; + char* name; + Uint8 prev; + bool hatFlag[4]; + void (Player::*frameFunc)(); + public: + enum functionIndex { + PUSH_UP, PUSH_RIGHT, PUSH_LEFT, PUSH_DOWN, + RELEASE_UP, RELEASE_RIGHT, RELEASE_LEFT, RELEASE_DOWN, + PUSH_A, PUSH_B, PUSH_C, PUSH_D, + RELEASE_A, RELEASE_B, RELEASE_C, RELEASE_D + }; + Player(char* name, Avatar* avatar, EyePoint* eyePoint) : + name(name), avatar(avatar), eyePoint(eyePoint), frameFunc(&Player::frameKEY) {}; + /*! + @function pushLeft(), releaseLeft(), pushRight(), releaseRight(), pushUp(), releaseUp(), + pushDown(), releaseDown(), pushA(), releaseA(), pushB(), releaseB(), + pushC(), releaseC(), pushD(), releaseD(), push1(), release2(), + @abstract KeyboardEventHanderでHandle設定できるControllableクラスの関数群(インターフェース) + @discussion Javaでいう interface (でも、純粋仮想関数ではない。デフォルトではなにもしないように) + */ + void initHat(); + void releaseHat(); + void releaseButton(); + void pushRightUp(); + void pushRightDown(); + void pushLeftUp(); + void pushLeftDown(); + void pushLeft(); + void releaseLeft(); + void pushRight(); + void releaseRight(); + void pushUp(); + void releaseUp(); + void pushDown(); + void releaseDown(); + void pushA(); + void releaseA(); + void pushB(); + void releaseB(); + void pushC(); + void releaseC(); + void pushD(); + void releaseD(); + void push1(); + void push2(); + + /*! + @function getKEH() + @param Martialのコールバックを登録したHandler + @abstract Playerの入力コールバックを登録 + @discussion 複数プレイヤーで入力が衝突しないようにするには? + ? 別々のAsciiを割り当てる(PlayerにIDを振る) ? + → いや、そもそもKeybaordじゃ厳しいよね。 + → COM Playerはどうしよう? + */ + void registerKEH(KeyboardEventHandler* keh); + void registerJOY(SDL_Joystick* joy); + void frame(); + void frameJOY(); + void frameKEY(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/PlayerEyePoint.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/PlayerEyePoint.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,48 @@ +/* + * PlayerEyePoint.cpp + * Martial + * + * Created by ryoma on 10/01/28. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "PlayerEyePoint.h" + +PlayerEyePoint::PlayerEyePoint(MovableObject *owner): + EyePoint(owner->getName()), owner(owner){ + position = osg::Vec3(-10,0,2); + direction = osg::Vec3(0, 0, 0); + target = NULL; + relativeRotate = true; +} + +void PlayerEyePoint::setRelativeRotate(bool rr) { + relativeRotate = rr; +} + +void PlayerEyePoint::setTarget(MovableObject* _target) { + target = _target; +} + +void PlayerEyePoint::setOwner(MovableObject* _owner) { + owner = _owner; +} + +void PlayerEyePoint::frame() { + osg::Matrixd myCameraMatrix; + osg::Matrixd rotation; + osg::Matrixd cameraTrans; + osg::Matrixd ownerTrans; + + cameraTrans.makeTranslate(position); + ownerTrans.makeTranslate(owner->getPos()); + + /* if relativeRotate is false, relativeRoate * target->getDir().z() always equals 0 */ + rotation.makeRotate(relativeRotate*owner->getDir().z()+direction.z(), osg::Vec3(0,0,1)); + + myCameraMatrix = cameraTrans * rotation * ownerTrans; + + myCameraMatrix.makeLookAt(myCameraMatrix.getTrans(), owner->getPos(), osg::Vec3(0,0,1) * rotation); + Tman->setByInverseMatrix(myCameraMatrix); +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/PlayerEyePoint.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/PlayerEyePoint.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,28 @@ +/* + * PlayerEyePoint.h + * Martial + * + * Created by ryoma on 10/01/28. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _PLAYER_EYE_POINT_H_ +#define _PLAYER_EYE_POINT_H_ + +#include "EyePoint.h" + +class PlayerEyePoint : public EyePoint { + protected: + MovableObject* owner; + MovableObject* target; + bool relativeRotate; + public: + PlayerEyePoint(MovableObject* owner); + void frame(); + void setTarget(MovableObject* target); + void setOwner(MovableObject* owner); + void setRelativeRotate(bool rr); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Robot.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Robot.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,348 @@ +/* + * Robot.cpp + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "Robot.h" + +Robot::Robot(char* _name) : Humanoid::Humanoid(_name) { + moveCount = 0.0; + scale = osg::Vec3(0.01,0.01,0.01); + + humanoidNode = osgDB::readNodeFile("robot.osg"); + humanoidForm = new osg::PositionAttitudeTransform(); + humanoidForm->addChild(humanoidNode); + mform->addChild(humanoidForm); + + //ノードにアクセス。MatrixTransformをnameで検索(visitor内部で std::map で保持) + SearchMatrixTransformVisitor visitor = SearchMatrixTransformVisitor(); + + humanoidNode->accept(visitor); + bodyForm = visitor.getMatrixTransform("body"); + leftUpperArmForm = visitor.getMatrixTransform("left_arm1"); + rightUpperArmForm = visitor.getMatrixTransform("right_arm1"); + leftDownArmForm = visitor.getMatrixTransform("left_arm2"); + rightDownArmForm = visitor.getMatrixTransform("right_arm2"); + leftUpperLegForm = visitor.getMatrixTransform("left_leg1"); + rightUpperLegForm = visitor.getMatrixTransform("right_leg1"); + leftDownLegForm = visitor.getMatrixTransform("left_leg2"); + rightDownLegForm = visitor.getMatrixTransform("right_leg2"); + + //衝突判定ノードの追加 + CollisionNode* collisionNode; + + bodyForm->setMatrix(osg::Matrix()); + + collisionNode = new CollisionNode("Body-Node1", new osg::Sphere(osg::Vec3(0, 0, 0), 50)); + bodyForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Body-Node2", new osg::Sphere(osg::Vec3(0, 0, 60), 50)); + bodyForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Body-Node3", new osg::Sphere(osg::Vec3(0, 0, -60), 50)); + bodyForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Left-Arm-Node", new osg::Sphere(osg::Vec3(100, -40, -70), 30)); + leftUpperArmForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Right-Arm-Node", new osg::Sphere(osg::Vec3(-100, -40, -70), 30)); + rightUpperArmForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Left-Leg-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 30)); + leftUpperLegForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + collisionNode = new CollisionNode("Right-Leg-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 30)); + rightUpperLegForm->addChild(collisionNode->getGeode()); + collisionNodeList.push_back(collisionNode); + + SearchGeodeVisitor gvisitor = SearchGeodeVisitor(); + + gvisitor.setSearchGeodeName("Collision_right_leg1_geode"); + humanoidNode->accept(gvisitor); + + //std::cout << "getVisitor: result = " << gvisitor.getGeode().getName(); << "\n"; + + unWaitFunc = &Robot::nop; + funcs[PUSH_LEFT] = &Robot::walk; + funcs[PUSH_RIGHT] = &Robot::turn; + funcs[PUSH_UP] = &Robot::jump; + funcs[PUSH_DOWN] = &Robot::squat; + funcs[PUSH_RIGHTUP] = &Robot::jump; + funcs[PUSH_LEFTUP] = &Robot::jump; + funcs[PUSH_RIGHTDOWN] = &Robot::walk; + funcs[PUSH_LEFTDOWN] = &Robot::walk; + funcs[RELEASE_HAT] = &Robot::stop; + funcs[PUSH_A] = &Robot::punch; + funcs[PUSH_B] = &Robot::nop; + funcs[PUSH_C] = &Robot::nop; + funcs[PUSH_D] = &Robot::nop; + funcs[RELEASE_BUTTON] = &Robot::stop; +} + +void Robot::releaseHat() { + printInput("Class Robot [%s] :: RELEASE-HAT\n", name); + (this->*funcs[RELEASE_HAT])(); +} + +void Robot::pushLeft() { + printInput("Class Robot [%s] :: PUSH-LEFT\n", name); + (this->*funcs[PUSH_LEFT])(); +} + +void Robot::pushRight() { + printInput("Class Robot [%s] :: PUSH-RIGHT\n", name); + (this->*funcs[PUSH_RIGHT])(); +} + +void Robot::pushUp() { + printInput("Class Robot [%s] :: PUSH-UP\n", name); + (this->*funcs[PUSH_UP])(); +} + +void Robot::pushDown() { + printInput("Class Robot [%s] :: PUSH-DOWN\n", name); + //(this->*funcs[PUSH_RIGHTDOWN])(); + (this->*funcs[PUSH_A])(); +} + +void Robot::pushRightUp() { + printInput("Class Robot [%s] :: PUSH-RIGHT-UP\n", name); + (this->*funcs[PUSH_RIGHTUP])(); +} +void Robot::pushRightDown() { + printInput("Class Robot [%s] :: PUSH-RIGHT-DOWN\n", name); + (this->*funcs[PUSH_RIGHTDOWN])(); +} +void Robot::pushLeftUp() { + printInput("Class Robot [%s] :: PUSH-LEFT-UP\n", name); + (this->*funcs[PUSH_RIGHTUP])(); +} + +void Robot::pushLeftDown() { + printInput("Class Robot [%s] :: PUSH-LEFT-DOWN\n", name); + (this->*funcs[PUSH_LEFTDOWN])(); +} + +void Robot::pushA() { + printInput("Class Robot [%s] :: PUSH-A\n", name); + (this->*funcs[PUSH_A])(); +} + +void Robot::releaseA() { + printInput("Class Robot [%s] :: RELEASE-A\n", name); +} + +void Robot::pushB() { + printInput("Class Robot [%s] :: PUSH-B\n", name); + (this->*funcs[PUSH_B])(); +} + +void Robot::releaseB() { + printInput("Class Robot [%s] :: RELASE-B\n", name); +} + +void Robot::pushC() { + printInput("Class Robot [%s] :: PUSH-C\n", name); + (this->*funcs[PUSH_C])(); +} + +void Robot::releaseC() { + printInput("Class Robot [%s] :: RELEASE-C\n", name); +} + +void Robot::pushD() { + printInput("Class Robot [%s] :: PUSH-D\n", name); + (this->*funcs[PUSH_D])(); +} + +void Robot::releaseD() { + printInput("Class Robot [%s] :: RELEASE-D\n", name); +} + +void Robot::stackPush() { + stack[PUSH_LEFT] = funcs[PUSH_LEFT]; + stack[PUSH_RIGHT] = funcs[PUSH_RIGHT]; + stack[PUSH_UP] = funcs[PUSH_UP]; + stack[PUSH_DOWN] = funcs[PUSH_DOWN]; + stack[PUSH_RIGHTUP] = funcs[PUSH_RIGHTUP]; + stack[PUSH_LEFTUP] = funcs[PUSH_LEFTUP]; + stack[PUSH_RIGHTDOWN] = funcs[PUSH_RIGHTDOWN]; + stack[PUSH_LEFTDOWN] = funcs[PUSH_LEFTDOWN]; + stack[RELEASE_HAT] = funcs[RELEASE_HAT]; + stack[PUSH_A] = funcs[PUSH_A]; + stack[PUSH_B] = funcs[PUSH_B]; + stack[PUSH_C] = funcs[PUSH_C]; + stack[PUSH_D] = funcs[PUSH_D]; + stack[RELEASE_BUTTON] = funcs[RELEASE_BUTTON]; + + funcs[PUSH_LEFT] = &Robot::wait; + funcs[PUSH_RIGHT] = &Robot::wait; + funcs[PUSH_UP] = &Robot::wait; + funcs[PUSH_DOWN] = &Robot::wait; + funcs[PUSH_RIGHTUP] = &Robot::wait; + funcs[PUSH_LEFTUP] = &Robot::wait; + funcs[PUSH_RIGHTDOWN] = &Robot::wait; + funcs[PUSH_LEFTDOWN] = &Robot::wait; + funcs[RELEASE_HAT] = &Robot::wait; + funcs[PUSH_A] = &Robot::wait; + funcs[PUSH_B] = &Robot::wait; + funcs[PUSH_C] = &Robot::wait; + funcs[PUSH_D] = &Robot::wait; + funcs[RELEASE_BUTTON] = &Robot::wait; +} + +void Robot::stackPop() { + funcs[PUSH_LEFT] = stack[PUSH_LEFT]; + funcs[PUSH_RIGHT] = stack[PUSH_RIGHT]; + funcs[PUSH_UP] = stack[PUSH_UP]; + funcs[PUSH_DOWN] = stack[PUSH_DOWN]; + funcs[PUSH_RIGHTUP] = stack[PUSH_RIGHTUP]; + funcs[PUSH_LEFTUP] = stack[PUSH_LEFTUP]; + funcs[PUSH_RIGHTDOWN] = stack[PUSH_RIGHTDOWN]; + funcs[PUSH_LEFTDOWN] = stack[PUSH_LEFTDOWN]; + funcs[RELEASE_HAT] = stack[RELEASE_HAT]; + funcs[PUSH_A] = stack[PUSH_A]; + funcs[PUSH_B] = stack[PUSH_B]; + funcs[PUSH_C] = stack[PUSH_C]; + funcs[PUSH_D] = stack[PUSH_D]; + funcs[RELEASE_BUTTON] = stack[RELEASE_BUTTON]; +} + +/* Robotの各モーションを定義 */ + +void Robot::punch() { + moveCount += 0.5; + float sinVal = sin(moveCount); + float cosVal = cos(moveCount); + + osg::Matrixd roteMatrix; + osg::Matrixd dirMatrix; + osg::Matrixd accMatrix; + //if(moveCount <= 0.5){ + bodyForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*10.0), osg::Vec3(0,0,1))); + rightUpperArmForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*60.0-90), osg::Vec3(1,0,0))); + //rightDownArmForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*60.0-20), osg::Vec3(1,0,0))); + //} +} + +void Robot::walk() { + velocity = osg::Vec3(0.5*avatarDirection,0,0); + moveCount += (float)avatarDirection * 0.5; + float sinVal = sin(moveCount); + float cosVal = cos(moveCount); + + setPos(osg::Vec3(position.x(), position.y(), position.z()+cos(moveCount)*0.01)); + + osg::Matrixd roteMatrix; + osg::Matrixd dirMatrix; + osg::Matrixd accMatrix; + + //positionAttitudeMatrix.setAttitude();での演算にくらべると、倍高速? + bodyForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*10.0), osg::Vec3(0,0,1))); + leftUpperArmForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*30.0+10), osg::Vec3(1,0,0))); + //rightUpperArmForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*-30.0+10), osg::Vec3(1,0,0))); + leftUpperLegForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*-45.0), osg::Vec3(1,0,0))); + rightUpperLegForm->setMatrix(osg::Matrixf::rotate(osg::DegreesToRadians(sinVal*45.0), osg::Vec3(1,0,0))); + +} + +void Robot::turn() { + angularVelocity = osg::Vec3(0,0,osg::DegreesToRadians(180.0/10.0)); + motionTime = 10; + avatarDirection *= -1; + void (Robot::*tmp)() = funcs[PUSH_LEFT]; + funcs[PUSH_LEFT] = funcs[PUSH_RIGHT]; + funcs[PUSH_RIGHT] = tmp; + stackPush(); + unWaitFunc = &Robot::stop; + wait(); +} + +void Robot::jump() { + funcs[PUSH_UP] = &Robot::nop; + funcs[PUSH_RIGHTUP] = &Robot::nop; + funcs[PUSH_LEFTUP] = &Robot::nop; + velocity = osg::Vec3(velocity.x(), velocity.y(), 4); + acceleration = osg::Vec3(acceleration.x(), acceleration.y(), -0.3); +} + +void Robot::stop() { + moveCount = 0; + motionTime = 0; + velocity = osg::Vec3(0,0,0); + angularVelocity = osg::Vec3(0,0,0); +} + +void Robot::wait() { + if ((--motionTime) < 0) { + (this->*unWaitFunc)(); + unWaitFunc = &Robot::nop; + stackPop(); + } +} + +//以下、未実装 + +void Robot:: run() {}; +void Robot:: squat() {}; +void Robot:: down() {}; +void Robot:: freeze() {}; + +void Robot::frame() { + update(); +} + +void Robot::update() { + + //[当たり判定の処理] - 未実装,ただ判定を消すだけ + std::list::iterator iter; + for (iter = collisionNodeList.begin(); iter != collisionNodeList.end(); ++iter) { + (*iter)->setCollision(false); + } + + osg::Matrixd roteMatrix; + osg::Matrixd dirMatrix; + osg::Matrixd accMatrix; + + direction += angularVelocity; + velocity += acceleration; + + accMatrix.makeTranslate(acceleration); + roteMatrix.makeRotate( + osg::Quat( + direction.x(), osg::Vec3(1,0,0), + direction.y(), osg::Vec3(0,1,0), + direction.z(), osg::Vec3(0,0,1) + ) + ); + + velocity += (accMatrix*roteMatrix).getTrans(); + position += velocity; + + // 地面を抜けた場合 + if (position.z() < 0) { + position.z() = 0; + funcs[PUSH_UP] = &Robot::jump; + funcs[PUSH_RIGHTUP] = &Robot::jump; + funcs[PUSH_LEFTUP] = &Robot::jump; + velocity = osg::Vec3(velocity.x(), velocity.y(), 0); + acceleration = osg::Vec3(acceleration.x(), acceleration.y(), 0); + } + + accMatrix.makeTranslate(acceleration); + roteMatrix.makeRotate( + osg::Quat( + defaultDirection.x()+direction.x(), osg::Vec3(1,0,0), + defaultDirection.y()+direction.y(), osg::Vec3(0,1,0), + defaultDirection.z()+direction.z(), osg::Vec3(0,0,1) + ) + ); + + dirMatrix.makeTranslate(position); + accMatrix.makeScale(scale); + mform->setMatrix(accMatrix*roteMatrix*dirMatrix); +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Robot.cpp.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Robot.cpp.orig Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,231 @@ +/* + * Robot.cpp + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "Robot.h" + +Robot::Robot(char* _name) : Character::Character(_name) { + name = _name; + moveCount = 0.0; + moveFlag = 0; + + reloadFunc = &Robot::reload; + + RobotNode = new osg::Group(); + body = osgDB::readNodeFile("robot_body.osg"); + + leftArm = osgDB::readNodeFile("robot_l_arm.osg"); + rightArm = osgDB::readNodeFile("robot_r_arm.osg"); + leftLeg = osgDB::readNodeFile("robot_l_leg.osg"); + rightLeg = osgDB::readNodeFile("robot_r_leg.osg"); + +// SearchMatrixTransformVisitor* visitor = new SearchMatrixTransformVisitor("Mesh133004__Black_"); +// body->accept(*visitor); +// hoge = visitor->getMatrixTransform(); + + if( hoge != NULL ) { + std::cout << "Success!! Matrix name is [" << hoge->getName() << "]\n"; + } else { + puts("False......"); + } + + bodyForm = new osg::PositionAttitudeTransform(); + leftArmForm = new osg::PositionAttitudeTransform(); + rightArmForm = new osg::PositionAttitudeTransform(); + leftLegForm = new osg::PositionAttitudeTransform(); + rightLegForm = new osg::PositionAttitudeTransform(); + + //ロボットの組み立て + + bodyForm->addChild(body); + leftArmForm->addChild(leftArm); + rightArmForm->addChild(rightArm); + leftLegForm->addChild(leftLeg); + rightLegForm->addChild(rightLeg); + + mform->addChild(bodyForm); + bodyForm->addChild(leftArmForm); + bodyForm->addChild(rightArmForm); + bodyForm->addChild(leftLegForm); + bodyForm->addChild(rightLegForm); + + //微調整。 ここはモデリングツールでやろうよ。。まじで。。 + + bodyForm->setPosition(osg::Vec3(0.0,0.0,1.5)); + leftArmForm->setPosition(osg::Vec3(0.5,-0.3,0.2)); + rightArmForm->setPosition(osg::Vec3(-0.5,-0.3,0.2)); + leftLegForm->setPosition(osg::Vec3(0.2,0,-1.2)); + rightLegForm->setPosition(osg::Vec3(-0.2,0,-1.2)); + + //衝突判定ノードの追加 + + CollisionNode* collisionNode = new CollisionNode("Body-Node", new osg::Cylinder(osg::Vec3(0, 0, 0), 0.4, 2.5)); + bodyForm->addChild(collisionNode->getNode()); + collisionNodeList.push_back(collisionNode); + + collisionNode = new CollisionNode("Left-Arm-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 0.3)); + leftArmForm->addChild(collisionNode->getNode()); + collisionNodeList.push_back(collisionNode); + + collisionNode = new CollisionNode("Right-Arm-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 0.3)); + rightArmForm->addChild(collisionNode->getNode()); + collisionNodeList.push_back(collisionNode); + + collisionNode = new CollisionNode("Left-Leg-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 0.3)); + leftLegForm->addChild(collisionNode->getNode()); + collisionNodeList.push_back(collisionNode); + + collisionNode = new CollisionNode("Right-Leg-Node", new osg::Sphere(osg::Vec3(0, 0, 0), 0.3)); + rightLegForm->addChild(collisionNode->getNode()); + collisionNodeList.push_back(collisionNode); + + reload(); +} + +void Robot::pushLeft() { + printf("Class Robott [%s] :: PUSH-LEFT\n", name); + moveFlag = 1; + setVel(osg::Vec3(1.0,0.0,0.0)); +} + +void Robot::releaseLeft() { + printf("Class Robott [%s] :: RELEASE-LEFT\n", name); + moveFlag = 0; + setVel(osg::Vec3(0,0.0,0.0)); +} + +void Robot::pushRight() { + printf("Class Robott [%s] :: PUSH-RIGHT\n", name); + moveFlag = 1; + setVel(osg::Vec3(-1.0,0.0,0.0)); +} + +void Robot::releaseRight() { + printf("Class Robott [%s] :: RELASE-RIGHT\n", name); + moveFlag = 0; + setVel(osg::Vec3(0,0.0,0.0)); +} + +void Robot::pushUp() { + printf("Class Robott [%s] :: PUSH-UP\n", name); +} + +void Robot::releaseUp() { + printf("Class Robott [%s] :: RELEASE-UP\n", name); +} + +void Robot::pushDown() { + printf("Class Robott [%s] :: PUSH-DOWN\n", name); +} + +void Robot::releaseDown() { + printf("Class Robott [%s] :: RELEASE-DOWN\n", name); +} + + + +void Robot::pushA() { + printf("Class Robott [%s] :: PUSH-A\n", name); + moveFlag = 1; + setVel(osg::Vec3(1.0,0.0,0.0)); +} + +void Robot::releaseA() { + printf("Class Robott [%s] :: RELEASE-A\n", name); + moveFlag = 0; + setVel(osg::Vec3(0,0.0,0.0)); +} + +void Robot::pushB() { + printf("Class Robott [%s] :: PUSH-B\n", name); + turn(); +} + +void Robot::releaseB() { + printf("Class Robott [%s] :: RELASE-B\n", name); + moveFlag = 0; + setVel(osg::Vec3(0,0.0,0.0)); +} + +void Robot::pushC() { + printf("Class Robott [%s] :: PUSH-C\n", name); +} + +void Robot::releaseC() { + printf("Class Robott [%s] :: RELEASE-C\n", name); +} + +void Robot::pushD() { + printf("Class Robott [%s] :: PUSH-D\n", name); +} + +void Robot::releaseD() { + printf("Class Robott [%s] :: RELEASE-D\n", name); +} + +void Robot::walk() { + printf("walk"); + moveFlag = 1; + setVel(osg::Vec3(-5.0,0.0,0.0)); +} + +void Robot::turn() { + angularVelocity = osg::Vec3(angularVelocity.x(), angularVelocity.y(), 0.1); +} + +void Robot::stop() { + velocity = osg::Vec3(0,0,0); + angularVelocity = osg::Vec3(0,0,0); +} + + +void Robot::reload() { + moveCount += (float)moveFlag * 0.5; + float sinVal = sin(moveCount); + float cosVal = cos(moveCount); + + if (moveFlag != 0) setPos(osg::Vec3(position.x(), position.y(), position.z()+cos(moveCount)*0.01)); + + bodyForm->setAttitude(osg::Quat(osg::DegreesToRadians(sinVal*10.0), osg::Vec3(0,0,1))); + leftArmForm->setAttitude(osg::Quat(osg::DegreesToRadians(sinVal*30.0+10.0), osg::Vec3(1,0,0))); + rightArmForm->setAttitude(osg::Quat(osg::DegreesToRadians(-sinVal*30.0+10.0), osg::Vec3(1,0,0))); + leftLegForm->setAttitude(osg::Quat(osg::DegreesToRadians(-sinVal*45.0), osg::Vec3(1,0,0))); + rightLegForm->setAttitude(osg::Quat(osg::DegreesToRadians(sinVal*45.0), osg::Vec3(1,0,0))); + + //位置の再計算は親クラスのreloadと一緒なのでまかせたい..けどなぜかできない + // Character::reload(); (MovableObject::reload()) + osg::Matrixd roteMatrix; + osg::Matrixd dirMatrix; + osg::Matrixd accMatrix; + + direction += angularVelocity; + accMatrix.makeTranslate(acceleration); + roteMatrix.makeRotate( + osg::Quat( + direction.x(), osg::Vec3(1,0,0), + direction.y(), osg::Vec3(0,1,0), + direction.z(), osg::Vec3(0,0,1) + ) + ); + + velocity += (accMatrix*roteMatrix).getTrans(); + position += velocity; + + accMatrix.makeTranslate(acceleration); + roteMatrix.makeRotate( + osg::Quat( + defaultDirection.x()+direction.x(), osg::Vec3(1,0,0), + defaultDirection.y()+direction.y(), osg::Vec3(0,1,0), + defaultDirection.z()+direction.z(), osg::Vec3(0,0,1) + ) + ); + + dirMatrix.makeTranslate(position); + accMatrix.makeScale(scale); + mform->setMatrix(accMatrix*roteMatrix*dirMatrix); +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/Robot.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Robot.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,57 @@ +/* + * Robot.h + * Martial + * + * Created by ryoma on 10/01/23. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _ROBOT_H_ +#define _ROBOT_H_ + +#include "Humanoid.h" + +class Robot : public Humanoid { + protected: + void (Robot::*funcs[14])(); + void (Robot::*stack[14])(); + void (Robot::*frameFunc)(); + void (Robot::*unWaitFunc)(); + virtual void walk(); + virtual void turn(); + virtual void jump(); + void punch(); + virtual void run(); + virtual void squat(); + virtual void down(); + virtual void wait(); + virtual void freeze(); + virtual void stop(); + virtual void update(); + virtual void stackPush(); + virtual void stackPop(); + virtual void nop() {}; //none operation + public: + Robot(char* _name = "Robot"); + virtual void frame(); + virtual void releaseHat(); + virtual void pushRight(); + virtual void pushLeft(); + virtual void pushUp(); + virtual void pushDown(); + virtual void pushRightUp(); + virtual void pushRightDown(); + virtual void pushLeftUp(); + virtual void pushLeftDown(); + virtual void pushA(); + virtual void releaseA(); + virtual void pushB(); + virtual void releaseB(); + virtual void pushC(); + virtual void releaseC(); + virtual void pushD(); + virtual void releaseD(); +}; + +#endif \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/SDLMain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SDLMain.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,16 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#ifndef _SDLMain_h_ +#define _SDLMain_h_ + +#import + +@interface SDLMain : NSObject +@end + +#endif /* _SDLMain_h_ */ diff -r 143f7b9f867d -r 5727d511a13a src/SDLMain.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SDLMain.m Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,383 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#include +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include + +/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, + but the method still is there and works. To avoid warnings, we declare + it ourselves here. */ +@interface NSApplication(SDL_Missing_Methods) +- (void)setAppleMenu:(NSMenu *)menu; +@end + +/* Use this flag to determine whether we use SDLMain.nib or not */ +#define SDL_USE_NIB_FILE 0 + +/* Use this flag to determine whether we use CPS (docking) or not */ +#define SDL_USE_CPS 1 +#ifdef SDL_USE_CPS +/* Portions of CPS.h */ +typedef struct CPSProcessSerNum +{ + UInt32 lo; + UInt32 hi; +} CPSProcessSerNum; + +extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); +extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); + +#endif /* SDL_USE_CPS */ + +static int gArgc; +static char **gArgv; +static BOOL gFinderLaunch; +static BOOL gCalledAppMainline = FALSE; + +static NSString *getApplicationName(void) +{ + const NSDictionary *dict; + NSString *appName = 0; + + /* Determine the application name */ + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + if (dict) + appName = [dict objectForKey: @"CFBundleName"]; + + if (![appName length]) + appName = [[NSProcessInfo processInfo] processName]; + + return appName; +} + +#if SDL_USE_NIB_FILE +/* A helper category for NSString */ +@interface NSString (ReplaceSubString) +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; +@end +#endif + +@interface SDLApplication : NSApplication +@end + +@implementation SDLApplication +/* Invoked from the Quit menu item */ +- (void)terminate:(id)sender +{ + /* Post a SDL_QUIT event */ + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); +} +@end + +/* The main class of the application, the application's delegate */ +@implementation SDLMain + +/* Set the working directory to the .app's parent directory */ +- (void) setupWorkingDirectory:(BOOL)shouldChdir +{ + if (shouldChdir) + { + char parentdir[MAXPATHLEN]; + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } +} + +#if SDL_USE_NIB_FILE + +/* Fix menu to contain the real app name instead of "SDL App" */ +- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName +{ + NSRange aRange; + NSEnumerator *enumerator; + NSMenuItem *menuItem; + + aRange = [[aMenu title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; + + enumerator = [[aMenu itemArray] objectEnumerator]; + while ((menuItem = [enumerator nextObject])) + { + aRange = [[menuItem title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; + if ([menuItem hasSubmenu]) + [self fixMenu:[menuItem submenu] withAppName:appName]; + } + [ aMenu sizeToFit ]; +} + +#else + +static void setApplicationMenu(void) +{ + /* warning: this code is very odd */ + NSMenu *appleMenu; + NSMenuItem *menuItem; + NSString *title; + NSString *appName; + + appName = getApplicationName(); + appleMenu = [[NSMenu alloc] initWithTitle:@""]; + + /* Add menu items */ + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Hide " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + + + /* Put menu into the menubar */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + [[NSApp mainMenu] addItem:menuItem]; + + /* Tell the application object that this is now the application menu */ + [NSApp setAppleMenu:appleMenu]; + + /* Finally give up our references to the objects */ + [appleMenu release]; + [menuItem release]; +} + +/* Create a window menu */ +static void setupWindowMenu(void) +{ + NSMenu *windowMenu; + NSMenuItem *windowMenuItem; + NSMenuItem *menuItem; + + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + + /* "Minimize" item */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; + [windowMenu addItem:menuItem]; + [menuItem release]; + + /* Put menu into the menubar */ + windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; + [windowMenuItem setSubmenu:windowMenu]; + [[NSApp mainMenu] addItem:windowMenuItem]; + + /* Tell the application object that this is now the window menu */ + [NSApp setWindowsMenu:windowMenu]; + + /* Finally give up our references to the objects */ + [windowMenu release]; + [windowMenuItem release]; +} + +/* Replacement for NSApplicationMain */ +static void CustomApplicationMain (int argc, char **argv) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SDLMain *sdlMain; + + /* Ensure the application object is initialised */ + [SDLApplication sharedApplication]; + +#ifdef SDL_USE_CPS + { + CPSProcessSerNum PSN; + /* Tell the dock about us */ + if (!CPSGetCurrentProcess(&PSN)) + if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) + if (!CPSSetFrontProcess(&PSN)) + [SDLApplication sharedApplication]; + } +#endif /* SDL_USE_CPS */ + + /* Set up the menubar */ + [NSApp setMainMenu:[[NSMenu alloc] init]]; + setApplicationMenu(); + setupWindowMenu(); + + /* Create SDLMain and make it the app delegate */ + sdlMain = [[SDLMain alloc] init]; + [NSApp setDelegate:sdlMain]; + + /* Start the main event loop */ + [NSApp run]; + + [sdlMain release]; + [pool release]; +} + +#endif + + +/* + * Catch document open requests...this lets us notice files when the app + * was launched by double-clicking a document, or when a document was + * dragged/dropped on the app's icon. You need to have a + * CFBundleDocumentsType section in your Info.plist to get this message, + * apparently. + * + * Files are added to gArgv, so to the app, they'll look like command line + * arguments. Previously, apps launched from the finder had nothing but + * an argv[0]. + * + * This message may be received multiple times to open several docs on launch. + * + * This message is ignored once the app's mainline has been called. + */ +- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +{ + const char *temparg; + size_t arglen; + char *arg; + char **newargv; + + if (!gFinderLaunch) /* MacOS is passing command line args. */ + return FALSE; + + if (gCalledAppMainline) /* app has started, ignore this document. */ + return FALSE; + + temparg = [filename UTF8String]; + arglen = SDL_strlen(temparg) + 1; + arg = (char *) SDL_malloc(arglen); + if (arg == NULL) + return FALSE; + + newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); + if (newargv == NULL) + { + SDL_free(arg); + return FALSE; + } + gArgv = newargv; + + SDL_strlcpy(arg, temparg, arglen); + gArgv[gArgc++] = arg; + gArgv[gArgc] = NULL; + return TRUE; +} + + +/* Called when the internal event loop has just started running */ +- (void) applicationDidFinishLaunching: (NSNotification *) note +{ + int status; + + /* Set the working directory to the .app's parent directory */ + [self setupWorkingDirectory:gFinderLaunch]; + +#if SDL_USE_NIB_FILE + /* Set the main menu to contain the real app name instead of "SDL App" */ + [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; +#endif + + /* Hand off to main application code */ + gCalledAppMainline = TRUE; + status = SDL_main (gArgc, gArgv); + + /* We're done, thank you for playing */ + exit(status); +} +@end + + +@implementation NSString (ReplaceSubString) + +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString +{ + unsigned int bufferSize; + unsigned int selfLen = [self length]; + unsigned int aStringLen = [aString length]; + unichar *buffer; + NSRange localRange; + NSString *result; + + bufferSize = selfLen + aStringLen - aRange.length; + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + + /* Get first part into buffer */ + localRange.location = 0; + localRange.length = aRange.location; + [self getCharacters:buffer range:localRange]; + + /* Get middle part into buffer */ + localRange.location = 0; + localRange.length = aStringLen; + [aString getCharacters:(buffer+aRange.location) range:localRange]; + + /* Get last part into buffer */ + localRange.location = aRange.location + aRange.length; + localRange.length = selfLen - localRange.location; + [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; + + /* Build output string */ + result = [NSString stringWithCharacters:buffer length:bufferSize]; + + NSDeallocateMemoryPages(buffer, bufferSize); + + return result; +} + +@end + + + +#ifdef main +# undef main +#endif + + +/* Main entry point to executable - should *not* be SDL_main! */ +int main (int argc, char **argv) +{ + /* Copy the arguments into a global variable */ + /* This is passed if we are launched by double-clicking */ + if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + gArgv = (char **) SDL_malloc(sizeof (char *) * 2); + gArgv[0] = argv[0]; + gArgv[1] = NULL; + gArgc = 1; + gFinderLaunch = YES; + } else { + int i; + gArgc = argc; + gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); + for (i = 0; i <= argc; i++) + gArgv[i] = argv[i]; + gFinderLaunch = NO; + } + +#if SDL_USE_NIB_FILE + [SDLApplication poseAsClass:[NSApplication class]]; + NSApplicationMain (argc, argv); +#else + CustomApplicationMain (argc, argv); +#endif + return 0; +} + diff -r 143f7b9f867d -r 5727d511a13a src/SearchGeodeVisitor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SearchGeodeVisitor.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,29 @@ +/* + * SearchGeodeVisitor.cpp + * Martial + * + * Created by ryoma on 10/01/31. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "SearchGeodeVisitor.h" + +void SearchGeodeVisitor::apply(osg::Geode& Geode) { + //ここでつまづいた。 char* と std::string の比較はfalse + if (Geode.getName() == targetGeodeName) { + std::cout << "success geode!!\n"; + targetGeode = &Geode; + } else { + std::cout << "false " << Geode.getName() << "\n"; + traverse(Geode); + } +} + +void SearchGeodeVisitor::setSearchGeodeName(const std::string &_targetGeodeName) { + targetGeodeName = _targetGeodeName; +} + +osg::Geode* SearchGeodeVisitor::getGeode() { + return targetGeode; +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/SearchGeodeVisitor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SearchGeodeVisitor.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,27 @@ +/* + * SearchGeodeVisitor.h + * Martial + * + * Created by ryoma on 10/01/31. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _SEARCH_GEODE_VISITORS_ +#define _SEARCH_GEODE_VISITORS_ + +class SearchGeodeVisitor : public osg::NodeVisitor { + protected: + std::string targetGeodeName; + osg::Geode* targetGeode; + public: + SearchGeodeVisitor(const std::string &targetGeodeName = "UNKNOWN") : + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), + targetGeodeName(targetGeodeName), targetGeode(NULL) {}; + + void apply(osg::Geode& geode); + void setSearchGeodeName(const std::string &_targetGeodeName); + osg::Geode* getGeode(); +}; + +#endif diff -r 143f7b9f867d -r 5727d511a13a src/SearchMatrixTransformVisitor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SearchMatrixTransformVisitor.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,20 @@ +/* + * FinderNodeVisitor.cpp + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "SearchMatrixTransformVisitor.h" + +void SearchMatrixTransformVisitor::apply(osg::MatrixTransform& matrixTransform) { + //Hashで保持 + matrixMap[matrixTransform.getName()] = &matrixTransform; + traverse(matrixTransform); +} + +osg::MatrixTransform* SearchMatrixTransformVisitor::getMatrixTransform(const std::string &name) { + return matrixMap[name]; +} \ No newline at end of file diff -r 143f7b9f867d -r 5727d511a13a src/SearchMatrixTransformVisitor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SearchMatrixTransformVisitor.h Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,24 @@ +/* + * FinderNodeVisitor.h + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#ifndef _SEARCH_MATRIX_VISITORS_ +#define _SEARCH_MATRIX_VISITORS_ + +class SearchMatrixTransformVisitor : public osg::NodeVisitor { + protected: + std::map matrixMap; + std::string targetMatrixTransformName; + public: + SearchMatrixTransformVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}; + + void apply(osg::MatrixTransform& matrix); + osg::MatrixTransform* getMatrixTransform(const std::string& name); +}; + +#endif diff -r 143f7b9f867d -r 5727d511a13a src/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,7 @@ +#include "GameManager.h" + +int main(int /*argc*/, char** /*argv*/) { + GameManager* martial = new GameManager(); + martial->gameStart(); + return 0; +}