コード例 #1
0
ファイル: rcpbody.cpp プロジェクト: trsquarelab/csscene
RVector RCPBody::force() const
{
    if (mBody) {
        cpVect p = cpBodyGetForce(mBody);
        mForce = RVector(p.x, p.y);
    }

    return mForce;
}
コード例 #2
0
	void RigidBody2D::CopyBodyData(cpBody* body)
	{
		cpBodySetAngle(m_handle, cpBodyGetAngle(body));
		cpBodySetAngularVelocity(m_handle, cpBodyGetAngularVelocity(body));
		cpBodySetCenterOfGravity(m_handle, cpBodyGetCenterOfGravity(body));
		cpBodySetForce(m_handle, cpBodyGetForce(body));
		cpBodySetPosition(m_handle, cpBodyGetPosition(body));
		cpBodySetTorque(m_handle, cpBodyGetTorque(body));
		cpBodySetVelocity(m_handle, cpBodyGetVelocity(body));
	}
コード例 #3
0
	void RigidBody2D::CopyBodyData(cpBody* from, cpBody* to)
	{
		cpBodySetAngle(to, cpBodyGetAngle(from));
		cpBodySetAngularVelocity(to, cpBodyGetAngularVelocity(from));
		cpBodySetCenterOfGravity(to, cpBodyGetCenterOfGravity(from));
		cpBodySetForce(to, cpBodyGetForce(from));
		cpBodySetPosition(to, cpBodyGetPosition(from));
		cpBodySetTorque(to, cpBodyGetTorque(from));
		cpBodySetVelocity(to, cpBodyGetVelocity(from));
	}
コード例 #4
0
ファイル: physics.c プロジェクト: dns/CLove
static int l_physics_getBodyForce(lua_State* state)
{
    l_tools_checkUserDataPlusErrMsg(state, 1, "You must provide a body");
    l_physics_Body* body = (l_physics_Body*)lua_touserdata(state, 1);

    cpVect vec = cpBodyGetForce(body->body);

    lua_pushnumber(state, vec.x);
    lua_pushnumber(state, vec.y);

    return 2;
}
コード例 #5
0
ファイル: cbody.cpp プロジェクト: dogtwelve/eepp
cVect cBody::Force() const {
	return tovect( cpBodyGetForce( mBody ) );
}
コード例 #6
0
ファイル: debug_draw.c プロジェクト: hdgarrood/swinging-game
static void
draw_shape(cpShape* shape, SDL_Surface* screen)
{
    cpBody* body = shape->body;
    struct draw_options opts = {
        .surface = screen,
        .colour = colour(200, 200, 200)
    };

    switch (shape->CP_PRIVATE(klass)->type)
    {
        case CP_CIRCLE_SHAPE:
            draw_circle_shape(opts, shape, body);
            break;
        case CP_SEGMENT_SHAPE:
            draw_segment_shape(opts, shape, body);
            break;
        case CP_POLY_SHAPE:
            draw_poly_shape(opts, shape, body);
            break;
        default:
            debug_putsf("ignoring unrecognised shape type %d",
                    shape->CP_PRIVATE(klass)->type);
            break;
    }
}

static void
draw_constraint(cpConstraint* constraint, SDL_Surface *screen)
{
    struct draw_options opts = {
        .surface = screen,
        .colour = colour(100, 100, 200)
    };

    cpVect vect_a = cpBodyGetPos(cpConstraintGetA(constraint));
    cpVect vect_b = cpBodyGetPos(cpConstraintGetB(constraint));
    draw_line(opts, vect_a, vect_b);
}

static void
draw_rotation_vector(cpBody *body, SDL_Surface *screen)
{
    struct draw_options opts = {
        .surface = screen,
        .colour = colour(200, 100, 100)
    };

    cpFloat rotation_vector_length = 30;
    cpVect pos = cpBodyGetPos(body);
    cpVect rotation = cpvmult(cpvforangle(cpBodyGetAngle(body)),
                              rotation_vector_length);
    draw_line(opts, pos, cpvadd(pos, rotation));
}

static void
draw_forces(cpBody *body, SDL_Surface *screen)
{
    struct draw_options opts = {
        .surface = screen,
        .colour = colour(100, 200, 100)
    };

    cpVect pos = cpBodyGetPos(body);
    cpVect force = cpBodyGetForce(body);
    draw_line(opts, pos, cpvadd(pos, force));
}

static void
draw_body(cpBody *body, SDL_Surface *screen)
{
    draw_rotation_vector(body, screen);
    draw_forces(body, screen);
}

void
debug_draw_space(cpSpace* space, SDL_Surface* screen)
{
    cpSpaceEachShape(space,
        (cpSpaceShapeIteratorFunc)draw_shape,
        screen);
    cpSpaceEachConstraint(space,
        (cpSpaceConstraintIteratorFunc)draw_constraint,
        screen);
    cpSpaceEachBody(space,
        (cpSpaceBodyIteratorFunc)draw_body,
        screen);
}
コード例 #7
0
ファイル: physics.c プロジェクト: andi2/cgame
Vec2 physics_get_force(Entity ent)
{
    PhysicsInfo *info = entitypool_get(pool, ent);
    error_assert(info);
    return vec2_of_cpv(cpBodyGetForce(info->body));
}
コード例 #8
0
ファイル: Body.cpp プロジェクト: Marwes/CppChipmunk
cp::Vect Body::getForce(void)
{
		return cpBodyGetForce(body);
}