void Ski::create(b2World * b2dworld, float x, float y, float w, float h) { b2Vec2 center = screenPtToWorldPt(ofVec2f(x,y)); skiWidth = w; skiHeight = h; start = false; takeoff = false; blow = false; wind = 0; // Define the body and make it from the shape b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(center.x, center.y); b2Body* body = b2dworld->CreateBody(&bd); // Define a polygon (this is what we use for a rectangle) b2PolygonShape ps; ps.SetAsBox(b2dNum(w/2), b2dNum(h/2)); // Define a fixture b2FixtureDef fd; fd.shape = &ps; // Parameters that affect physics fd.density = 20; fd.friction = 0.001; fd.restitution = 0; // attach fixture to body body->CreateFixture(&fd); // Give it some initial random velocity //body.setLinearVelocity(new Vec2(100,0)); body->SetAngularVelocity(0); bodies.push_back(body); b2Vec2 frontPos = center; frontPos.x += b2dNum(skiWidth/2); createWheel(b2dworld, frontPos, skiHeight/2); b2Vec2 backPos = center; backPos.x -= b2dNum(skiWidth/2); createWheel(b2dworld, backPos, skiHeight/2); createJoint(b2dworld, bodies.at(0), bodies.at(1)); createJoint(b2dworld, bodies.at(0), bodies.at(2)); }
ClientUnit::ClientUnit( Rendering* const rendering, Wrapper* const wrapper, GameStaticData* const gameStaticData, GameDynData* const gameDynData, ClientSquad* const squad, const IntCode id, const Coord& coord, Input* const input ) : mRendering(rendering), mWrapper(wrapper), mGameStaticData(gameStaticData), mGameDynData(gameDynData), mSquad(squad), mId(id), mCoord(coord), mInput(input), mMode(MODE_PLAYER), mCtrl(MODE_PLAYER), mSpeed(100.0f, 100.0f, Math::PI/360.0f, Math::PI/360.0f), mScale(0, 0, 0, 0), mDiff(0, 0.55, 0.46, 0.45), mTarget(0), mAgressor(0), mTargetTime(TIME_TO_PEACE), mAgressorTime(TIME_TO_PEACE), mFireTime(TIME_TO_CHANGE), mMoveTime(TIME_TO_CHANGE), mInterfaceInput( squad ? new ClientInputGame(rendering, input) : 0 ), mSaladin( squad ? new Saladin(rendering, wrapper) : 0 ), mSquadData( squad ? squad->mSquadData : 0 ), mLeader( squad ? squad->mLeader : 0 ), maUnit( squad ? squad->maUnit : 0 ), maPlayerDynData( squad ? gameDynData->aPlayerDynData : 0 ), Actor(wrapper->scene) { if (squad) { for (IntVal index = 0 ; index < 5 ; ++index) { maState[index] = 0; } for (IntVal index = 0 ; index < MAX_AMMO ; ++index) { maBullet[index] = 0; } mSpeed.x *= (0.60 + (bool)mLeader*0.60); NxOgre::RigidBodyDescription description; description.mName = "Unit"; description.mMass = 24500; description.mWakeUpCounter = 1E12; description.mMassLocalPose = Vec3(0.00f, -2.18f, 0.0f); mName = description.mName; mNameHash = NxOgre::Strings::hash(mName); NxOgre::ShapeDescriptions vShapes; vShapes.push_back(createBox ( 0.00f, 0.00f, 0.00f, 4.40f, 2.50f, 7.00f)); vShapes.push_back(createBox ( 0.10f, 0.70f, 0.70f, 4.40f, 1.50f, 4.40f)); vShapes.push_back(createBox (-0.10f, 0.40f, 4.10f, 0.50f, 0.50f, 4.00f)); vShapes.push_back(createWheel(-2.30f, -2.18f, 3.54f)); vShapes.push_back(createWheel(-2.29f, -2.18f, 0.50f)); vShapes.push_back(createWheel(-2.31f, -2.18f, -3.00f)); vShapes.push_back(createWheel( 2.30f, -2.18f, 3.54f)); vShapes.push_back(createWheel( 2.29f, -2.18f, 0.50f)); vShapes.push_back(createWheel( 2.31f, -2.18f, -3.00f)); this ->createDynamic(coord, description, vShapes); mSaladin ->init(this); for (IntVal index = 0 ; index < vShapes.size() ; ++index) { delete vShapes[index]; } } }
int main( int argc, char** argv ) { btDynamicsWorld* bw = initPhysics(); osg::Group* root = new osg::Group; osg::ref_ptr< osgbInteraction::SaveRestoreHandler > srh = new osgbInteraction::SaveRestoreHandler; osg::Matrix m; m = osg::Matrix::rotate( .4, 0., 0., 1. ) * osg::Matrix::translate( 16., 0., 10. ); btRigidBody *rb = createObject(root, m, srh.get()); bw->addRigidBody(rb); m = osg::Matrix::rotate( osg::PI_2, 0, 1, 0 ) * osg::Matrix::translate( 0., 0., 10. ); bw->addRigidBody(createWheel(root, m, srh.get())); m = osg::Matrix::rotate( 0, 0., 0., 1. ) * osg::Matrix::translate( -20., 0., 0. ); bw->addRigidBody(createCow(root, m, srh.get())); root->addChild( osgbDynamics::generateGroundPlane( osg::Vec4( 0.f, 0.f, 1.f, 0.f ), bw ) ); osgViewer::Viewer viewer; viewer.setUpViewInWindow( 30, 30, 768, 480, 1 ); viewer.setSceneData( root ); osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator; viewer.setCameraManipulator( tb ); viewer.realize(); srh->capture(); viewer.addEventHandler(new myEventHandler(rb)); viewer.addEventHandler( srh.get() ); viewer.addEventHandler( new osgbInteraction::DragHandler(bw, viewer.getCamera() ) ); double prevSimTime = 0.; while( !viewer.done() ) { const double currSimTime = viewer.getFrameStamp()->getSimulationTime(); bw->stepSimulation( currSimTime - prevSimTime ); prevSimTime = currSimTime; viewer.frame(); } return( 0 ); }
void QgsColorWheel::paintEvent( QPaintEvent *event ) { Q_UNUSED( event ); QPainter painter( this ); //draw a frame QStyleOptionFrameV3 option = QStyleOptionFrameV3(); option.initFrom( this ); option.state = this->hasFocus() ? QStyle::State_Active : QStyle::State_None; style()->drawPrimitive( QStyle::PE_Frame, &option, &painter ); if ( !mWidgetImage || !mWheelImage || !mTriangleImage ) { createImages( size() ); } //draw everything in an image mWidgetImage->fill( Qt::transparent ); QPainter imagePainter( mWidgetImage ); imagePainter.setRenderHint( QPainter::Antialiasing ); if ( mWheelDirty ) { //need to redraw the wheel image createWheel(); } //draw wheel centered on widget QPointF center = QPointF( width() / 2.0, height() / 2.0 ); imagePainter.drawImage( QPointF( center.x() - ( mWheelImage->width() / 2.0 ), center.y() - ( mWheelImage->height() / 2.0 ) ), *mWheelImage ); //draw hue marker int h = hue(); double length = mWheelImage->width() / 2.0; QLineF hueMarkerLine = QLineF( center.x(), center.y(), center.x() + length, center.y() ); hueMarkerLine.setAngle( h ); imagePainter.save(); //use sourceIn mode for nicer antialiasing imagePainter.setCompositionMode( QPainter::CompositionMode_SourceIn ); QPen pen; pen.setWidth( 2 ); //adapt pen color for hue pen.setColor( h > 20 && h < 200 ? Qt::black : Qt::white ); imagePainter.setPen( pen ); imagePainter.drawLine( hueMarkerLine ); imagePainter.restore(); //draw triangle if ( mTriangleDirty ) { createTriangle(); } imagePainter.drawImage( QPointF( center.x() - ( mWheelImage->width() / 2.0 ), center.y() - ( mWheelImage->height() / 2.0 ) ), *mTriangleImage ); //draw current color marker double triangleRadius = length - mWheelThickness - 1; //adapted from equations at https://github.com/timjb/colortriangle/blob/master/colortriangle.js by Tim Baumann double lightness = mCurrentColor.lightnessF(); double hueRadians = ( h * M_PI / 180.0 ); double hx = cos( hueRadians ) * triangleRadius; double hy = -sin( hueRadians ) * triangleRadius; double sx = -cos( -hueRadians + ( M_PI / 3.0 ) ) * triangleRadius; double sy = -sin( -hueRadians + ( M_PI / 3.0 ) ) * triangleRadius; double vx = -cos( hueRadians + ( M_PI / 3.0 ) ) * triangleRadius; double vy = sin( hueRadians + ( M_PI / 3.0 ) ) * triangleRadius; double mx = ( sx + vx ) / 2.0; double my = ( sy + vy ) / 2.0; double a = ( 1 - 2.0 * fabs( lightness - 0.5 ) ) * mCurrentColor.hslSaturationF(); double x = sx + ( vx - sx ) * lightness + ( hx - mx ) * a; double y = sy + ( vy - sy ) * lightness + ( hy - my ) * a; //adapt pen color for lightness pen.setColor( lightness > 0.7 ? Qt::black : Qt::white ); imagePainter.setPen( pen ); imagePainter.setBrush( Qt::NoBrush ); imagePainter.drawEllipse( QPointF( x + center.x(), y + center.y() ), 4.0, 4.0 ); imagePainter.end(); //draw image onto widget painter.drawImage( QPoint( 0, 0 ), *mWidgetImage ); painter.end(); }