| 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | * SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/ |
| 23 | |
| 24 | #ifndef CP_SPACE_DISABLE_DEBUG_API |
| 25 | |
| 26 | static void |
| 27 | cpSpaceDebugDrawShapecxx . . $ cpSpaceDebugDrawShape(3e4f539ab8088f7e).(cpShapecxx . . $ cpShape# *shape, cpSpaceDebugDrawOptionscxx . . $ cpSpaceDebugDrawOptions# *options) |
| 28 | { |
| 29 | cpBodycxx . . $ cpBody# *body = shape->bodycxx . . $ cpShape#body.; |
| 30 | cpDataPointercxx . . $ cpDataPointer# data = options->datacxx . . $ cpSpaceDebugDrawOptions#data.; |
| 31 | |
| 32 | cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# outline_color = options->shapeOutlineColorcxx . . $ cpSpaceDebugDrawOptions#shapeOutlineColor.; |
| 33 | cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# fill_color = options->colorForShapecxx . . $ cpSpaceDebugDrawOptions#colorForShape.(shape, data); |
| 34 | |
| 35 | switch(shape->klasscxx . . $ cpShape#klass.->typecxx . . $ cpShapeClass#type.){ |
| 36 | case CP_CIRCLE_SHAPEcxx . . $ CP_CIRCLE_SHAPE.: { |
| 37 | cpCircleShapecxx . . $ cpCircleShape# *circle = (cpCircleShapecxx . . $ cpCircleShape# *)shape; |
| 38 | options->drawCirclecxx . . $ cpSpaceDebugDrawOptions#drawCircle.(circle->tccxx . . $ cpCircleShape#tc., body->acxx . . $ cpBody#a., circle->rcxx . . $ cpCircleShape#r., outline_color, fill_color, data); |
| 39 | break; |
| 40 | } |
| 41 | case CP_SEGMENT_SHAPEcxx . . $ CP_SEGMENT_SHAPE.: { |
| 42 | cpSegmentShapecxx . . $ cpSegmentShape# *seg = (cpSegmentShapecxx . . $ cpSegmentShape# *)shape; |
| 43 | options->drawFatSegmentcxx . . $ cpSpaceDebugDrawOptions#drawFatSegment.(seg->tacxx . . $ cpSegmentShape#ta., seg->tbcxx . . $ cpSegmentShape#tb., seg->rcxx . . $ cpSegmentShape#r., outline_color, fill_color, data); |
| 44 | break; |
| 45 | } |
| 46 | case CP_POLY_SHAPEcxx . . $ CP_POLY_SHAPE.: { |
| 47 | cpPolyShapecxx . . $ cpPolyShape# *poly = (cpPolyShapecxx . . $ cpPolyShape# *)shape; |
| 48 | |
| 49 | int count = poly->countcxx . . $ cpPolyShape#count.; |
| 50 | struct cpSplittingPlanecxx . . $ cpSplittingPlane# *planes = poly->planescxx . . $ cpPolyShape#planes.; |
| 51 | cpVectcxx . . $ cpVect# *verts = (cpVectcxx . . $ cpVect# *)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(count*sizeof(cpVect)); |
| 52 | |
| 53 | for(int i=0; i<count; i++) verts[i] = planes[i].v0cxx . . $ cpSplittingPlane#v0.; |
| 54 | options->drawPolygoncxx . . $ cpSpaceDebugDrawOptions#drawPolygon.(count, verts, poly->rcxx . . $ cpPolyShape#r., outline_color, fill_color, data); |
| 55 | break; |
| 56 | } |
| 57 | default: break; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | static const cpVectcxx . . $ cpVect# spring_vertscxx . . $ spring_verts.[] = { |
| 62 | {0.00f, 0.0f}, |
| 63 | {0.20f, 0.0f}, |
| 64 | {0.25f, 3.0f}, |
| 65 | {0.30f,-6.0f}, |
| 66 | {0.35f, 6.0f}, |
| 67 | {0.40f,-6.0f}, |
| 68 | {0.45f, 6.0f}, |
| 69 | {0.50f,-6.0f}, |
| 70 | {0.55f, 6.0f}, |
| 71 | {0.60f,-6.0f}, |
| 72 | {0.65f, 6.0f}, |
| 73 | {0.70f,-3.0f}, |
| 74 | {0.75f, 6.0f}, |
| 75 | {0.80f, 0.0f}, |
| 76 | {1.00f, 0.0f}, |
| 77 | }; |
| 78 | static const int spring_countcxx . . $ spring_count. = sizeof(spring_vertscxx . . $ spring_verts.)/sizeof(cpVectcxx . . $ cpVect#); |
| 79 | |
| 80 | static void |
| 81 | cpSpaceDebugDrawConstraintcxx . . $ cpSpaceDebugDrawConstraint(f0b63336718cfb48).(cpConstraintcxx . . $ cpConstraint# *constraint, cpSpaceDebugDrawOptionscxx . . $ cpSpaceDebugDrawOptions# *options) |
| 82 | { |
| 83 | cpDataPointercxx . . $ cpDataPointer# data = options->datacxx . . $ cpSpaceDebugDrawOptions#data.; |
| 84 | cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# color = options->constraintColorcxx . . $ cpSpaceDebugDrawOptions#constraintColor.; |
| 85 | |
| 86 | cpBodycxx . . $ cpBody# *body_a = constraint->acxx . . $ cpConstraint#a.; |
| 87 | cpBodycxx . . $ cpBody# *body_b = constraint->bcxx . . $ cpConstraint#b.; |
| 88 | |
| 89 | if(cpConstraintIsPinJointcxx . . $ cpConstraintIsPinJoint(ca4e56e976f68364).(constraint)){ |
| 90 | cpPinJointcxx . . $ cpPinJoint# *joint = (cpPinJointcxx . . $ cpPinJoint# *)constraint; |
| 91 | |
| 92 | cpVectcxx . . $ cpVect# a = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., joint->anchorAcxx . . $ cpPinJoint#anchorA.); |
| 93 | cpVectcxx . . $ cpVect# b = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_b->transformcxx . . $ cpBody#transform., joint->anchorBcxx . . $ cpPinJoint#anchorB.); |
| 94 | |
| 95 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, a, color, data); |
| 96 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, b, color, data); |
| 97 | options->drawSegmentcxx . . $ cpSpaceDebugDrawOptions#drawSegment.(a, b, color, data); |
| 98 | } else if(cpConstraintIsSlideJointcxx . . $ cpConstraintIsSlideJoint(ca4e56e976f68364).(constraint)){ |
| 99 | cpSlideJointcxx . . $ cpSlideJoint# *joint = (cpSlideJointcxx . . $ cpSlideJoint# *)constraint; |
| 100 | |
| 101 | cpVectcxx . . $ cpVect# a = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., joint->anchorAcxx . . $ cpSlideJoint#anchorA.); |
| 102 | cpVectcxx . . $ cpVect# b = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_b->transformcxx . . $ cpBody#transform., joint->anchorBcxx . . $ cpSlideJoint#anchorB.); |
| 103 | |
| 104 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, a, color, data); |
| 105 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, b, color, data); |
| 106 | options->drawSegmentcxx . . $ cpSpaceDebugDrawOptions#drawSegment.(a, b, color, data); |
| 107 | } else if(cpConstraintIsPivotJointcxx . . $ cpConstraintIsPivotJoint(ca4e56e976f68364).(constraint)){ |
| 108 | cpPivotJointcxx . . $ cpPivotJoint# *joint = (cpPivotJointcxx . . $ cpPivotJoint# *)constraint; |
| 109 | |
| 110 | cpVectcxx . . $ cpVect# a = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., joint->anchorAcxx . . $ cpPivotJoint#anchorA.); |
| 111 | cpVectcxx . . $ cpVect# b = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_b->transformcxx . . $ cpBody#transform., joint->anchorBcxx . . $ cpPivotJoint#anchorB.); |
| 112 | |
| 113 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, a, color, data); |
| 114 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, b, color, data); |
| 115 | } else if(cpConstraintIsGrooveJointcxx . . $ cpConstraintIsGrooveJoint(ca4e56e976f68364).(constraint)){ |
| 116 | cpGrooveJointcxx . . $ cpGrooveJoint# *joint = (cpGrooveJointcxx . . $ cpGrooveJoint# *)constraint; |
| 117 | |
| 118 | cpVectcxx . . $ cpVect# a = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., joint->grv_acxx . . $ cpGrooveJoint#grv_a.); |
| 119 | cpVectcxx . . $ cpVect# b = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., joint->grv_bcxx . . $ cpGrooveJoint#grv_b.); |
| 120 | cpVectcxx . . $ cpVect# c = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_b->transformcxx . . $ cpBody#transform., joint->anchorBcxx . . $ cpGrooveJoint#anchorB.); |
| 121 | |
| 122 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, c, color, data); |
| 123 | options->drawSegmentcxx . . $ cpSpaceDebugDrawOptions#drawSegment.(a, b, color, data); |
| 124 | } else if(cpConstraintIsDampedSpringcxx . . $ cpConstraintIsDampedSpring(ca4e56e976f68364).(constraint)){ |
| 125 | cpDampedSpringcxx . . $ cpDampedSpring# *spring = (cpDampedSpringcxx . . $ cpDampedSpring# *)constraint; |
| 126 | cpDataPointercxx . . $ cpDataPointer# data = options->datacxx . . $ cpSpaceDebugDrawOptions#data.; |
| 127 | cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# color = options->constraintColorcxx . . $ cpSpaceDebugDrawOptions#constraintColor.; |
| 128 | |
| 129 | cpVectcxx . . $ cpVect# a = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_a->transformcxx . . $ cpBody#transform., spring->anchorAcxx . . $ cpDampedSpring#anchorA.); |
| 130 | cpVectcxx . . $ cpVect# b = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(body_b->transformcxx . . $ cpBody#transform., spring->anchorBcxx . . $ cpDampedSpring#anchorB.); |
| 131 | |
| 132 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, a, color, data); |
| 133 | options->drawDotcxx . . $ cpSpaceDebugDrawOptions#drawDot.(5, b, color, data); |
| 134 | |
| 135 | cpVectcxx . . $ cpVect# delta = cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(b, a); |
| 136 | cpFloatcxx . . $ cpFloat# cos = delta.xcxx . . $ cpVect#x.; |
| 137 | cpFloatcxx . . $ cpFloat# sin = delta.ycxx . . $ cpVect#y.; |
| 138 | cpFloatcxx . . $ cpFloat# s = 1.0f/cpvlengthcxx . . $ cpvlength(c4ef53c170268e01).(delta); |
| 139 | |
| 140 | cpVectcxx . . $ cpVect# r1 = cpvcxx . . $ cpv(3142d57d978b2176).(cos, -sin*s); |
| 141 | cpVectcxx . . $ cpVect# r2 = cpvcxx . . $ cpv(3142d57d978b2176).(sin, cos*s); |
| 142 | |
| 143 | cpVectcxx . . $ cpVect# *verts = (cpVectcxx . . $ cpVect# *)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(spring_count*sizeof(cpVect)); |
| 144 | for(int i=0; i<spring_countcxx . . $ spring_count.; i++){ |
| 145 | cpVectcxx . . $ cpVect# v = spring_vertscxx . . $ spring_verts.[i]; |
| 146 | verts[i] = cpvcxx . . $ cpv(3142d57d978b2176).(cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(v, r1) + a.xcxx . . $ cpVect#x., cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(v, r2) + a.ycxx . . $ cpVect#y.); |
| 147 | } |
| 148 | |
| 149 | for(int i=0; i<spring_countcxx . . $ spring_count.-1; i++){ |
| 150 | options->drawSegmentcxx . . $ cpSpaceDebugDrawOptions#drawSegment.(verts[i], verts[i + 1], color, data); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void |
| 156 | cpSpaceDebugDrawcxx . . $ cpSpaceDebugDraw(65c744a1b54fb2ad).(cpSpacecxx . . $ cpSpace# *space, cpSpaceDebugDrawOptionscxx . . $ cpSpaceDebugDrawOptions# *options) |
| 157 | { |
| 158 | if(options->flagscxx . . $ cpSpaceDebugDrawOptions#flags. & CP_SPACE_DEBUG_DRAW_SHAPEScxx . . $ CP_SPACE_DEBUG_DRAW_SHAPES.){ |
| 159 | cpSpaceEachShapecxx . . $ cpSpaceEachShape(c89de79254242337).(space, (cpSpaceShapeIteratorFunccxx . . $ cpSpaceShapeIteratorFunc#)cpSpaceDebugDrawShapecxx . . $ cpSpaceDebugDrawShape(3e4f539ab8088f7e)., options); |
| 160 | } |
| 161 | |
| 162 | if(options->flagscxx . . $ cpSpaceDebugDrawOptions#flags. & CP_SPACE_DEBUG_DRAW_CONSTRAINTScxx . . $ CP_SPACE_DEBUG_DRAW_CONSTRAINTS.){ |
| 163 | cpSpaceEachConstraintcxx . . $ cpSpaceEachConstraint(b1831c7c46e49bbc).(space, (cpSpaceConstraintIteratorFunccxx . . $ cpSpaceConstraintIteratorFunc#)cpSpaceDebugDrawConstraintcxx . . $ cpSpaceDebugDrawConstraint(f0b63336718cfb48)., options); |
| 164 | } |
| 165 | |
| 166 | if(options->flagscxx . . $ cpSpaceDebugDrawOptions#flags. & CP_SPACE_DEBUG_DRAW_COLLISION_POINTScxx . . $ CP_SPACE_DEBUG_DRAW_COLLISION_POINTS.){ |
| 167 | cpArraycxx . . $ cpArray# *arbiters = space->arbiterscxx . . $ cpSpace#arbiters.; |
| 168 | cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# color = options->collisionPointColorcxx . . $ cpSpaceDebugDrawOptions#collisionPointColor.; |
| 169 | cpSpaceDebugDrawSegmentImplcxx . . $ cpSpaceDebugDrawSegmentImpl# draw_seg = options->drawSegmentcxx . . $ cpSpaceDebugDrawOptions#drawSegment.; |
| 170 | cpDataPointercxx . . $ cpDataPointer# data = options->datacxx . . $ cpSpaceDebugDrawOptions#data.; |
| 171 | |
| 172 | for(int i=0; i<arbiters->numcxx . . $ cpArray#num.; i++){ |
| 173 | cpArbitercxx . . $ cpArbiter# *arb = (cpArbitercxx . . $ cpArbiter#*)arbiters->arrcxx . . $ cpArray#arr.[i]; |
| 174 | cpVectcxx . . $ cpVect# n = arb->ncxx . . $ cpArbiter#n.; |
| 175 | |
| 176 | for(int j=0; j<arb->countcxx . . $ cpArbiter#count.; j++){ |
| 177 | cpVectcxx . . $ cpVect# p1 = cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(arb->body_acxx . . $ cpArbiter#body_a.->pcxx . . $ cpBody#p., arb->contactscxx . . $ cpArbiter#contacts.[j].r1cxx . . $ cpContact#r1.); |
| 178 | cpVectcxx . . $ cpVect# p2 = cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(arb->body_bcxx . . $ cpArbiter#body_b.->pcxx . . $ cpBody#p., arb->contactscxx . . $ cpArbiter#contacts.[j].r2cxx . . $ cpContact#r2.); |
| 179 | |
| 180 | cpFloatcxx . . $ cpFloat# d = 2.0f; |
| 181 | cpVectcxx . . $ cpVect# a = cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(p1, cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(n, -d)); |
| 182 | cpVectcxx . . $ cpVect# b = cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(p2, cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(n, d)); |
| 183 | draw_seg(a, b, color, data); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | #endif |