game-physics

Quadtree for 2D collision detection

一世执手 提交于 2019-11-27 03:03:43
I'm trying to use a quadtree for 2D collision detection, but I'm a little stumped on how to implement it. First of all, I'd have a quadtree which contains four subtrees (one representing each quadrant), as well as a collection of objects which don't fit into a single subtree. When checking an object for collisions in the tree, I would do something like this (thanks to QuadTree for 2D collision detection ): Check the object for collisions with any objects in the current node. For any subtree whose space overlaps the object, recurse. To find all collisions within a quadtree tree: Check each

Pygame: key.get_pressed() does not coincide with the event queue

。_饼干妹妹 提交于 2019-11-27 02:16:09
I'm attempting to work out simple controls for an application using pygame in Python. I have got the basics working, but I'm hitting a weird wall: I am using the arrow keys to control my character. If I hold down one arrow key, then hold down another arrow key (to move diagonally), the character moves as expected. However, if I release the second key that I pressed (while still holding down the first key), the character stops moving, even though I am still holding down that first key. Here is my simple movement code: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys

SpriteKit's SKPhysicsBody with polygon helper tool

好久不见. 提交于 2019-11-26 23:53:47
I wonder if there is a tool that could be used for easy generation of complex physics bodies in SpriteKit. I would like to have a volume based physical bodies with polygon-type shapes. SpriteKit allows to create such bodies with that method: + (SKPhysicsBody *)bodyWithPolygonFromPath:(CGPathRef)path Unfortunately it's time consuming task to generate such paths manually, and it could be problematic when testing. There is a SpriteHelper application that allows you to define body shape within easy-to-use visual editor, but this app can't export paths that could be used here. It was made for

Wanted to make an object bounce inside a circle, ended up making the object move along the rim of the circle

拟墨画扇 提交于 2019-11-26 23:47:50
问题 Here's the code in question: public void calculate() { // Center of circle is at (250, 250). //THIS ALGORITHM IS NOW PROVEN TO BE WORSE THAN I FEARED... /* What it does: * Moves object around in a circle. * Does not move the object towards the center. * Object always stays on the rim of the circle. * * Algorithm I used. (DOES NOT WORK): * N is normalized vector. * R = -2*(V dot N)*N + V */ vx += Accelero.X * 0.1; vy += Accelero.Y * 0.1; double nx = x - 250; double ny = y - 250; double nd =

Transforms are added…endlessly

北战南征 提交于 2019-11-26 21:55:58
问题 I'm creating a simple asteroids-like game in CSS and JS using the DOM over canvas for...experimentation purposes. My code is pretty small in this example to make it easy to see what's going on below. The ultimate goal: Let arrow keys smoothly rotate and translate the spaceship around the window without creating an infinite amount of transforms. I think I'm 90% there : Use the arrow keys to control the snippet below. 'use strict'; function defineDistances() { var distance = {}; distance.up =

How to convert Euler angles to directional vector?

不想你离开。 提交于 2019-11-26 21:36:46
I have pitch, roll, and yaw angles. How would I convert these to a directional vector? It'd be especially cool if you can show me a quaternion and/or matrix representation of this! Unfortunately there are different conventions on how to define these things (and roll, pitch, yaw are not quite the same as Euler angles), so you'll have to be careful. If we define pitch=0 as horizontal (z=0) and yaw as counter-clockwise from the x axis, then the direction vector will be x = cos(yaw)*cos(pitch) y = sin(yaw)*cos(pitch) z = sin(pitch) Note that I haven't used roll; this is direction unit vector, it

How to fix circle and rectangle overlap in collision response?

早过忘川 提交于 2019-11-26 19:26:04
问题 Since in the digital world a real collision almost never happens, we will always have a situation where the "colliding" circle overlaps the rectangle. How to put back the circle in the situation where it collides perfectly with the rectangle without overlap? Suppose that the rectangle is stopped (null velocity) and axis-aligned. I would solve this problem with a posteriori approach (in two dimensions). In short I have to solve this equation for t : Where: is a number that answers to the

iOS 7 Sprite Kit freeing up memory

爱⌒轻易说出口 提交于 2019-11-26 17:38:31
I am building an iOS game aimed for the new iOS 7 and Sprite Kit, using emitter nodes and physics to enhance gameplay. While developing the app, I ran into a serious problem: you create your scenes, nodes, effects, but when you are done and need to return to the main screen, how do you free up all the memory allocated by these resources? Ideally ARC should free up everything and the application should get back to the memory consumption level it had before creating the scene, but this is not what happens. I've added the following code, as the dealloc method of the view, which draws the scene

Why transforming normals with the transpose of the inverse of the modelview matrix?

我与影子孤独终老i 提交于 2019-11-26 17:15:02
I am working on some shaders, and I need to transform normals. I read in few tutorials the way you transform normals is you multiply them with the transpose of the inverse of the modelview matrix . But I can't find explanation of why is that so, and what is the logic behind that? Invalid Take a look at this tutorial: https://paroj.github.io/gltut/Illumination/Tut09%20Normal%20Transformation.html You can imagine that when the surface of a sphere stretches (so the sphere is scaled along one axis or something similar) the normals of that surface will all 'bend' towards each other. It turns out

Path generation for non-intersecting disc movement on a plane

南笙酒味 提交于 2019-11-26 16:55:00
问题 What I'm looking for I have 300 or fewer discs of equal radius on a plane. At time 0 each disc is at a position. At time 1 each disc is at a potentially different position. I'm looking to generate a 2D path for each disc for times between 0 and 1 such that the discs do not intersect and the paths are relatively efficient (short) and of low curvature if possible. (for example, straight lines are preferable to squiggly lines) Lower computation time is generally more important than exactness of