当前位置: 首页>>代码示例>>C++>>正文


C++ cpv函数代码示例

本文整理汇总了C++中cpv函数的典型用法代码示例。如果您正苦于以下问题:C++ cpv函数的具体用法?C++ cpv怎么用?C++ cpv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cpv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

static cpSpace *
init(void)
{
	cpSpace *space = cpSpaceNew();
	cpSpaceSetIterations(space, 30);
	cpSpaceSetGravity(space, cpv(0, -100));
	cpSpaceSetSleepTimeThreshold(space, 0.5f);
	cpSpaceSetCollisionSlop(space, 0.5f);
	
	cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
	cpShape *shape;
	
	// Create segments around the edge of the screen.
	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
	cpShapeSetElasticity(shape, 1.0f);
	cpShapeSetFriction(shape, 1.0f);
	cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
	cpShapeSetElasticity(shape, 1.0f);
	cpShapeSetFriction(shape, 1.0f);
	cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	cpShapeSetElasticity(shape, 1.0f);
	cpShapeSetFriction(shape, 1.0f);
	cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
	
	// Add lots of boxes.
	for(int i=0; i<14; i++){
		for(int j=0; j<=i; j++){
			body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f)));
			cpBodySetPosition(body, cpv(j*32 - i*16, 300 - i*32));
			
			shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f, 0.5f));
			cpShapeSetElasticity(shape, 0.0f);
			cpShapeSetFriction(shape, 0.8f);
		}
	}
	
	// Add a ball to make things more interesting
	cpFloat radius = 15.0f;
	body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
	cpBodySetPosition(body, cpv(0, -240 + radius+5));

	shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
	cpShapeSetElasticity(shape, 0.0f);
	cpShapeSetFriction(shape, 0.9f);
	
	return space;
}
开发者ID:ConfusedReality,项目名称:pkg_game-engine_chipmunk,代码行数:51,代码来源:PyramidStack.c

示例2: cpSpaceNew

PhysicsWorld::PhysicsWorld()
{
    mySpace = cpSpaceNew();
    
    // Set default gravity
    cpVect gravity = cpv(0, -10);
    cpSpaceSetGravity(mySpace, gravity);
}
开发者ID:pkonneker,项目名称:Open2dAdventure,代码行数:8,代码来源:PhysicsWorld.cpp

示例3: cpBodyNewKinematic

void DynamicObjectStabilizator::fixatePoints()
{
//	vector<IDynamicObject *>::iterator begin = m_DynamicObjects.begin();
//	vector<IDynamicObject *>::iterator end = m_DynamicObjects.end();
//	vector<IDynamicObject *>::iterator iter = begin + 1;
//	for(  ; iter != end ; iter++ )
	size_t count = m_DynamicObjects.size();
	for( size_t object_i = 0 ; object_i < 2 ; object_i++ )
	{
		const IGeometryObject & geometryObjext = m_DynamicObjects[object_i]->getGeometryObject();
		if( geometryObjext.getType() != GEOMETRYOBJECT_POINT )
		{
//			assert( false );
			continue;
		}
		cpBody * kineticBody = cpBodyNewKinematic();
		cpSpaceAddBody( m_Space, kineticBody );
		m_KineticBodies.push_back( kineticBody );

		const GeometryPoint & geometryPoint = dynamic_cast<const GeometryPoint &>( geometryObjext );

		int x = geometryPoint.getX();
		int y = geometryPoint.getY();
		cpVect mousePoint = cpv( x, y );
		cpShape * shape = cpSpacePointQueryNearest( m_Space, mousePoint, 100.0, GRAB_FILTER, 0 );

		if( 0 == shape )
		{
			return;
		}

		cpVect new_mouse_position = cpv( x, y );
		cpBodySetPosition( kineticBody, new_mouse_position );

		cpBody * trackingBody = cpShapeGetBody( shape );


		cpConstraint * joint = cpPivotJointNew2( kineticBody, trackingBody, cpvzero, cpvzero );
		cpSpaceAddConstraint( m_Space, joint );

		m_Joints.push_back( joint );

		break; //one pointb
	}
}
开发者ID:virtual-creature,项目名称:vc_constructor,代码行数:45,代码来源:DynamicObjectStabilizator.cpp

示例4: cpv

void PhysicsShape::componentComplete()
{
    if(m_shapeType == PhysicsTypes::Box) {
        cpVect niz[] = {
            cpv(-(this->width()/2.0f), -(this->height()/2.0f)),
            cpv(-(this->width()/2.0f),  (this->height()/2.0f)),
            cpv( (this->width()/2.0f),  (this->height()/2.0f)),
            cpv( (this->width()/2.0f), -(this->height()/2.0f))
        };
        m_shape = cpPolyShapeNew(NULL, 4, niz, cpv(m_offsetX, -m_offsetY));
    }
    else if(m_shapeType == PhysicsTypes::Circle) {
         m_shape = cpCircleShapeNew(NULL, m_diameter/2, cpvzero);
    }
    else {
        //TODO error
        qDebug() << "Error circle";
    }

    m_shape->data = this;
    cpShapeSetFriction(m_shape, m_friction);
    cpShapeSetElasticity(m_shape, m_elasticity);
    if(m_sensor) { cpShapeSetSensor(m_shape, true); }
    cpShapeSetLayers(m_shape, m_layer);
    m_isPhysicsCreated = true;
    m_world->addPhysicsInterface(this);

    if(m_debugDraw) {
        this->setFlag(QQuickItem::ItemHasContents, true);
    }

    if(m_debugPrint) {

        qDebug() << "PhysicsShape - componentComplete()";
        qDebug() << "   Is sensor:"         << m_sensor;
        qDebug() << "   Shape type:"        << m_shapeType;
        qDebug() << "   Name:"              << m_name;
        qDebug() << "   Width:"             << this->width();
        qDebug() << "   Height:"            << this->height();
        qDebug() << "   QQuickitem pos:"    << this->x() << this->y();
        qDebug() << "   Offset pos:"        << this->m_offsetX << this->m_offsetY;
    }

     QQuickItem::componentComplete();
}
开发者ID:ccera,项目名称:QuickPhysics,代码行数:45,代码来源:physicsshape.cpp

示例5: cpBodyNew

void Ring::init(float backBoardLength, float groundLength, float ringSize, float e, float u)
{
	/*
	 
	 cpBody* backBoardBody;
	 cpShape* backBoardShape;
	 
	 cpShape* groundShape;
	 cpShape* ring1Shape;
	 cpShape* ring2Shape;*/
	int easy = -3; // 난이도 하락시키는 직선높이 차이
	this->ringSize = ringSize;
	backBoardBody = cpBodyNew(INFINITY, INFINITY);
	setPosition(cpv(57, 250));
	//backBoardBody->p = cpv(60, 250); // 50
	//backBoardBody->p = cpv(60, 100);
	backBoardShape = cpSegmentShapeNew(backBoardBody, cpv(0,0), cpv(0, backBoardLength), 1.f);
//	CCLog("backboard shape %x", backBoardShape);
	backBoardShape->e = BACKBOARD_E;
	backBoardShape->u = u;
	
	groundShape = cpSegmentShapeNew(backBoardBody, cpv(0,0), cpv(groundLength - 2.f, easy), 1.f);
//	CCLog("ground shape %x", groundShape);
	groundShape->e = e / 3.f;
	groundShape->u = u;
	
	subObject = cpSegmentShapeNew(backBoardBody, cpv(groundLength -2.f, easy), cpv(groundLength - 2.f, -10.f), 1.f); // 길다란 보조 장치, 자연스러운 공경로를 위해
//	CCLog("subobject shape %x", subObject);
	subObject->e = e;
	subObject->u = u;
	
	ring1Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv(groundLength, easy  ));
//	CCLog("ring1 shape %x", ring1Shape);
	ring1Shape->e = e / 3.f;
	ring1Shape->u = u;
	ring2Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv(groundLength + ringSize, 0.f));
//	CCLog("ring2 shape %x", ring2Shape);
	ring2Shape->e = e;
	ring2Shape->u = u;
	
	ring3Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv((2*groundLength + ringSize) / 2.f, 0.f));
//	CCLog("ring3 shape %x", ring2Shape);
	ring3Shape->e = e;
	ring3Shape->u = u;
}
开发者ID:LitQoo,项目名称:SportsWorldCupOriginal,代码行数:45,代码来源:BS2Ring.cpp

示例6: loadEditorPalette

static void loadEditorPalette(void) {
    double rx, ry;
    float xp;

    rx = atlWindowWidth() / 2.0;
    ry = atlWindowHeight() / 2.0;

    xp = -rx+editorBody->p.x+25;

    paletteObjects[0] = createPaletteObject(cpv(xp, ry-45),
                                            "data/textures/wood0.png", 100, 1.0f);

    paletteObjects[1] = createPaletteObject(cpv(xp, ry-(45*2)),
                                            "data/textures/marble0.png", 400, 2.0f);

    paletteObjects[2] = createPaletteObject(cpv(xp, ry-(45*3)),
                                            NULL, 400, 2.0f);
}
开发者ID:davidreynolds,项目名称:Atlas2D,代码行数:18,代码来源:editor.c

示例7: eachBody

// Iterate over all of the bodies and reset the ones that have fallen offscreen.
static void
eachBody(cpBody *body, void *unused)
{
	cpVect pos = cpBodyGetPos(body);
	if(pos.y < -260 || cpfabs(pos.x) > 340){
		cpFloat x = rand()/(cpFloat)RAND_MAX*640 - 320;
		cpBodySetPos(body, cpv(x, 260));
	}
}
开发者ID:Adefy,项目名称:AdefyiOS,代码行数:10,代码来源:Plink.c

示例8: PhysicalObject

ConvexObject::ConvexObject(std::vector<cpVect> points, float mass)
  : PhysicalObject(points, mass)
{
     cpRecenterPoly(points.size(), points.data());
     shape = cpPolyShapeNew(body, points.size(), points.data(), cpv(0, 0));
     shape->data = static_cast<PhysicalObject *>(this);

     shapes.push_back(shape);
}
开发者ID:mvr,项目名称:abandoned-game,代码行数:9,代码来源:ConvexObject.cpp

示例9: cpMomentForBox2

cpFloat
cpMomentForBox2(cpFloat m, cpBB box)
{
	cpFloat width = box.r - box.l;
	cpFloat height = box.t - box.b;
	cpVect offset = cpvmult(cpv(box.l + box.r, box.b + box.t), 0.5f);
	
	return cpMomentForBox(m, width, height) + m*cpvlengthsq(offset);
}
开发者ID:50Cubes,项目名称:ClusterFear,代码行数:9,代码来源:chipmunk.c

示例10: sHitData

 CEmbodiedEntity* CDynamics2DEngine::CheckIntersectionWithRay(Real& f_t_on_ray,
                                                              const CRay3& c_ray) const {
    /* Query all hits along the ray */
    SDynamics2DSegmentHitData sHitData(c_ray);
    cpSpaceSegmentQuery(
       m_ptSpace,
       cpv(c_ray.GetStart().GetX(), c_ray.GetStart().GetY()),
       cpv(c_ray.GetEnd().GetX()  , c_ray.GetEnd().GetY()  ),
       CP_ALL_LAYERS,
       CP_NO_GROUP,
       Dynamics2DSegmentQueryFunc,
       &sHitData);
    /* Check whether we have a hit */
    if(sHitData.Body != NULL) {
       f_t_on_ray = sHitData.T;
    }
    return sHitData.Body;
 }
开发者ID:hoelzl,项目名称:argos3,代码行数:18,代码来源:dynamics2d_engine.cpp

示例11: drawing_new

cpBody* drawing_new(cpFloat x, cpFloat y, long color_rgb) {
    cpBody *drawing = cpBodyNew(INITIAL, INITIAL);
    cpBodySetPos(drawing, cpv(x, y));
    
    Point_array *pa = point_array_new(x, y, color_rgb);
    cpBodySetUserData(drawing, pa);
    
    return drawing;
}
开发者ID:outgame,项目名称:CrayonPhysics,代码行数:9,代码来源:stablePhysics.c

示例12: init

static cpSpace *
init(void)
{
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	space->iterations = 30;
	cpSpaceResizeStaticHash(space, 40.0f, 1000);
	cpSpaceResizeActiveHash(space, 40.0f, 1000);
	space->gravity = cpv(0, -100);
	space->sleepTimeThreshold = 0.5f;
	
	cpBody *body, *staticBody = &space->staticBody;
	cpShape *shape;
	
	// Create segments around the edge of the screen.
	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	
	// Add lots of boxes.
	for(int i=0; i<14; i++){
		for(int j=0; j<=i; j++){
			body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f)));
			body->p = cpv(j*32 - i*16, 300 - i*32);
			
			shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f));
			shape->e = 0.0f; shape->u = 0.8f;
		}
	}
	
	// Add a ball to make things more interesting
	cpFloat radius = 15.0f;
	body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
	body->p = cpv(0, -240 + radius+5);

	shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
	shape->e = 0.0f; shape->u = 0.9f;
	
	return space;
}
开发者ID:9miao,项目名称:cocos2dx-win8,代码行数:49,代码来源:PyramidStack.cpp

示例13: main

int main (int argc, char **argv) {
    cpSpace *space = cpSpaceNew();
    cpSpaceSetGravity(space, cpv(0, GRAVITY));
    cpEnableSegmentToSegmentCollisions();
    
    cpShape *ground = cpSpaceAddShape(space, cpSegmentShapeNew(space->staticBody, cpv(0, 5), cpv(10, -5), 0));
    cpShapeSetFriction(ground, 0.3);
    
    cpBody *drawing = drawing_new(2, 7, 0);
    drawing = drawing_update(space, drawing, 3, 8);
    drawing = drawing_update(space, drawing, 3, 9);
    drawing = drawing_update(space, drawing, 2, 9);
    //cpBody *drawing = drawing_new(0, 0, 0);
    //drawing = drawing_update(space, drawing, 2, 0);
    //drawing = drawing_update(space, drawing, 2, 2);
    //drawing = drawing_update(space, drawing, 0, 2);
    print_positions(drawing);
    
    //drawing_activate(drawing);
    //print_positions(drawing);
    
    cpVect vel, pos;
    int i = 0;
    for(cpFloat time = 0; time < 2; time += TIMESTEP){
        pos = cpBodyGetPos(drawing);
        vel = cpBodyGetVel(drawing);
        
        printf( "Time = %2.2f Position = (%2.2f, %2.2f) Velocity = (%2.2f, %2.2f)\n",
            time, pos.x, pos.y, vel.x, vel.y);
        cpSpaceStep(space, TIMESTEP);
        
        i++;
        if (i == 20) {
            drawing_activate(space, drawing);
            print_positions(drawing);
        }
    }
    print_positions(drawing);
    
    free_body_full(drawing);
    cpShapeFree(ground);
    cpSpaceFree(space);
    return EXIT_SUCCESS;
}
开发者ID:outgame,项目名称:CrayonPhysics,代码行数:44,代码来源:physics.c

示例14: addChild

void HelloWorld::addPhysicSprite() {
#if CC_ENABLE_CHIPMUNK_INTEGRATION
    // Use batch node. Faster
    CCSpriteBatchNode *parent = CCSpriteBatchNode::create(s_SpinPea, 100);
    m_pSpriteTexture = parent->getTexture();

    addChild(parent, 100, kTagParentNode);

    CCPoint pos = ccp(200,200);
    int posx, posy;

    CCNode *parent = getChildByTag(kTagParentNode);

    posx = CCRANDOM_0_1() * 200.0f;
    posy = CCRANDOM_0_1() * 200.0f;

    posx = (posx % 4) * 85;
    posy = (posy % 3) * 121;


    int num = 4;
    cpVect verts[] = {
        cpv(-24,-54),
        cpv(-24, 54),
        cpv( 24, 54),
        cpv( 24,-54),
    };

    cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));

    body->p = cpv(pos.x, pos.y);
    cpSpaceAddBody(m_pSpace, body);

    cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
    shape->e = 0.5f; shape->u = 0.5f;
    cpSpaceAddShape(m_pSpace, shape);

    CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121));
    parent->addChild(sprite,50);

    sprite->setCPBody(body);
    sprite->setPosition(pos);
#endif
}
开发者ID:S74390E2,项目名称:dd_Sudoku,代码行数:44,代码来源:HelloWorldScene.cpp

示例15: cpSpaceAddBody

cpBody*
PhysicsWorld::AddRectBody(cpFloat width, cpFloat height, cpFloat xPosition, cpFloat yPosition, cpFloat mass)
{
    // Create and add the body
    cpBody *boxBody = cpSpaceAddBody(mySpace, cpBodyNew(mass, cpMomentForBox(mass, width, height)));
    // Set it's position in the world
    cpBodySetPos(boxBody, cpv(xPosition, yPosition));
    
    return boxBody;
}
开发者ID:pkonneker,项目名称:Open2dAdventure,代码行数:10,代码来源:PhysicsWorld.cpp


注:本文中的cpv函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。