本文整理汇总了C++中cpvdot函数的典型用法代码示例。如果您正苦于以下问题:C++ cpvdot函数的具体用法?C++ cpvdot怎么用?C++ cpvdot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpvdot函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cpPolyShapeSegmentQuery
static void
cpPolyShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info)
{
cpPolyShape *poly = (cpPolyShape *)shape;
cpPolyShapeAxis *axes = poly->tAxes;
cpVect *verts = poly->tVerts;
int numVerts = poly->numVerts;
for(int i=0; i<numVerts; i++){
cpVect n = axes[i].n;
cpFloat an = cpvdot(a, n);
if(axes[i].d > an) continue;
cpFloat bn = cpvdot(b, n);
cpFloat t = (axes[i].d - an)/(bn - an);
if(t < 0.0f || 1.0f < t) continue;
cpVect point = cpvlerp(a, b, t);
cpFloat dt = -cpvcross(n, point);
cpFloat dtMin = -cpvcross(n, verts[i]);
cpFloat dtMax = -cpvcross(n, verts[(i+1)%numVerts]);
if(dtMin <= dt && dt <= dtMax){
info->shape = shape;
info->t = t;
info->n = n;
}
}
}
开发者ID:Avant-Flux,项目名称:chipmunk,代码行数:29,代码来源:cpPolyShape.c
示例2: DeepestNotch
static struct Notch
DeepestNotch(int count, cpVect *verts, int hullCount, cpVect *hullVerts, int first, cpFloat tol)
{
struct Notch notch = {};
int j = Next(first, count);
for(int i=0; i<hullCount; i++){
cpVect a = hullVerts[i];
cpVect b = hullVerts[Next(i, hullCount)];
// TODO use a cross check instead?
cpVect n = cpvnormalize(cpvrperp(cpvsub(a, b)));
cpFloat d = cpvdot(n, a);
cpVect v = verts[j];
while(!cpveql(v, b)){
cpFloat depth = cpvdot(n, v) - d;
if(depth > notch.d){
notch.d = depth;
notch.i = j;
notch.v = v;
notch.n = n;
}
j = Next(j, count);
v = verts[j];
}
j = Next(j, count);
}
return notch;
}
开发者ID:cxuhua,项目名称:cxengine,代码行数:34,代码来源:cpPolyline.c
示例3: cpSegmentShapePointQuery
static cpBool
cpSegmentShapePointQuery(cpSegmentShape *seg, cpVect p){
if(!cpBBContainsVect(seg->shape.bb, p)) return cpFalse;
// Calculate normal distance from segment.
cpFloat dn = cpvdot(seg->tn, p) - cpvdot(seg->ta, seg->tn);
cpFloat dist = cpfabs(dn) - seg->r;
if(dist > 0.0f) return cpFalse;
// Calculate tangential distance along segment.
cpFloat dt = -cpvcross(seg->tn, p);
cpFloat dtMin = -cpvcross(seg->tn, seg->ta);
cpFloat dtMax = -cpvcross(seg->tn, seg->tb);
// Decision tree to decide which feature of the segment to collide with.
if(dt <= dtMin){
if(dt < (dtMin - seg->r)){
return cpFalse;
} else {
return cpvlengthsq(cpvsub(seg->ta, p)) < (seg->r*seg->r);
}
} else {
if(dt < dtMax){
return cpTrue;
} else {
if(dt < (dtMax + seg->r)) {
return cpvlengthsq(cpvsub(seg->tb, p)) < (seg->r*seg->r);
} else {
return cpFalse;
}
}
}
return cpTrue;
}
开发者ID:50Cubes,项目名称:ClusterFear,代码行数:35,代码来源:cpShape.c
示例4: circle2segment
static int
circle2segment(const cpCircleShape *circleShape, const cpSegmentShape *segmentShape, cpContact *con)
{
cpVect seg_a = segmentShape->ta;
cpVect seg_b = segmentShape->tb;
cpVect center = circleShape->tc;
cpVect seg_delta = cpvsub(seg_b, seg_a);
cpFloat closest_t = cpfclamp01(cpvdot(seg_delta, cpvsub(center, seg_a))/cpvlengthsq(seg_delta));
cpVect closest = cpvadd(seg_a, cpvmult(seg_delta, closest_t));
if(circle2circleQuery(center, closest, circleShape->r, segmentShape->r, con)){
cpVect n = con[0].n;
// Reject endcap collisions if tangents are provided.
if(
(closest_t == 0.0f && cpvdot(n, segmentShape->a_tangent) < 0.0) ||
(closest_t == 1.0f && cpvdot(n, segmentShape->b_tangent) < 0.0)
) return 0;
return 1;
} else {
return 0;
}
}
开发者ID:csdnnet,项目名称:hiygame,代码行数:25,代码来源:cpCollision.c
示例5: segValueOnAxis
// Like cpPolyValueOnAxis(), but for segments.
static inline cpFloat
segValueOnAxis(cpSegmentShape *seg, cpVect n, cpFloat d)
{
cpFloat a = cpvdot(n, seg->ta) - seg->r;
cpFloat b = cpvdot(n, seg->tb) - seg->r;
return cpfmin(a, b) - d;
}
开发者ID:BellyWong,项目名称:RubyCocos2D,代码行数:8,代码来源:cpCollision.c
示例6: applyImpulse
static void
applyImpulse(cpPulleyJoint *joint)
{
cpBody* b1 = joint->constraint.a;
cpBody* b2 = joint->constraint.b;
cpVect r1 = joint->r1;
cpVect r2 = joint->r2;
// The magic and mystery below
if (joint->state)
{
cpVect v1 = cpvadd(b1->v, cpv(-b1->w * r1.y, b1->w * r1.x));
cpVect v2 = cpvadd(b2->v, cpv(-b2->w * r2.y, b2->w * r2.x));
cpFloat Cdot = -cpvdot(joint->u1, v1) - joint->ratio * cpvdot(joint->u2, v2);
cpFloat impulse = joint->pulleyMass * (-Cdot);
cpFloat oldImpulse = joint->jnAcc;
joint->jnAcc = cpfmax(0.0f, joint->jnAcc + impulse);
impulse = joint->jnAcc - oldImpulse;
cpVect P1 = cpvmult(joint->u1, -impulse);
cpVect P2 = cpvmult(joint->u2, -joint->ratio * impulse);
cpBodyApplyImpulse(b1, P1, r1);
cpBodyApplyImpulse(b2, P2, r2);
}
if (joint->limitState1)
{
cpVect v1 = cpvadd(b1->v, cpv(-b1->w * r1.y, b1->w * r1.x));
cpFloat Cdot = -cpvdot(joint->u1, v1);
cpFloat impulse = -joint->limitMass1 * Cdot;
cpFloat oldImpulse = joint->jnAccLim1;
joint->jnAccLim1 = cpfmax(0.0f, joint->jnAccLim1 + impulse);
impulse = joint->jnAccLim1 - oldImpulse;
cpVect P1 = cpvmult(joint->u1, -impulse);
cpBodyApplyImpulse(b1, P1, r1);
}
if (joint->limitState2)
{
cpVect v2 = cpvadd(b2->v, cpv(-b2->w * r2.y, b2->w * r2.x));
cpFloat Cdot = -cpvdot(joint->u2, v2);
cpFloat impulse = -joint->limitMass2 * Cdot;
cpFloat oldImpulse = joint->jnAccLim2;
joint->jnAccLim2 = cpfmax(0.0f, joint->jnAccLim2 + impulse);
impulse = joint->jnAccLim2 - oldImpulse;
cpVect P2 = cpvmult(joint->u2, -impulse);
cpBodyApplyImpulse(b2, P2, r2);
}
}
开发者ID:Morrok123,项目名称:Toss-Blocks,代码行数:57,代码来源:cpPulleyJoint.c
示例7: cpArbiterApplyImpulse
void
cpArbiterApplyImpulse(cpArbiter *arb)
{
cpBody *a = arb->a->body;
cpBody *b = arb->b->body;
for(int i=0; i<arb->numContacts; i++){
cpContact *con = &arb->contacts[i];
cpVect n = con->n;
cpVect r1 = con->r1;
cpVect r2 = con->r2;
// Calculate the relative bias velocities.
cpVect vb1 = cpvadd(a->v_bias, cpvmult(cpvperp(r1), a->w_bias));
cpVect vb2 = cpvadd(b->v_bias, cpvmult(cpvperp(r2), b->w_bias));
cpFloat vbn = cpvdot(cpvsub(vb2, vb1), n);
// Calculate and clamp the bias impulse.
cpFloat jbn = (con->bias - vbn)*con->nMass;
cpFloat jbnOld = con->jBias;
con->jBias = cpfmax(jbnOld + jbn, 0.0f);
jbn = con->jBias - jbnOld;
// Apply the bias impulse.
cpVect jb = cpvmult(n, jbn);
cpBodyApplyBiasImpulse(a, cpvneg(jb), r1);
cpBodyApplyBiasImpulse(b, jb, r2);
// Calculate the relative velocity.
cpVect v1 = cpvadd(a->v, cpvmult(cpvperp(r1), a->w));
cpVect v2 = cpvadd(b->v, cpvmult(cpvperp(r2), b->w));
cpVect vr = cpvsub(v2, v1);
cpFloat vrn = cpvdot(vr, n);
// Calculate and clamp the normal impulse.
cpFloat jn = -(con->bounce + vrn)*con->nMass;
cpFloat jnOld = con->jnAcc;
con->jnAcc = cpfmax(jnOld + jn, 0.0f);
jn = con->jnAcc - jnOld;
// Calculate the relative tangent velocity.
cpVect t = cpvperp(n);
cpFloat vrt = cpvdot(cpvadd(vr, arb->target_v), t);
// Calculate and clamp the friction impulse.
cpFloat jtMax = arb->u*con->jnAcc;
cpFloat jt = -vrt*con->tMass;
cpFloat jtOld = con->jtAcc;
con->jtAcc = cpfmin(cpfmax(jtOld + jt, -jtMax), jtMax);
jt = con->jtAcc - jtOld;
// Apply the final impulse.
cpVect j = cpvadd(cpvmult(n, jn), cpvmult(t, jt));
cpBodyApplyImpulse(a, cpvneg(j), r1);
cpBodyApplyImpulse(b, j, r2);
}
}
开发者ID:Fissuras,项目名称:retroremakes-framework,代码行数:57,代码来源:cpArbiter.c
示例8: SegmentSupportPoint
static inline struct SupportPoint
SegmentSupportPoint(const cpSegmentShape *seg, const cpVect n)
{
if(cpvdot(seg->ta, n) > cpvdot(seg->tb, n)) {
return SupportPointNew(seg->ta, 0);
} else {
return SupportPointNew(seg->tb, 1);
}
}
开发者ID:cxuhua,项目名称:cxengine,代码行数:9,代码来源:cpCollision.c
示例9: GJKRecurse
// Recursive implementatino of the GJK loop.
static inline struct ClosestPoints
GJKRecurse(const struct SupportContext *ctx, const struct MinkowskiPoint v0, const struct MinkowskiPoint v1, const int iteration)
{
if(iteration > MAX_GJK_ITERATIONS) {
cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK iterations: %d", iteration);
return ClosestPointsNew(v0, v1);
}
cpVect delta = cpvsub(v1.ab, v0.ab);
// TODO: should this be an area2x check?
if(cpvcross(delta, cpvadd(v0.ab, v1.ab)) > 0.0f) {
// Origin is behind axis. Flip and try again.
return GJKRecurse(ctx, v1, v0, iteration);
} else {
cpFloat t = ClosestT(v0.ab, v1.ab);
cpVect n = (-1.0f < t && t < 1.0f ? cpvperp(delta) : cpvneg(LerpT(v0.ab, v1.ab, t)));
struct MinkowskiPoint p = Support(ctx, n);
#if DRAW_GJK
ChipmunkDebugDrawSegment(v0.ab, v1.ab, RGBAColor(1, 1, 1, 1));
cpVect c = cpvlerp(v0.ab, v1.ab, 0.5);
ChipmunkDebugDrawSegment(c, cpvadd(c, cpvmult(cpvnormalize(n), 5.0)), RGBAColor(1, 0, 0, 1));
ChipmunkDebugDrawDot(5.0, p.ab, LAColor(1, 1));
#endif
if(
cpvcross(cpvsub(v1.ab, p.ab), cpvadd(v1.ab, p.ab)) > 0.0f &&
cpvcross(cpvsub(v0.ab, p.ab), cpvadd(v0.ab, p.ab)) < 0.0f
) {
// The triangle v0, p, v1 contains the origin. Use EPA to find the MSA.
cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK->EPA iterations: %d", iteration);
return EPA(ctx, v0, p, v1);
} else {
if(cpvdot(p.ab, n) <= cpfmax(cpvdot(v0.ab, n), cpvdot(v1.ab, n))) {
// The edge v0, v1 that we already have is the closest to (0, 0) since p was not closer.
cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK iterations: %d", iteration);
return ClosestPointsNew(v0, v1);
} else {
// p was closer to the origin than our existing edge.
// Need to figure out which existing point to drop.
if(ClosestDist(v0.ab, p.ab) < ClosestDist(p.ab, v1.ab)) {
return GJKRecurse(ctx, v0, p, iteration + 1);
} else {
return GJKRecurse(ctx, p, v1, iteration + 1);
}
}
}
}
}
开发者ID:Jornason,项目名称:LearnCocos2D,代码行数:51,代码来源:cpCollision.c
示例10: cpSegmentShapeSegmentQuery
static void
cpSegmentShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info)
{
cpSegmentShape *seg = (cpSegmentShape *)shape;
cpVect n = seg->tn;
// flip n if a is behind the axis
if(cpvdot(a, n) < cpvdot(seg->ta, n))
n = cpvneg(n);
cpFloat an = cpvdot(a, n);
cpFloat bn = cpvdot(b, n);
cpFloat d = cpvdot(seg->ta, n) + seg->r;
cpFloat t = (d - an)/(bn - an);
if(0.0f < t && t < 1.0f) {
cpVect point = cpvlerp(a, b, t);
cpFloat dt = -cpvcross(seg->tn, point);
cpFloat dtMin = -cpvcross(seg->tn, seg->ta);
cpFloat dtMax = -cpvcross(seg->tn, seg->tb);
if(dtMin < dt && dt < dtMax) {
info->shape = shape;
info->t = t;
info->n = n;
return; // don't continue on and check endcaps
}
}
if(seg->r) {
cpSegmentQueryInfo info1;
info1.shape = NULL;
cpSegmentQueryInfo info2;
info2.shape = NULL;
circleSegmentQuery(shape, seg->ta, seg->r, a, b, &info1);
circleSegmentQuery(shape, seg->tb, seg->r, a, b, &info2);
if(info1.shape && !info2.shape) {
(*info) = info1;
} else if(info2.shape && !info1.shape) {
(*info) = info2;
} else if(info1.shape && info2.shape) {
if(info1.t < info2.t) {
(*info) = info1;
} else {
(*info) = info2;
}
}
}
}
开发者ID:davidmorford,项目名称:GameBuildKit,代码行数:50,代码来源:cpShape.c
示例11: cpArbiterApplyImpulse
void
cpArbiterApplyImpulse(cpArbiter *arb, cpFloat eCoef)
{
cpBody *a = arb->a->body;
cpBody *b = arb->b->body;
for(int i=0; i<arb->numContacts; i++){
cpContact *con = &arb->contacts[i];
cpVect n = con->n;
cpVect r1 = con->r1;
cpVect r2 = con->r2;
// Calculate the relative bias velocities.
cpVect vb1 = cpvadd(a->v_bias, cpvmult(cpvperp(r1), a->w_bias));
cpVect vb2 = cpvadd(b->v_bias, cpvmult(cpvperp(r2), b->w_bias));
cpFloat vbn = cpvdot(cpvsub(vb2, vb1), n);
// Calculate and clamp the bias impulse.
cpFloat jbn = (con->bias - vbn)*con->nMass;
cpFloat jbnOld = con->jBias;
con->jBias = cpfmax(jbnOld + jbn, 0.0f);
jbn = con->jBias - jbnOld;
// Apply the bias impulse.
apply_bias_impulses(a, b, r1, r2, cpvmult(n, jbn));
// Calculate the relative velocity.
cpVect vr = relative_velocity(a, b, r1, r2);
cpFloat vrn = cpvdot(vr, n);
// Calculate and clamp the normal impulse.
cpFloat jn = -(con->bounce*eCoef + vrn)*con->nMass;
cpFloat jnOld = con->jnAcc;
con->jnAcc = cpfmax(jnOld + jn, 0.0f);
jn = con->jnAcc - jnOld;
// Calculate the relative tangent velocity.
cpFloat vrt = cpvdot(cpvadd(vr, arb->surface_vr), cpvperp(n));
// Calculate and clamp the friction impulse.
cpFloat jtMax = arb->u*con->jnAcc;
cpFloat jt = -vrt*con->tMass;
cpFloat jtOld = con->jtAcc;
con->jtAcc = cpfclamp(jtOld + jt, -jtMax, jtMax);
jt = con->jtAcc - jtOld;
// Apply the final impulse.
apply_impulses(a, b, r1, r2, cpvrotate(n, cpv(jn, jt)));
}
}
开发者ID:0w,项目名称:moai-dev,代码行数:50,代码来源:cpArbiter.cpp
示例12: circle2segment
// Collide circles to segment shapes.
static int
circle2segment(cpShape *circleShape, cpShape *segmentShape, cpContact **con)
{
cpCircleShape *circ = (cpCircleShape *)circleShape;
cpSegmentShape *seg = (cpSegmentShape *)segmentShape;
// Radius sum
cpFloat rsum = circ->r + seg->r;
// Calculate normal distance from segment.
cpFloat dn = cpvdot(seg->tn, circ->tc) - cpvdot(seg->ta, seg->tn);
cpFloat dist = cpfabs(dn) - rsum;
if(dist > 0.0f) return 0;
// Calculate tangential distance along segment.
cpFloat dt = -cpvcross(seg->tn, circ->tc);
cpFloat dtMin = -cpvcross(seg->tn, seg->ta);
cpFloat dtMax = -cpvcross(seg->tn, seg->tb);
// Decision tree to decide which feature of the segment to collide with.
if(dt < dtMin){
if(dt < (dtMin - rsum)){
return 0;
} else {
return circle2circleQuery(circ->tc, seg->ta, circ->r, seg->r, con);
}
} else {
if(dt < dtMax){
cpVect n = (dn < 0.0f) ? seg->tn : cpvneg(seg->tn);
(*con) = (cpContact *)cpmalloc(sizeof(cpContact));
cpContactInit(
(*con),
cpvadd(circ->tc, cpvmult(n, circ->r + dist*0.5f)),
n,
dist,
0
);
return 1;
} else {
if(dt < (dtMax + rsum)) {
return circle2circleQuery(circ->tc, seg->tb, circ->r, seg->r, con);
} else {
return 0;
}
}
}
return 1;
}
开发者ID:BellyWong,项目名称:RubyCocos2D,代码行数:50,代码来源:cpCollision.c
示例13: segmentEncapQuery
static int
segmentEncapQuery(cpVect p1, cpVect p2, cpFloat r1, cpFloat r2, cpContact *con, cpVect tangent)
{
int count = circle2circleQuery(p1, p2, r1, r2, con);
// printf("dot %5.2f\n", cpvdot(con[0].n, tangent));
return (cpvdot(con[0].n, tangent) >= 0.0 ? count : 0);
}
开发者ID:gwthomas,项目名称:sol-framework,代码行数:7,代码来源:cpCollision.c
示例14: ClosestPointsNew
static inline struct ClosestPoints
ClosestPointsNew(const struct MinkowskiPoint v0, const struct MinkowskiPoint v1)
{
cpFloat t = ClosestT(v0.ab, v1.ab);
cpVect p = LerpT(v0.ab, v1.ab, t);
cpVect pa = LerpT(v0.a, v1.a, t);
cpVect pb = LerpT(v0.b, v1.b, t);
cpCollisionID id = (v0.id & 0xFFFF)<<16 | (v1.id & 0xFFFF);
cpVect delta = cpvsub(v1.ab, v0.ab);
cpVect n = cpvnormalize(cpvperp(delta));
cpFloat d = -cpvdot(n, p);
if(d <= 0.0f || (0.0f < t && t < 1.0f)){
struct ClosestPoints points = {pa, pb, cpvneg(n), d, id};
return points;
} else {
cpFloat d2 = cpvlength(p);
cpVect n = cpvmult(p, 1.0f/(d2 + CPFLOAT_MIN));
struct ClosestPoints points = {pa, pb, n, d2, id};
return points;
}
}
开发者ID:Ben-G,项目名称:spritebuilder-example,代码行数:25,代码来源:cpCollision.c
示例15: FindSteiner
static cpFloat
FindSteiner(int count, cpVect *verts, struct Notch notch)
{
cpFloat min = INFINITY;
cpFloat feature = -1.0;
for(int i=1; i<count-1; i++){
int index = (notch.i + i)%count;
cpVect seg_a = verts[index];
cpVect seg_b = verts[Next(index, count)];
cpFloat thing_a = cpvcross(notch.n, cpvsub(seg_a, notch.v));
cpFloat thing_b = cpvcross(notch.n, cpvsub(seg_b, notch.v));
if(thing_a*thing_b <= 0.0){
cpFloat t = thing_a/(thing_a - thing_b);
cpFloat dist = cpvdot(notch.n, cpvsub(cpvlerp(seg_a, seg_b, t), notch.v));
if(dist >= 0.0 && dist <= min){
min = dist;
feature = index + t;
}
}
}
return feature;
}
开发者ID:cxuhua,项目名称:cxengine,代码行数:27,代码来源:cpPolyline.c
示例16: seg2poly
// This one is complicated and gross. Just don't go there...
// TODO: Comment me!
static int
seg2poly(const cpShape *shape1, const cpShape *shape2, cpContact *arr)
{
cpSegmentShape *seg = (cpSegmentShape *)shape1;
cpPolyShape *poly = (cpPolyShape *)shape2;
cpSplittingPlane *planes = poly->tPlanes;
cpFloat segD = cpvdot(seg->tn, seg->ta);
cpFloat minNorm = cpPolyShapeValueOnAxis(poly, seg->tn, segD) - seg->r;
cpFloat minNeg = cpPolyShapeValueOnAxis(poly, cpvneg(seg->tn), -segD) - seg->r;
if(minNeg > 0.0f || minNorm > 0.0f) return 0;
int mini = 0;
cpFloat poly_min = segValueOnAxis(seg, planes->n, planes->d);
if(poly_min > 0.0f) return 0;
for(int i=0; i<poly->numVerts; i++){
cpFloat dist = segValueOnAxis(seg, planes[i].n, planes[i].d);
if(dist > 0.0f){
return 0;
} else if(dist > poly_min){
poly_min = dist;
mini = i;
}
}
int num = 0;
cpVect poly_n = cpvneg(planes[mini].n);
cpVect va = cpvadd(seg->ta, cpvmult(poly_n, seg->r));
cpVect vb = cpvadd(seg->tb, cpvmult(poly_n, seg->r));
if(cpPolyShapeContainsVert(poly, va))
cpContactInit(nextContactPoint(arr, &num), va, poly_n, poly_min, CP_HASH_PAIR(seg->shape.hashid, 0));
if(cpPolyShapeContainsVert(poly, vb))
cpContactInit(nextContactPoint(arr, &num), vb, poly_n, poly_min, CP_HASH_PAIR(seg->shape.hashid, 1));
// Floating point precision problems here.
// This will have to do for now.
// poly_min -= cp_collision_slop; // TODO is this needed anymore?
if(minNorm >= poly_min || minNeg >= poly_min) {
if(minNorm > minNeg)
findPointsBehindSeg(arr, &num, seg, poly, minNorm, 1.0f);
else
findPointsBehindSeg(arr, &num, seg, poly, minNeg, -1.0f);
}
// If no other collision points are found, try colliding endpoints.
if(num == 0){
cpVect poly_a = poly->tVerts[mini];
cpVect poly_b = poly->tVerts[(mini + 1)%poly->numVerts];
if(circle2circleQuery(seg->ta, poly_a, seg->r, 0.0f, arr)) return 1;
if(circle2circleQuery(seg->tb, poly_a, seg->r, 0.0f, arr)) return 1;
if(circle2circleQuery(seg->ta, poly_b, seg->r, 0.0f, arr)) return 1;
if(circle2circleQuery(seg->tb, poly_b, seg->r, 0.0f, arr)) return 1;
}
return num;
}
开发者ID:csdnnet,项目名称:hiygame,代码行数:62,代码来源:cpCollision.c
示例17: update_drive
void update_drive()
{
const cpFloat max_forward_speed = 150;
const cpFloat max_backward_speed = -20;
const cpFloat max_drive_force = 100;
int i;
for(i=0; i<1; i++) {
cpFloat desired_speed = 0;
// find desired speed
if(controls.forward)
desired_speed = max_forward_speed;
else if(controls.back)
desired_speed = max_backward_speed;
// find speed
cpVect forward_normal = cpvperp(cpvforangle(cpBodyGetAngle(tire[i])));
cpFloat speed = cpvdot(forward_velocity(i), forward_normal);
// apply force
cpFloat force = 0;
if(desired_speed > speed)
force = max_drive_force;
else if(desired_speed < speed)
force = -max_drive_force;
else
return;
cpBodyApplyImpulse(tire[i], cpvmult(forward_normal, force), cpvzero);
}
}
开发者ID:andrenho,项目名称:newhope,代码行数:31,代码来源:testwheel.c
示例18: applyImpulse
static void
applyImpulse(cpSlideJoint *joint)
{
if(cpveql(joint->n, cpvzero)) return; // early exit
cpBody *a = joint->constraint.a;
cpBody *b = joint->constraint.b;
cpVect n = joint->n;
cpVect r1 = joint->r1;
cpVect r2 = joint->r2;
// compute relative velocity
cpVect vr = relative_velocity(a, b, r1, r2);
cpFloat vrn = cpvdot(vr, n);
// compute normal impulse
cpFloat jn = (joint->bias - vrn)*joint->nMass;
cpFloat jnOld = joint->jnAcc;
joint->jnAcc = cpfclamp(jnOld + jn, -joint->jnMax, 0.0f);
jn = joint->jnAcc - jnOld;
// apply impulse
apply_impulses(a, b, joint->r1, joint->r2, cpvmult(n, jn));
}
开发者ID:johnstorm,项目名称:pur,代码行数:25,代码来源:cpSlideJoint.c
示例19: setUpVerts
static void
setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset)
{
// Fail if the user attempts to pass a concave poly, or a bad winding.
cpAssertHard(cpPolyValidate(verts, numVerts), "Polygon is concave or has a reversed winding. Consider using cpConvexHull() or CP_CONVEX_HULL().");
poly->numVerts = numVerts;
poly->verts = (cpVect *)cpcalloc(2*numVerts, sizeof(cpVect));
poly->planes = (cpSplittingPlane *)cpcalloc(2*numVerts, sizeof(cpSplittingPlane));
poly->tVerts = poly->verts + numVerts;
poly->tPlanes = poly->planes + numVerts;
for(int i=0; i<numVerts; i++){
cpVect a = cpvadd(offset, verts[i]);
cpVect b = cpvadd(offset, verts[(i+1)%numVerts]);
cpVect n = cpvnormalize(cpvperp(cpvsub(b, a)));
poly->verts[i] = a;
poly->planes[i].n = n;
poly->planes[i].d = cpvdot(n, a);
}
// TODO: Why did I add this? It duplicates work from above.
for(int i=0; i<numVerts; i++){
poly->planes[i] = cpSplittingPlaneNew(poly->verts[(i - 1 + numVerts)%numVerts], poly->verts[i]);
}
}
开发者ID:CatalystApps,项目名称:Cocos2dxv3_GAFSampleGame,代码行数:27,代码来源:cpPolyShape.c
示例20: cpDampedSpring
void
cpDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt)
{
// Calculate the world space anchor coordinates.
cpVect r1 = cpvrotate(anchr1, a->rot);
cpVect r2 = cpvrotate(anchr2, b->rot);
cpVect delta = cpvsub(cpvadd(b->p, r2), cpvadd(a->p, r1));
cpFloat dist = cpvlength(delta);
cpVect n = dist ? cpvmult(delta, 1.0f/dist) : cpvzero;
cpFloat f_spring = (dist - rlen)*k;
// Calculate the world relative velocities of the anchor points.
cpVect v1 = cpvadd(a->v, cpvmult(cpvperp(r1), a->w));
cpVect v2 = cpvadd(b->v, cpvmult(cpvperp(r2), b->w));
// Calculate the damping force.
// This really should be in the impulse solver and can produce problems when using large damping values.
cpFloat vrn = cpvdot(cpvsub(v2, v1), n);
cpFloat f_damp = vrn*cpfmin(dmp, 1.0f/(dt*(a->m_inv + b->m_inv)));
// Apply!
cpVect f = cpvmult(n, f_spring + f_damp);
cpBodyApplyForce(a, f, r1);
cpBodyApplyForce(b, cpvneg(f), r2);
}
开发者ID:JINXSHADYLANE,项目名称:quibble,代码行数:27,代码来源:cpBody.c
注:本文中的cpvdot函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论