Ejemplo n.º 1
0
__declspec( dllexport ) void push( const void * _in, int in_size, void * _out, int out_sz )
{
	int index;
	Variable *var;
	cpBody *body;
	cpShape *shape;

	index = PEEKINT(INPUT_MEMBLOCK,0);
	var = vhGetVariable(&mVariableHandler,index);
	switch (var->mType)
	{
	case VarTypeBody:
		body = (cpBody*)var->mPtr;
		
		cpBodySetAngle(body,degToRad(PEEKFLOAT(INPUT_MEMBLOCK,4)));
		cpBodySetPos(body,PEEKVECT(INPUT_MEMBLOCK,8));
		cpBodySetAngVel(body,degToRad(PEEKFLOAT(INPUT_MEMBLOCK,16)));
		cpBodySetVel(body,PEEKVECT(INPUT_MEMBLOCK,20));
		break;

	case VarTypeShape:
		shape = (cpShape*)var->mPtr;
		cpShapeSetFriction(shape,PEEKFLOAT(INPUT_MEMBLOCK,4));
		cpShapeSetElasticity(shape,PEEKFLOAT(INPUT_MEMBLOCK,8));
		cpShapeSetLayers(shape,PEEKUINT(INPUT_MEMBLOCK,12));
		cpShapeSetGroup(shape,PEEKUINT(INPUT_MEMBLOCK,16));
		break;
	}
}
void PhysicsShapeInfo::add(cpShape* shape)
{
    if (shape == nullptr) return;
    
    cpShapeSetGroup(shape, _group);
    _shapes.push_back(shape);
    _map.insert(std::pair<cpShape*, PhysicsShapeInfo*>(shape, this));
}
void PhysicsShapeInfo::setGroup(cpGroup group)
{
    this->_group = group;
    
    for (cpShape* shape : _shapes)
    {
        cpShapeSetGroup(shape, group);
    }
}
Ejemplo n.º 4
0
void PhysicsShape::addShape(cpShape* shape)
{
    if (shape)
    {
        cpShapeSetGroup(shape, _group);
        _cpShapes.push_back(shape);
        s_physicsShapeMap.insert(std::pair<cpShape*, PhysicsShape*>(shape, this));
    }
}
Ejemplo n.º 5
0
static void
make_leg(cpFloat side, cpFloat offset, cpBody *chassis, cpBody *crank, cpVect anchor)
{
	cpVect a, b;
	cpShape *shape;
	
	cpFloat leg_mass = 1.0f;

	// make leg
	a = cpvzero, b = cpv(0.0f, side);
	cpBody *upper_leg = cpSpaceAddBody(space, cpBodyNew(leg_mass, cpMomentForSegment(leg_mass, a, b)));
	cpBodySetPos(upper_leg, cpv(offset, 0.0f));
	
	cpSpaceAddShape(space, cpSegmentShapeNew(upper_leg, a, b, seg_radius));
	cpSpaceAddConstraint(space, cpPivotJointNew2(chassis, upper_leg, cpv(offset, 0.0f), cpvzero));
	
	// lower leg
	a = cpvzero, b = cpv(0.0f, -1.0f*side);
	cpBody *lower_leg = cpSpaceAddBody(space, cpBodyNew(leg_mass, cpMomentForSegment(leg_mass, a, b)));
	cpBodySetPos(lower_leg, cpv(offset, -side));
	
	shape = cpSpaceAddShape(space, cpSegmentShapeNew(lower_leg, a, b, seg_radius));
	cpShapeSetGroup(shape, 1);
	
	shape = cpSpaceAddShape(space, cpCircleShapeNew(lower_leg, seg_radius*2.0f, b));
	cpShapeSetGroup(shape, 1);
	cpShapeSetElasticity(shape, 0.0f);
	cpShapeSetFriction(shape, 1.0f);
	
	cpSpaceAddConstraint(space, cpPinJointNew(chassis, lower_leg, cpv(offset, 0.0f), cpvzero));
	
	cpSpaceAddConstraint(space, cpGearJointNew(upper_leg, lower_leg, 0.0f, 1.0f));
	
	cpConstraint *constraint;
	cpFloat diag = cpfsqrt(side*side + offset*offset);
	
	constraint = cpSpaceAddConstraint(space, cpPinJointNew(crank, upper_leg, anchor, cpv(0.0f, side)));
	cpPinJointSetDist(constraint, diag);
	
	constraint = cpSpaceAddConstraint(space, cpPinJointNew(crank, lower_leg, anchor, cpvzero));
	cpPinJointSetDist(constraint, diag);
}
Ejemplo n.º 6
0
void PhysicsShape::setGroup(int group)
{
    if (group < 0)
    {
        for (auto shape : _cpShapes)
        {
            cpShapeSetGroup(shape, (cpGroup)group);
        }
    }
    
    _group = group;
}
Ejemplo n.º 7
0
static cpBody *
add_bar(cpVect a, cpVect b, int group)
{
	cpVect center = cpvmult(cpvadd(a, b), 1.0f/2.0f);
	cpFloat length = cpvlength(cpvsub(b, a));
	cpFloat mass = length/160.0f;
	
	cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, mass*length*length/12.0f));
	cpBodySetPos(body, center);
	
	cpShape *shape = cpSpaceAddShape(space, cpSegmentShapeNew(body, cpvsub(a, center), cpvsub(b, center), 10.0f));
	cpShapeSetGroup(shape, group);
	
	return body;
}
Ejemplo n.º 8
0
static cpBody *
addWheel(cpVect pos, cpVect boxOffset)
{
	cpFloat radius = 15.0f;
	cpFloat mass = 1.0f;
	cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, radius, cpvzero)));
	cpBodySetPos(body, cpvadd(pos, boxOffset));
	
	cpShape *shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
	cpShapeSetElasticity(shape, 0.0f);
	cpShapeSetFriction(shape, 0.7f);
	cpShapeSetGroup(shape, 1); // use a group to keep the car parts from colliding
	
	return body;
}
Ejemplo n.º 9
0
static cpBody *
addChassis(cpVect pos, cpVect boxOffset)
{
	cpFloat mass = 5.0f;
	cpFloat width = 80;
	cpFloat height = 30;
	
	cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForBox(mass, width, height)));
	cpBodySetPos(body, cpvadd(pos, boxOffset));
	
	cpShape *shape = cpSpaceAddShape(space, cpBoxShapeNew(body, width, height));
	cpShapeSetElasticity(shape, 0.0f);
	cpShapeSetFriction(shape, 0.7f);
	cpShapeSetGroup(shape, 1); // use a group to keep the car parts from colliding
	
	return body;
}
Ejemplo n.º 10
0
void CCPhysicsShape::setCollisionGroup(int group)
{
    cpShapeSetGroup(m_shape, (cpGroup)group);
}
Ejemplo n.º 11
0
bool Unit::update( const Frame& frame )
{
	const StackData& param = frame.params[0];

	switch(frame.command){
		case acNone:
			break;

		// Functions
		case acSuper:
			Actions.saveState( true );
			Actions.setParentAction( param.stringData );
			break;
		case acRestoreState:
			// This is return for acSuper command. It does nothing if no saved state .
			Actions.restoreState();
			break;
		case acSetAction:
			// If param is not null, it will be action call, not replacing
			if( Actions.checkFrameParams( frame, 1, stStringOrNone ) ){
				Actions.setAction( param.stringData );
				return false;
			}
			break;
		case acSetTimer:
			if( Actions.checkFrameParams( frame, 2, stFunction, stInt ) ){
				ActionTimer* timer = actionTimers;
				const Frame* pframe = &frame;
				while( timer != NULL ){
					if( timer->frame == pframe )
						break;
					timer = timer->next;
				}
				if( !timer || !Timer::UpdateEventById( timer->timerId, frame.params[1].intData) ){
					if( timer ){
						ActionTimer* oldtimer = actionTimers;
						while( timer != NULL ){
							// ActionTimer is deleted from manager. Delete it from holder.
							if( oldtimer->next == timer ){
								oldtimer->next = oldtimer->next->next;
								delete timer, timer = NULL;
								break;
							}
							timer = timer->next;
						}
					}
					IActionTimer* t = new IActionTimer( this, param.intData );
					actionTimers = new ActionTimer( pframe, t, actionTimers );
					actionTimers->timerId = Timer::AddInternalTimerEvent( t, frame.params[1].intData );
				}
			}
			break;

		// Action parameters stack
		case acPushInt:
			Actions.params.Push( param.intData );
			break;
		case acPushFloat:
			//TODO: float
			Actions.params.Push( param.intData );
			Debug::debug( Debug::PROTO, "acPushFloat not implemented.\n" );
			break;
		case acPushString:
			Actions.params.Push( param.stringData );
			break;
		case acPush:
			for( int i = 0; i < FRAME_PARAMS_COUNT; ++i ){
				switch( frame.param_types[i] ){
					case stInt:
						Actions.params.Push( frame.params[i].intData );
						break;
					case stString:
						Actions.params.Push( frame.params[i].stringData );
						break;
					default:
						break;
				}
			}
			break;

		// Conditions
		case acCondition: // acCondition always false
			Actions.frame = frame.condition_end;
			break;
		case acEnd: // Do nothing
			break;



		case acIfParamEqual:
			PARAMCOND( != )
			break;
		case acIfParamLess:
			PARAMCOND( > )
			break;
		case acIfParamMore:
			PARAMCOND( < )
			break;


		case acIfParametersEqual:
			PARAMSCOND( != )
			break;
		case acIfParametersLess:
			PARAMSCOND( > )
			break;
		case acIfParametersMore:
			PARAMSCOND( < )
			break;
		case acIfParametersLessBy:
			PARAMSCOND( + param.intData > )
			break;



		// Unit flags
		case acIfFlag:
			CHECKFLAG
				if( !( flags & param.intData ) )
					Actions.frame = frame.condition_end;
			break;
		case acIfNotFlag:
			CHECKFLAG
				if( flags & param.intData )
					Actions.frame = frame.condition_end;
			break;
		case acSetFlag:
			CHECKFLAG
				flags |= param.intData;
			break;
		case acRemoveFlag:
			CHECKFLAG
				flags &= ~param.intData;
			break;



		// Unit Parameters
		case acSetParam:
			if( Actions.checkFrameParams( frame, 2, stInt, stInt ) )
				Char.set( param.intData, (float)frame.params[1].intData );
			else
				Debug::debug( Debug::PROTO, "acSetParam bad parameter name.\n" );
			break;
		case acCopyParam:
			if( !Actions.checkFrameParams( frame, 2, stInt, stInt ) )
				Debug::debug( Debug::PROTO, "acCopyParam bad original parameter name.\n" );
			else if( !param.intData )
				Debug::debug( Debug::PROTO, "acCopyParam bad parameter name.\n" );
			else
				Char.set( param.intData, Char.get( frame.params[1].intData ) );
			break;
		case acLoadParam:
		{
			if( !Actions.checkFrameParams( frame, 2, stInt, stString ) )
				break;
			LuaConfig* cfg = new LuaConfig;
			if( param.intData < uCharIntLast )
				cfg->getValue( frame.params[1].stringData, UnitName, TypeName,
								Char.getRef( (enum character)param.intData ) );
			else
				cfg->getValue( frame.params[1].stringData, UnitName, TypeName,
								Char.getRef( (enum character_float)param.intData ) );
			delete cfg;
			break;
		}
		case acLoadParamBunch:
		{
			if( param.intData <= 0 )
				break;
			LuaConfig* cfg = new LuaConfig;
			for( int i = 0; i < param.intData; i++ ){
				if( !Actions.params.CheckParamTypes( 2, stInt, stString ) ){
					Debug::debug( Debug::PROTO, "acLoadPraramBunch wrong " +
							citoa(i+1) + " parameter set.\n" );
					continue;
				}
				int psparam = Actions.params.PopInt();
				if( psparam < uCharIntLast )
					cfg->getValue( Actions.params.PopString(), UnitName, TypeName,
							Char.getRef( (enum character)psparam ) );
				else
					cfg->getValue( Actions.params.PopString(), UnitName, TypeName,
							Char.getRef( (enum character_float)psparam ) );
			}
			delete cfg;
			break;
		}


		// Physics
		case acSetUnitPhysics:
			if( Actions.checkFrameParams( frame, 3, stInt, stInt, stIntOrNone ) ){
				int firstparam = frame.params[1].intData;
				switch(param.intData){
					case pptMat:
						break;
					case pptRadius:
						phys.radius = firstparam;
						break;
					case pptSides:
						phys.sides.x = firstparam;
						phys.sides.y = frame.params[2].intData;
						break;
				}
				phys.calc_mass();
				updatePhysics( );
			}
			break;
		case acSetPhysicsLayer:
			if( Actions.checkFrameParams( frame, 1, stInt ) && physShape != NULL )
				cpShapeSetGroup( physShape, param.intData );
			break;

		// Misc
		case acSetUnitSize:
			if( Actions.checkFrameParams( frame, 1, stInt ) )
				setUnitSize( static_cast<float>(param.intData) / 100 );
			break;
		case acSetColor:
			if( Actions.checkFrameParams( frame, 4, stInt, stInt, stInt, stInt ) )
				Image.getSprite()->clr.set( frame.params[0].intData, frame.params[1].intData,
						frame.params[2].intData, frame.params[3].intData );
			break;

		default:
			return false;
	}
	return true;
}
Ejemplo n.º 12
0
static cpSpace *
init(void)
{
	ChipmunkDemoMessageString = "Use the arrow keys to control the machine.";
	
	space = cpSpaceNew();
	cpSpaceSetIterations(space, 20);
	cpSpaceSetGravity(space, cpv(0,-500));
	
	cpBody *staticBody = cpSpaceGetStaticBody(space);
	cpShape *shape;
	cpVect a, b;
	
	// 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);
	cpShapeSetLayers(shape, NOT_GRABABLE_MASK);

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

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	cpShapeSetElasticity(shape, 1.0f);
	cpShapeSetFriction(shape, 1.0f);
	cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
	
	cpFloat offset = 30.0f;

	// make chassis
	cpFloat chassis_mass = 2.0f;
	a = cpv(-offset, 0.0f), b = cpv(offset, 0.0f);
	cpBody *chassis = cpSpaceAddBody(space, cpBodyNew(chassis_mass, cpMomentForSegment(chassis_mass, a, b)));
	
	shape = cpSpaceAddShape(space, cpSegmentShapeNew(chassis, a, b, seg_radius));
	cpShapeSetGroup(shape, 1);
	
	// make crank
	cpFloat crank_mass = 1.0f;
	cpFloat crank_radius = 13.0f;
	cpBody *crank = cpSpaceAddBody(space, cpBodyNew(crank_mass, cpMomentForCircle(crank_mass, crank_radius, 0.0f, cpvzero)));
	
	shape = cpSpaceAddShape(space, cpCircleShapeNew(crank, crank_radius, cpvzero));
	cpShapeSetGroup(shape, 1);
	
	cpSpaceAddConstraint(space, cpPivotJointNew2(chassis, crank, cpvzero, cpvzero));
	
	cpFloat side = 30.0f;
	
	int num_legs = 2;
	for(int i=0; i<num_legs; i++){
		make_leg(side,  offset, chassis, crank, cpvmult(cpvforangle((cpFloat)(2*i+0)/(cpFloat)num_legs*M_PI), crank_radius));
		make_leg(side, -offset, chassis, crank, cpvmult(cpvforangle((cpFloat)(2*i+1)/(cpFloat)num_legs*M_PI), crank_radius));
	}
	
	motor = cpSpaceAddConstraint(space, cpSimpleMotorNew(chassis, crank, 6.0f));

	return space;
}
Ejemplo n.º 13
0
void worldShape_setGroup(WorldShape_t *aShape, WorldShapeGroup_t aGroup)
{
    cpShapeSetGroup(aShape->cpShape, aGroup);
}
Ejemplo n.º 14
0
		void shape::group( cpGroup group ) {	cpShapeSetGroup( this->m_shape, group );	}