collision-detection

Java Objects in Array - collision detection

前提是你 提交于 2019-12-24 11:35:51
问题 Let's say that I have code like this: private void actuallyDrawGraphics(Canvas canvas) { canvas.drawColor(Color.WHITE); for(Ball ball : balls){ canvas.drawBitmap(ballBitmap, -16 + (ball.x / 100f) * canvas.getWidth(), -16 + (ball.y / 100f) * canvas.getHeight(), paint ); } } Every ball is registered in an array. I need to make a collision (when one collides with the second) and everything goes well, until I have more balls, for example 10. It's not efficient to make a check like: ball 1 with 2,

Cannot implicitly convert 'bool' to 'int' - collision detection

落花浮王杯 提交于 2019-12-24 08:38:07
问题 I am trying to make a simple collision detection class for a soccer game. Here is the code: int Collision(int x1, int y1, int radius1, int x2, int y2, int radius2) { int dx = x2 - x1; int dy = y2 - y1; int radii = radius1 + radius2; if ((dx*dy)+(dy*dy)< radii * radii) { return true; } else { return false; } } The problem is with the code returning true or false. Visual Studio says it cannot implicitly convert bool to int, and I understand that, but how can I fix it? Thanks for any help. 回答1:

Calculate collision and area of intersection of two rotated rectangles/polygons

落爺英雄遲暮 提交于 2019-12-24 05:36:06
问题 I want to calculate collision area of two polygons (rotated rectangles). I want to calculate what area of the polyA is in the collision area (%). 回答1: turf.js (advanced geospatial analysis for browsers and node) provides turf-intersect and turf-area packages. These can be used to calculate collision and area of intersection of two polygons. In turf, rectangles (polygons) are described using features, e.g. a description of a pentagon: var polyA; polyA = { type: 'Feature', geometry: { type:

NetLogo wall collision - 'bounce' function

筅森魡賤 提交于 2019-12-24 05:15:10
问题 The NetLogo turtles keep going through the walls of the maze. How do I stop them from going through the walls and instead have them change direction? I'm grateful for any help. My code so far : breed [ defaults default ] defaults-own [ new-heading ] breed [squares1 square] breed [squares2 square] breed [squares3 square] globals [ score ] to setup-row [row colour segments] foreach segments [ if pycor = row * row-patches-width and (pxcor >= col-patches-width * (item 0 ?)) and (pxcor <= col

Collision detection in pygame

一世执手 提交于 2019-12-24 04:29:10
问题 I wrote a little test to get a feeling for collision detection in pygame. My players moves properly and stop at the rock, where the collision shall happen, but when I reach the rock I can't move away again. Do you guys know why this is the case? This is my test code: import pygame import sys white = (255, 255, 255) black = ( 0, 0, 0) # Player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.image.load('../foo.png') self.rect = self.image.get

Combining many rectangles into fewer rectangles

南笙酒味 提交于 2019-12-24 02:37:08
问题 I want to compress many non-overlapping rectangles into larger rectangles When they are adjacent. Pseudo-code for my current algorithm: do compress horizontally using sweep and prune compress horizontal output vertically using sweep and prune while (this output is small than previous output) Here's a link to sweep and prune. This is working well, but I want to know if there are approaches which result in fewer rectangles output. I figure there's more sophisticated than what I'm doing now. 回答1

Collision Detection in Box2D

喜你入骨 提交于 2019-12-24 01:25:34
问题 So I'm using Box2D for collision detection in a game. I have a tilemap that contains information on the terrain: for now it's just a char[][] that has either road or grass. Now, at the start of each level I wanted to create rectangles to describe the different terrains, but I wanted these rectangles to be optimized and apparently that takes quite an algorithm. My first approach was to create an individual terrain for EVERY tile in the map at the start of the level. The FPS was reduced to 5.

p5.js collision/object interaction. Ball bounce

末鹿安然 提交于 2019-12-24 01:09:53
问题 Following the collision between a ball from an array and an object (rectangle), the ball doesn't seem to have the same bounce affect as it has when it hits the ground. When coming into contact with the object, it seems to pick up speed and suddenly glitches through and comes to rest on the ground. Questions: Why does it seem to want to rest on the ground and not on the object itself? How can I make the ball have the same bounce affect when coming into contact with the object as it has when

WPF: Collision Detection with Rotated Squares

眉间皱痕 提交于 2019-12-23 22:24:56
问题 With reference to this programming game I am currently building. Thanks to the answers from this post, I am now able to find the x-y coordinates of all the points of the rectangles (even when rotated), and Collision-Detection with Walls is almost working perfectly now. Now I need to implement collision detection with the bots themselves (cause obviously, there will be more than one bot in the Arena). Square-Square Collision Detection (Non-rotated) is not valid in this case because the bots

Detect pixel collision/overlapping between two images

别来无恙 提交于 2019-12-23 12:38:42
问题 I have two UIImageViews that contain images with some transparent area. Is there any way to check if the non-transparent area between both images collide? Thanks. [UPDATE] So this is what I have up until now, unfortunately it still ain't working but I can't figure out why. if (!CGRectIntersectsRect(frame1, frame2)) return NO; NSLog(@"OverlapsPixelsInImage:withImage:> Images Intersect"); UIImage *img1 = imgView1.image; UIImage *img2 = imgView2.image; CGImageRef imgRef1 = [img1 CGImage];