kopia lustrzana https://github.com/backface/turtlestitch
alternative collision detection method using the video-cache
no noticable speed-up, commented out for reference.pull/95/head
rodzic
12629d64ec
commit
32b57bdf6b
|
@ -19,6 +19,9 @@
|
|||
* Spanish, thanks, Joan!
|
||||
* Catalan, thanks, Joan!
|
||||
|
||||
### 2020-12-05
|
||||
* objects: alternative collision detection method using the video-cache, commented out for reference.
|
||||
|
||||
### 2020-12-04
|
||||
* threads: refactored raycasting
|
||||
* integrated raycasting into "relation TO object" primitive
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<script src="src/widgets.js?version=2020-10-06"></script>
|
||||
<script src="src/blocks.js?version=2020-12-04"></script>
|
||||
<script src="src/threads.js?version=2020-12-04"></script>
|
||||
<script src="src/objects.js?version=2020-12-04"></script>
|
||||
<script src="src/objects.js?version=2020-12-05"></script>
|
||||
<script src="src/gui.js?version=2020-12-01"></script>
|
||||
<script src="src/paint.js?version=2020-05-17"></script>
|
||||
<script src="src/lists.js?version=2020-12-01"></script>
|
||||
|
|
|
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph,
|
|||
localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph,
|
||||
AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/
|
||||
|
||||
modules.objects = '2020-December-04';
|
||||
modules.objects = '2020-December-05';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -4354,6 +4354,56 @@ SpriteMorph.prototype.goBack = function (layers) {
|
|||
|
||||
// SpriteMorph collision detection
|
||||
|
||||
// attempted optimized collision detection using video buffer
|
||||
// turns out it's actually slower to partially enumerate 2 sets of pixels
|
||||
// than to create a new masked canvas.
|
||||
// commented out and kept for reference
|
||||
|
||||
/*
|
||||
SpriteMorph.prototype.isTouching = function (other) {
|
||||
var stage = this.parentThatIsA(StageMorph),
|
||||
inter, off, src, trg, sw, tw, x, y;
|
||||
|
||||
function isOpaque(imageData, width, x, y) {
|
||||
return (imageData[y * width + x] && 0x000000FF) > 0; // alpha
|
||||
}
|
||||
|
||||
if (!(other instanceof SpriteMorph)) {
|
||||
return SpriteMorph.uber.isTouching.call(this, other);
|
||||
}
|
||||
|
||||
// determine the intersection of both bounding boxes
|
||||
// unscaled and translated to local coordinates
|
||||
|
||||
inter = this.bounds.intersect(other.bounds).translateBy(
|
||||
this.position().neg()
|
||||
).scaleBy(1 / stage.scale); // .floor(); ?
|
||||
|
||||
if (inter.width() < 1 || inter.height() < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
off = this.position().subtract(
|
||||
other.position()
|
||||
).scaleBy(1 / stage.scale).floor();
|
||||
|
||||
src = this.getImageData();
|
||||
sw = Math.floor(this.width() / stage.scale);
|
||||
trg = other.getImageData();
|
||||
tw = Math.floor(other.width() / stage.scale);
|
||||
|
||||
for (y = inter.origin.y; y <= inter.corner.y; y += 1) {
|
||||
for (x = inter.origin.x; x <= inter.corner.x; x += 1) {
|
||||
if (isOpaque(src, sw, x, y) &&
|
||||
isOpaque(trg, tw, x + off.x, y + off.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
*/
|
||||
|
||||
SpriteMorph.prototype.reportTouchingColor = function (aColor) {
|
||||
var stage = this.parentThatIsA(StageMorph),
|
||||
data, len, i;
|
||||
|
|
Ładowanie…
Reference in New Issue