Rotate a small wheel using magnets - physics

I know this question already asked so much times.
I tried to rotate a wheel by placing few magnets on it. And I used some powerful magnet and repel it using opposite poles in the magnets placed in a wheel.
Thing is I got rotation for a while upto next magnet in the wheel. Only issue I get is the first magnet repels and make some movement in the wheel. When second magnet coming, it doesn't enter the repelling magnet position. Any idea to overcome this?

As the second magnet approaches the repelling magnet, move the repelling magnet away. When the second magnet reaches the original position of the first magnet, move the repelling magnet back into position, so as to push the second magnet on its way.
If you try to move the wheel without moving the repelling magnet, you may discover an important principle of physics.

Related

Processing camera frustum() and perspective() rotations

How can I make a camera that I can move around and rotate around its own axis in processing 2+?
I have a camera that I can move around in the world space and have some kind of rotation:
frustum(-10,10,-10,10,10,2000);
translate(camX,camY,camZ);//I move around by adding to these values when a button is pressed
rotate(angleX,1,0,0);//same here...
rotate(angleY,0,1,0);
rotate(angleZ,0,0,1);
Bu the problem with this is that the rotation is centered in the scene, meaning that I get very strange rotations when moving further away from the scene's center coordinates. Why does that happen when I have translated before rotating?
Thanks to Nicolás Carlo and his suggestion to watch This Youtube playlist made by Jorge Rodriguez I was able to fix what I almost made right the first time.
All I had to do was really just to do some simple trigonometric calculations to get the forward-vector from the angles I got, and then just add the camera position to that for the centerX,centerY,centerZ values in camera();
Ex. where camPos is the current position 3D-Vector and vecForward is the calculated 3D-forward vector that I needed.
vecForward.x = cos(yaw)*cos(pitch);
vecForward.y = sin(pitch);
vecForward.z = sin(yaw)*cos(pitch);
camera(camPos.x,camPos.y,camPos.z, camPos.x+vecForward.x,camPos.y+vecForward.y,camPos.z+vecForward.z, 0,1,0);
If some of you do not know, Pitch is the up-down angle and Yaw is left-right angle of the camera.
And as a last note here,I highly suggest watching Rodriguez "Math for game developers" that Carlo suggested since every video explains at least one of the most important/oftenly used mathematical solutions at a time to different problems and then giving an example in the end.

How to move the sprite with the movement of background?

I am working on a tilemap based game in cocos2d in which the player moves in four directions and I have used four images for the movement of player for example left,right,top and down. My problem is that when my background map change its position or move to other position then my sprite does not change its position. Can anyone tell me how to move a sprite with the movement of background.
Use a CCNode to contain both the background and the sprites for your players. Instead of moving the background, move that node.
There are a couple of ways to handle tilemap based games, and neither of them are very convenient. One way is to leave your character in the center of the screen at all times and move the background underneath it. If your character moves 'right', you simply slide the background to the left, and vice versa. This will give the illusion that the character moves around the map, when in reality it remains centered. Under this paradigm you must remember to convert all detection / collisions into the world's space, and not just the screen space. If you don't convert everything, then your 'range' of collision / detection is limited to the size of the screen.
The second method is to pan the camera over the world. You still keep the character in the middle of the screen, but it actually moves around in the world, and the camera follows. This makes the most intuitive sense to me because it allows you to view the game world as you see the real world. It is also much easier to deal with collisions because the position of the character and the world 'just work' and don't have to be converted. The downside here is that Cocos2D doesn't make it easy to use CCCamera, and the documentation is a little thin in that respect.
In your particular case, it sounds like you have a CCLayer problem. If your character is inside the layer you are moving, it will indeed remain in the same place relative to the map (as you are describing). Instead, float the character in a different layer on top of the map.
You could use a scrolling Parallex and then add the sprite onto the same layer as the background. They will move together.

Is there a simplistic method of getting kinect sensor to recognise swipes

I'm not the best programmer and I'm trying to adapt the skeletal tracking project available from channel 9 but I have no idea how to do so. I've also looked at kinect toolbox but it seems overly complicated. I'm trying to create an application that allows the user to make a left swipe and it uses a defined keybind such as ctrl+b when its detected.
Can anyone help or does anyone have any advice?
Kind Regards,
Aislinn
you can create a simple algorithm.
Swipe is a move form point A to B. You just need to know when the hand is in point A. If it is there start tracking the history of moves and compare to samo pattern. For example pattern can be a horizontal move from A to B where hand shouldn`t go up or down just to the side. So check if in every frame is going straight to the side. If it goes to much up or down you cancel the move and do nothing.
Comparing to pattern is simple math. You just check position X and Y: X for move to the side and Y for the move up and down.
Hope it helps :)

Objective-C draw a path and detect when it closes (forms a closed shape)

I'm fairly new to game programming (but not to programming) and I want to create a space ship which leaves a trail on the screen. Now my problem is to come up with a solution how to detect if the trail left from the ship forms a closed shape - eg. if the ship left a trail around an object, the object is caught inside its trail so to speak.
The direction I'm thinking is to draw the path of the trail on an image not visible on the screen and every now and then try to fill it with certain color and then check if fill is caught within the trail path. However it seems like a lot of overhead.
Any ideas how to do that? I'm using cocos2d if that's of any help
In game programming you often need to think more mathematically than visually.
First does your ship continuously leaves a trail on the screen? If yes, then it will be easier to know when the shape closes : you just have to remember the coordinate where your ship started to leave a trail, then wait for the trail to approach this coordinate another time (for example within a radius of 10 pixels, or else the user will need to be really accurate to hit exactly the same pixel to close the shape).
The visual representation of the trail is only here for the user, you'll never use it to compute anything. What you will do is to keep in memory the path followed by the ship's trail : a polygon, which is nothing else than the list of coordinates it followed.
Then after you know that your shape is closed, you have to determine if an object is inside your polygon or not. It's possible that objective-c or cocos2d (I don't know much about it) already contains a built-in function to know if a point is inside a polygon. In java there is the Polygon class which makes this really easy. If you don't find anything you can do it yourself, there are already great answers about this subject on SO, here is a nice one : How can I determine whether a 2D Point is within a Polygon?

Finding significant images in a set of surveillance camera images

I've had theft problems outside my house so I setup a simple webcam to capture every second with Dorgem (http://dorgem.sf.net).
Dorgem does offer a feature to use motion detection to only capture frames where something is moving on the screen. The problem is that the motion detection algorithm it uses is extremely sensitive. It goes off because of variations in color between successive shots on my cheap webcam, and it also goes off because the trees in front of the house are blowing in the wind. Additionally, the front of my house is a high traffic area so there is also a large number of legitimately captured frames.
I average capturing 2800/3600 frames every second using Dorgem's motion detection. This is too much for me to search through to find out where the interesting activity is.
I wish I could re-position the camera to a more optimal position where it would only capture the areas I'm interested in, so that motion detection would be simpler, however this is not an option for me.
I think that because my camera has a fixed position and each picture frames the same area in front of my house, then I should be able to scan the images and figure out which ones have motion in some interesting region of that image, throwing out all other frames.
For example: if there's a change in pixel 320,240 then someone has stepped in front of my house and I want to see that frame, but if there's a change in pixel 1,1 then its just the trees blowing in the wind and the frame can be discarded.
I've looked at pdiff, a tool for finding diffs in sets of pictures, but it seems to be also focused on diffing the entire picture, rather than a specific region of it:
http://pdiff.sourceforge.net/
I've also looked at phash, a tool for calculating a hash based on human perception of an image, but it seems too complex:
http://www.phash.org/
I suppose I could implement it in a shell script using imagemagick's mogrify -crop to cherry pick the regions of the image I'm interested in, then running pdiff to find the interesting ones, and using that to pick out the interesting frames.
Any thoughts? ideas? existing tools?
cropping and then using pdiff seems like the best choice to me.