MCPcopy Create free account
hub / github.com/axmolengine/axmol / update

Function update

tests/cpp-tests/Source/ChipmunkTestBed/demo/Query.cpp:27–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25static cpVect QUERY_START = {0, 0};
26
27static void update(cpSpace* space, double dt)
28{
29 cpSpaceStep(space, dt);
30
31 if (ChipmunkDemoRightClick)
32 {
33 QUERY_START = ChipmunkDemoMouse;
34 }
35
36 cpVect start = QUERY_START;
37 cpVect end = ChipmunkDemoMouse;
38 cpFloat radius = 10.0;
39 ChipmunkDebugDrawSegment(start, end, RGBAColor(0, 1, 0, 1));
40
41 ChipmunkDemoPrintString("Query: Dist(%f) Point(%5.2f, %5.2f),\n", cpvdist(start, end), end.x, end.y);
42
43 cpSegmentQueryInfo segInfo = {0};
44 if (cpSpaceSegmentQueryFirst(space, start, end, radius, CP_SHAPE_FILTER_ALL, &segInfo))
45 {
46 cpVect point = segInfo.point;
47 cpVect n = segInfo.normal;
48
49 // Draw blue over the occluded part of the query
50 ChipmunkDebugDrawSegment(cpvlerp(start, end, segInfo.alpha), end, RGBAColor(0, 0, 1, 1));
51
52 // Draw a little red surface normal
53 ChipmunkDebugDrawSegment(point, cpvadd(point, cpvmult(n, 16)), RGBAColor(1, 0, 0, 1));
54
55 // Draw a little red dot on the hit point.
56 ChipmunkDebugDrawDot(3, point, RGBAColor(1, 0, 0, 1));
57
58 ChipmunkDemoPrintString("Segment Query: Dist(%f) Normal(%5.2f, %5.2f)\n", segInfo.alpha * cpvdist(start, end),
59 n.x, n.y);
60 }
61 else
62 {
63 ChipmunkDemoPrintString("Segment Query (None)\n");
64 }
65
66 // Draw a fat green line over the unoccluded part of the query
67 ChipmunkDebugDrawFatSegment(start, cpvlerp(start, end, segInfo.alpha), radius, RGBAColor(0, 1, 0, 1),
68 LAColor(0, 0));
69
70 cpPointQueryInfo nearestInfo = {0};
71 cpSpacePointQueryNearest(space, ChipmunkDemoMouse, 100.0, CP_SHAPE_FILTER_ALL, &nearestInfo);
72 if (nearestInfo.shape)
73 {
74 // Draw a grey line to the closest shape.
75 ChipmunkDebugDrawDot(3, ChipmunkDemoMouse, RGBAColor(0.5, 0.5, 0.5, 1.0));
76 ChipmunkDebugDrawSegment(ChipmunkDemoMouse, nearestInfo.point, RGBAColor(0.5, 0.5, 0.5, 1.0));
77
78 // Draw a red bounding box around the shape under the mouse.
79 if (nearestInfo.distance < 0)
80 ChipmunkDebugDrawBB(cpShapeGetBB(nearestInfo.shape), RGBAColor(1, 0, 0, 1));
81 }
82}
83
84static cpSpace* init(void)

Callers

nothing calls this directly

Calls 15

cpSpaceStepFunction · 0.85
ChipmunkDebugDrawSegmentFunction · 0.85
ChipmunkDemoPrintStringFunction · 0.85
cpvdistFunction · 0.85
cpSpaceSegmentQueryFirstFunction · 0.85
cpvlerpFunction · 0.85
cpvaddFunction · 0.85
cpvmultFunction · 0.85
ChipmunkDebugDrawDotFunction · 0.85
cpSpacePointQueryNearestFunction · 0.85
ChipmunkDebugDrawBBFunction · 0.85

Tested by

no test coverage detected