void MiniMap::Render() { mMiniMap.Render(); SVector2 boxPosition(1375, 10); int numberOfNPCS = mMap.GetNumberOfNPCS(); int numberOfPlayers = mOtherPlayers.GetNumberOfPlayers(); SCircle mapCircle(1482, 114, 75); //Graphics_DebugCircle(mapCircle, 0XFF0000); SVector2 offset(boxPosition.x + mMiniMap.GetWidth() * 0.5f, boxPosition.y + mMiniMap.GetHeight() * 0.5f); for(int a = 0; a < numberOfNPCS; ++a) { SVector2 position = ((mMap.GetNPC(a)->GetPosition() - mCharacter.GetPosition()) * 0.05f + offset); SCircle tempCircle(position, 1); // If within our map radius if(Intersect(tempCircle, mapCircle)) { mMiniMapEnemy.SetPosition(position); mMiniMapEnemy.Render(); } } // If within our map radius mMiniMapPlayer.SetPosition(offset); mMiniMapPlayer.Render(); for(int a = 0; a < numberOfPlayers; ++a) { SVector2 position = ((mOtherPlayers.GetPlayer(a)->GetPosition() - mCharacter.GetPosition()) * 0.05f + offset); SCircle tempCircle(position, 1); // If within our map radius if(Intersect(tempCircle, mapCircle)) { mMiniMapChar.SetPosition(position); mMiniMapChar.Render(); } } }
void CStage9::Initialize() { m_isAdd2DCollision = false; m_isAdd3DCollision = false; CStage::Initialize(); D3DXMatrixPerspectiveFovLH(&m_projMatrix, D3DX_PI / 4, 960.0f / 580.0f, 1.0f, 100.0f); m_Player.Initialize(); m_Player.SetPointa(&m_pointa); m_Player.SetPosition(playerpos_stage9); m_Ground9.Initialize(); m_camera.Initialize(); m_camera.SetEyePt(D3DXVECTOR3(0.0f, 1.0f, -3.0f)); m_pointa.Initialize(); m_GameCursor.Initialize();//ゲームカーソル000 m_GCursorWind.Initialize();//ゲームカーソル風 m_GameCursor3D.Initialize();//ゲームカーソル3D g_Shadow.Create(512, 512); g_Shadow.Entry(&m_Player); m_goal.Initialize(D3DXVECTOR3(292.0f, 40.0f, 0.0f)); m_Back1.Initialize(); m_Back1.SetPointa(&m_Player); m_Ray.Initialize();//レイカーソル初期化 m_Ray.SetPointa(&m_pointa); D3DXVECTOR3 boxPosition(m_position.x, m_position.y, m_position.z); //g_Shadow.Create(512, 512); //g_Shadow.Entry(&m_Player); this->CreateCollision3D(); this->CreateCollision2D(); this->Add3DRigidBody(ARRAYSIZE(collision9InfoTable3D)); m_gimmick.InitGimmick(gimmick3dobj9, ARRAYSIZE(gimmick3dobj9), gimmick2dobj9, ARRAYSIZE(gimmick2dobj9)); GoalCount = 0; }
void UIBox::resize(int width, int height) { //Renderable *renderable; float ratio = (width / (float)height); int bWidth = (int)(_uiBorder * width), bHeight = (int)(_uiBorder * height * ratio); UIElement::resize(width, height); clearRenderables(); // Add the center box Vec2f boxPosition(0, 0); Vec2f boxDimensions((float)_dimensions.x, (float)_dimensions.y); if(_uiBorder > 0) { // Subtract space for the border if there is a border that protrudes inwards boxPosition += Vec2f((float)bWidth, (float)bHeight); boxDimensions -= Vec2f(bWidth * 2.0f, bHeight * 2.0f); } addRenderable(Renderable::OrthoBox(boxPosition, boxDimensions, false, false, _material)); if(_uiBorder != 0) { int bXOffset = 0, bYOffset = 0; if(_uiBorder < 0) { bXOffset = bWidth; bYOffset = bHeight; } // Top border addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, (float)_dimensions.h), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)-bHeight), false, false, _borderMaterial)); // Bottom border addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)bHeight), false, false, _borderMaterial)); // Left border addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial)); // Right border addRenderable(Renderable::OrthoBox(Vec2f((float)_dimensions.w, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial)); } }
Box::Box(float width, float height) { conv = 3.141592 / 180.0; gravity = 9.8; displayx = width; displayy = height; rectW = 50.0; rectL = 50.0; sf::Vector2f rectSize( rectW, rectL ); sf::Color rectColor( sf::Color::Green ); rect.setSize( rectSize ); rect.setOrigin( rectW/2.0, rectL/2.0 ); rect.setFillColor( rectColor ); // Some Initial Conditions sf::Vector2f boxPosition(0,0); speed = 1.f; rect.setPosition( displayx/2.0, 3*rectL ); collision = false; bounceNumber = 0; }
FrictionDemo::FrictionDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { // // Setup the camera // { hkVector4 from(0.0f, 7.0f, 20.0f); hkVector4 to (0.0f, 3.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } // // Create the world // { hkpWorldCinfo info; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); info.setBroadPhaseWorldSize( 100.0f ); info.m_enableDeactivation = false; m_world = new hkpWorld( info ); m_world->lock(); setupGraphics(); } // // Register the agents // { hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); } // In this demo we have one fixed object and 10 dynamic objects, all of which are hkBoxShapes. But before we create // them we will outline the parameters used in this demo: // // Illustrative parameters for the demo // const int numObjects = 10; // the number of moving boxes const hkReal objectStep = 1.2f; // a notional 'width' of a moving box pair const hkReal initialFriction = 0.0f; const hkReal frictionRange = 1.0f; // friction ranges from initialFriction to frictionRange const hkVector4 axis(0.0f,0.0f,1.0f); const hkReal angle = -HK_REAL_PI / 10.0f; const hkQuaternion boxOrientation(axis, angle); // Orientation const hkReal fixedBoxHalfHeight = 1.0f; const hkReal movingBoxHalfHeight = 0.1f; const hkReal movingBoxInitialVerticalDisplacement = 0.25f; // // Derived parameters for the demo // const hkReal frictionStep = frictionRange / numObjects; // friction ranges in steps of frictionStep const hkReal positionAlongZ = - (objectStep * numObjects) / 2.0f; const hkVector4 fixedBoxSize((objectStep * numObjects) / 2.0f + 2.0f, fixedBoxHalfHeight, (objectStep * numObjects) / 2.0f + 2.0f); const hkVector4 boxSize(0.5f, movingBoxHalfHeight, 0.5f); // Since we've rotated everything, the height above the fixed box is proportional to the 1/cosine of the angle we rotated by. const hkReal movingBoxCentreHeight = (fixedBoxHalfHeight + movingBoxHalfHeight + movingBoxInitialVerticalDisplacement) / hkMath::cos(angle); // As you can see these parameters are used to calculate the position, orientation and frictional values // that are assigned to each of the boxes. By scaling the frictional values between 0.0 and 0.9 you // can see a range of responses from the different boxes as they drop on the surface of the large sloped box. // The creation of the various rigid bodies in the demo is fairly straight forward and follows the usual scheme // of filling out the various members of the hkpRigidBodyCinfo structure, asking Havok to compute // the 'mass properties' for the body and finally adding it to the world. The only slight difference this time // is that each of the dynamic boxes receives a different value for 'm_friction': // // Box shapes // hkpBoxShape* fixedBoxShape = new hkpBoxShape( fixedBoxSize , 0 ); hkpBoxShape* boxShape = new hkpBoxShape( boxSize , 0 ); // // Physical parameters for the demo // hkReal fixedBoxFriction = 0.25f; hkReal boxMass = 1.0f; // // Create the fixed box // { // Position of the box hkVector4 boxPosition(0.0f, 0.0f, 0.0f); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; info.m_motionType = hkpMotion::MOTION_FIXED; info.m_friction = fixedBoxFriction; info.m_shape = fixedBoxShape; info.m_position = boxPosition; info.m_rotation = boxOrientation; // Create fixed box hkpRigidBody* box = new hkpRigidBody(info); m_world->addEntity(box); box->removeReference(); } // // Create the moving boxes // for(int i = 0; i < numObjects; i++) { // Compute the box inertia tensor hkpMassProperties massProperties; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxSize, boxMass, massProperties); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; // Each box has a different friction ranging from 0.0 to 0.9 info.m_friction = initialFriction + frictionStep * i; info.m_shape = boxShape; info.m_mass = boxMass; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; // Position of the box float zpos = positionAlongZ + objectStep * i; info.m_position = hkVector4(0.0f, movingBoxCentreHeight, zpos); info.m_rotation = boxOrientation; // Create a box hkpRigidBody* box = new hkpRigidBody(info); m_world->addEntity(box); box->removeReference(); } /// Once we've created the bodies and added them to the world we simply let the simulation proceed. // // Remove references from shapes // fixedBoxShape->removeReference(); boxShape->removeReference(); m_world->unlock(); }
void PauseState::init() { sf::Vector2f window( mGame->getTarget()->getSize().x, mGame->getTarget()->getSize().y ); sf::Vector2f boxSize( 500.0f, 230.f ); sf::Vector2f boxPosition( window.x / 2.f - boxSize.x / 2.f, window.y / 2.f - boxSize.y / 2.f ); TextButton* bg = new TextButton(); bg->setSize( boxSize ); bg->setPosition( boxPosition ); bg->setBackgroundColor( sf::Color::Black ); bg->setVisible( true ); mMenu.addItem( "1_BG", bg ); TextButton* resume = new TextButton(); resume->setFont( DEFAULT_FONT ); resume->setText( "Resume" ); resume->setTextColor( sf::Color::White ); resume->setHighlightTextColor( sf::Color::Green ); resume->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 20.f ) ); resume->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); resume->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); resume->setVisible( true ); resume->setClickFunction( []( Menu* menu, Game* game ) { game->popState(); } ); mMenu.addItem( "2_Resume", resume ); // TextButton* restart = new TextButton(); // restart->setFont( DEFAULT_FONT ); // restart->setText( "Restart" ); // restart->setTextColor( sf::Color::White ); // restart->setHighlightTextColor( sf::Color::Green ); // restart->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 90.f ) ); // restart->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); // restart->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); // restart->setVisible( true ); // std::string map = mMap; // restart->setClickFunction( [map]( Menu* menu, Game* game ) // { // std::cout << map << std::endl; // game->popState(); // game->popState(); // game->pushState( new PlayState( map ) ); // } ); // mMenu.addItem( "3_Restart", restart ); TextButton* menu = new TextButton(); menu->setFont( DEFAULT_FONT ); menu->setText( "Return to menu" ); menu->setTextColor( sf::Color::White ); menu->setHighlightTextColor( sf::Color::Green ); menu->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 90.f ) ); menu->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); menu->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); menu->setVisible( true ); menu->setClickFunction( []( Menu* menu, Game* game ) { game->popState(); game->popState(); } ); mMenu.addItem( "4_Menu", menu ); TextButton* quit = new TextButton(); quit->setFont( DEFAULT_FONT ); quit->setText( "Quit" ); quit->setTextColor( sf::Color::White ); quit->setHighlightTextColor( sf::Color::Green ); quit->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 160.f ) ); quit->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); quit->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); quit->setVisible( true ); quit->setClickFunction( []( Menu* menu, Game* game ) { game->quit(); } ); mMenu.addItem( "5_Quit", quit ); }
void DemoKeeper::RestitutionDemo( void ) { mWorld->markForWrite(); // Illustrative parameters for the demo unsigned int numObjects = 10; // the number of box/sphere pairs hkReal objectStep = 1.2f; // a notional 'width' of a box/sphere pair hkReal initialRestitution = 0.0f; hkReal restitutionRange = 1.0f; // sphere restitution ranges from initialRestitution to restitutionRange // Derived parameters for the demo hkReal restitutionStep = restitutionRange / numObjects; // restitution ranges in steps of restitutionStep hkReal positionAlongX = - (objectStep * numObjects) / 2.0f; // Geometric parameters for the demo hkVector4 boxSize(0.5f, 0.1f, 0.5f); hkReal sphereRadius = 0.5f; hkpBoxShape* boxShape = new hkpBoxShape( boxSize , 0 ); hkpSphereShape* sphereShape = new hkpSphereShape( sphereRadius ); // Physical parameters for the demo hkReal boxRestitution = 1.0f; hkReal sphereMass = 1.0f; // Create the objects for(unsigned int i = 0; i <= numObjects; i++) { { // Position of the box hkVector4 boxPosition(positionAlongX, 5.0f, 0.0f); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; info.m_motionType = hkpMotion::MOTION_FIXED; // // NOTE: The current implementation of restitution uses a very simple approximation, and // may not produce physically accurate results. A more accurate version will // implemented in later versions of the SDK. // info.m_restitution = boxRestitution; info.m_shape = boxShape; info.m_position = boxPosition; // Create fixed box hkpRigidBody* box = new hkpRigidBody(info); mWorld->addEntity(box); box->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale boxNode->scale(0.5f, 0.1f, 0.5f); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, box,mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, box); } { // Compute the sphere inertia tensor hkMassProperties massProperties; hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereRadius, sphereMass, massProperties); // Set up the construction info parameters for the sphere hkpRigidBodyCinfo info; // // NOTE: The current implementation of restitution uses a very simple approximation, and // may not produce physically accurate results. A more accurate version will // implemented in later versions of the SDK. // info.m_restitution = initialRestitution + restitutionStep * i; info.m_mass = sphereMass; info.m_shape = sphereShape; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA; info.m_position.set(positionAlongX, 12.0f, 0.0f); // Create movable sphere hkpRigidBody* sphere = new hkpRigidBody(info); mWorld->addEntity(sphere); sphere->removeReference(); //render it with Ogre Ogre::SceneNode* sphereNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale sphereNode->scale(0.5f, 0.5f, 0.5f); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defSphere.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.5538,0.3187,0.1275)); HkOgre::Renderable* rend = new HkOgre::Renderable(sphereNode, sphere,mWorld); sphereNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( sphereNode, sphere); } positionAlongX += objectStep; } // Clean up boxShape->removeReference(); sphereShape->removeReference(); mWorld->unmarkForWrite(); }
void DemoKeeper::FrictionDemo( void ) { mWorld->markForWrite(); // In this demo we have one fixed object and 10 dynamic objects, all of which are hkBoxShapes. But before we create // them we will outline the parameters used in this demo: // // Illustrative parameters for the demo // const int numObjects = 10; // the number of moving boxes const hkReal objectStep = 1.2f; // a notional 'width' of a moving box pair const hkReal initialFriction = 0.0f; const hkReal frictionRange = 1.0f; // friction ranges from initialFriction to frictionRange const hkVector4 axis(0.0f,0.0f,1.0f); const hkReal angle = -HK_REAL_PI / 10.0f; const hkQuaternion boxOrientation(axis, angle); // Orientation const hkReal fixedBoxHalfHeight = 1.0f; const hkReal movingBoxHalfHeight = 0.3f; const hkReal movingBoxInitialVerticalDisplacement = 0.25f; // // Derived parameters for the demo // const hkReal frictionStep = frictionRange / numObjects; // friction ranges in steps of frictionStep const hkReal positionAlongZ = - (objectStep * numObjects) / 2.0f; const hkVector4 fixedBoxSize((objectStep * numObjects) / 2.0f + 2.0f, fixedBoxHalfHeight, (objectStep * numObjects) / 2.0f + 2.0f); const hkVector4 boxSize(0.5f, movingBoxHalfHeight, 0.5f); // Since we've rotated everything, the height above the fixed box is proportional to the 1/cosine of the angle we rotated by. const hkReal movingBoxCentreHeight = (fixedBoxHalfHeight + movingBoxHalfHeight + movingBoxInitialVerticalDisplacement) / hkMath::cos(angle); // As you can see these parameters are used to calculate the position, orientation and frictional values // that are assigned to each of the boxes. By scaling the frictional values between 0.0 and 0.9 you // can see a range of responses from the different boxes as they drop on the surface of the large sloped box. // The creation of the various rigid bodies in the demo is fairly straight forward and follows the usual scheme // of filling out the various members of the hkpRigidBodyCinfo structure, asking Havok to compute // the 'mass properties' for the body and finally adding it to the world. The only slight difference this time // is that each of the dynamic boxes receives a different value for 'm_friction': // // Box shapes // hkpBoxShape* fixedBoxShape = new hkpBoxShape( fixedBoxSize , 0 ); hkpBoxShape* boxShape = new hkpBoxShape( boxSize , 0 ); // // Physical parameters for the demo // hkReal fixedBoxFriction = 0.25f; hkReal boxMass = 1.0f; // // Create the fixed box // { // Position of the box hkVector4 boxPosition(0.0f, 5.0f, 0.0f); hkpRigidBodyCinfo info; { info.m_motionType = hkpMotion::MOTION_FIXED; info.m_friction = fixedBoxFriction; info.m_shape = fixedBoxShape; info.m_position = boxPosition; info.m_rotation = boxOrientation; } hkpRigidBody* box = new hkpRigidBody(info); mWorld->addEntity(box); box->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(((objectStep * numObjects) / 2.0f + 2.0f)*2, fixedBoxHalfHeight*2,((objectStep * numObjects) / 2.0f + 2.0f)*2); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(boxOrientation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, box,mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, box); } // // Create the moving boxes // for(int i = 0; i < numObjects; i++) { // Compute the box inertia tensor hkMassProperties massProperties; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxSize, boxMass, massProperties); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; // Each box has a different friction ranging from 0.0 to 0.9 info.m_friction = initialFriction + frictionStep * i; info.m_shape = boxShape; info.m_mass = boxMass; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; // Position of the box hkReal zpos = positionAlongZ + objectStep * i; info.m_position = hkVector4(0.0f, movingBoxCentreHeight+6.5, zpos); info.m_rotation = boxOrientation; // Create a box hkpRigidBody* box = new hkpRigidBody(info); mWorld->addEntity(box); box->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale boxNode->scale(0.5f*2, movingBoxHalfHeight*2, 0.5f*2); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.1356,0.3242,0.5403)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, box,mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, box); } // // Remove references from shapes // fixedBoxShape->removeReference(); boxShape->removeReference(); mWorld->unmarkForWrite(); }
ActivationCallbacksDemo::ActivationCallbacksDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { // // Setup the camera // { hkVector4 from(0.0f, 7.0f, 30.0f); hkVector4 to (0.0f, 3.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } // // Create the world // { hkpWorldCinfo info; info.setBroadPhaseWorldSize( 100.0f ); m_world = new hkpWorld( info ); m_world->lock(); m_debugViewerNames.pushBack( hkpSimulationIslandViewer::getName() ); setupGraphics(); } // // Register the agents // { hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); } // // Create the fixed box // { // Position of the box hkVector4 boxPosition(0.0f, 0.0f, 0.0f); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; info.m_motionType = hkpMotion::MOTION_FIXED; info.m_friction = 1.0f; info.m_shape = new hkpBoxShape( hkVector4(60.0f, 0.2f, 60.0f), 0.05f ); info.m_position = boxPosition; // Create fixed box hkpRigidBody* box = new hkpRigidBody(info); m_world->addEntity(box); box->removeReference(); info.m_shape->removeReference(); } // // Create the moving boxes // for (int i = 0; i < 20; i++) { // Create some object hkpRigidBodyCinfo info; info.m_friction = 1.0f; info.m_shape = new hkpBoxShape( hkVector4(0.5f, 0.5f, 0.5f), 0.0f ); hkpInertiaTensorComputer::setShapeVolumeMassProperties( info.m_shape, 1.0f, info ); info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; // Position of the box info.m_position.setZero4(); info.m_position(0) = - hkReal(i) * 1.5f + 2.0f; //left info.m_position(1) = 1.0f; info.m_position(2) = hkMath::sin( hkReal(i) / 3.0f ) * 0.7f; if (i == 0) { info.m_motionType = hkpMotion::MOTION_KEYFRAMED; info.m_linearVelocity = hkVector4( -1.0f, 0.0f, 0.0f ); } // Create a box hkpRigidBody* box = new hkpRigidBody(info); info.m_shape->removeReference(); // Create a listener and attach it to the box // NOTE: The listener attaches itself to the body as an hkpEntityListener // and deletes itself automatically when the entity is deleted. ActivationCallbacksDemoEntityActivationListener* listener = new ActivationCallbacksDemoEntityActivationListener(); box->addEntityActivationListener(listener); box->addEntityListener(listener); // Insert the box into the world m_world->addEntity(box); box->removeReference(); } m_world->unlock(); }
void KBBGraphicsItemOnBox::mouseReleaseEvent (QGraphicsSceneMouseEvent* event) { // Let's Qt handle the drag en drop QGraphicsItem::mouseReleaseEvent(event); qreal dropX = event->scenePos().x(); qreal dropY = event->scenePos().y(); if ((dropX==m_dragX) && (dropY==m_dragY)) { setCursor(Qt::ArrowCursor); if ((position()!=NO_POSITION) && (position()<(m_columns*m_rows))) m_widget->mouseBoxClick(event->button(), position()); } else if (isMovable()) { setCursor(Qt::ArrowCursor); if ((boxPosition(dropX, dropY)==NO_POSITION) || (boxPosition(dropX, dropY)==boxPosition(m_dragX, m_dragY)) || (boxPosition(dropX, dropY)>=m_columns*m_rows)) // Cancel move setPos(m_dragXPos, m_dragYPos); else { if (m_itemType==KBBScalableGraphicWidget::markerNothing) setBoxPosition(m_widget->moveMarkerNothing(boxPosition(m_dragX, m_dragY), boxPosition(dropX, dropY))); else { int newPos = m_widget->positionAfterMovingBall(boxPosition(m_dragX, m_dragY), boxPosition(dropX, dropY)); // if we do move from outside the board. Because in this case and if the move is OK, we will destroy ourself to put a "real" new ball over the board... So we cannot do anything else more after calling m_widget->moveBall()... if ((m_boxPosition==NO_POSITION) || (m_boxPosition>=(m_columns*m_rows))) { if (newPos==m_boxPosition) setPos(m_dragXPos, m_dragYPos); else m_widget->moveBall(boxPosition(m_dragX, m_dragY), boxPosition(dropX, dropY)); } else setBoxPosition(m_widget->moveBall(boxPosition(m_dragX, m_dragY), boxPosition(dropX, dropY))); } } } }