Can I freeze the angle of a shape? - pymunk

Like Unitys transfrom,If you freeze the rotate,object will never rotate in its x axis.
Dose pymunk have this function?

Try setting the moment of the Body to infinity.
At creation:
mybody = pymunk.Body(mass, pymunk.inf)
or later:
mybody.moment = pymunk.inf
See http://www.pymunk.org/en/latest/pymunk.html#pymunk.inf and http://www.pymunk.org/en/latest/pymunk.html#pymunk.Body.init

Related

how do I get mouse world position. X Y plane only in unity

how do I get mouse world position. X Y plane only in unity . ScreenToWorldPosition isn't working. I think I need to cast a ray to mouse but not sure.
This is what I am using. doesnt seem to give the correct coordinates or right plane. need for targeting and raycasting.
private void Get3dMousePoint()
{
var screenPosition = Input.mousePosition;
screenPosition.z = 1;
worldPosition = mainCamera.ScreenToWorldPoint(screenPosition);
worldPosition.z = 0;
}
Just need XY coords.
I tried with ScreenToWorldPoint () and it works.
The key I think is in understanding the z coordinate of the position.
Geometrically, in 3D space we need 3 coordinates to define a point. With only 2 coordinates we have a straight line with variable z parameter. To obtain a point from that line, we must choose at what distance (i.e. set z) we want the point sought to be.
Obviously, since the camera is perspective, the coordinates you have at z = 1 are different from those at z = 100, differently from the 2D plane.
If you can figure out how far away, that is, to set the z correctly, you can find the point you want.
Just remember that the z must be greater than the minimum rendering distance of the chamber. I set that very value in the script.
Also remember that the resulting vector will have the z equal to the z position of the camera + the z value of the vector used in ScreenToWorldPoint.
void Get3dMousePoint()
{
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane));
print(worldPosition);
}
if you think my answer helped you, you can mark it as accepted and vote positively. I would very much appreciate it :)

Swift: comparing 2 object's positions in if statement not working?

Alright, so I'm trying to do something simple here and I think I've overcomplicated it- I need an if statement saying if this object goes off the screen (into negative y coordinates), have something happen. I can't get it.
I've tried a number of things, including if statements that compare to numbers like this, having it be equal and then trying greater/less than:
if block1.position.y == -50 {
savior.hidden = true
}
I've tried having the object be less than the size of the self.size.height :
if block1.position.y < self.size.height {
savior.hidden = true
}
And I've tried placing an object at the point off the screen and having an if statement comparing the 2 object's y positions:
if block1.position.y == ptBlock1.position.y {
savior.hidden = true
}
And nothing's working. Block1, the object I'm working with, is being sent to the specific point in an SKAction, so I know that it's getting there:
var moveDownLeft = SKAction.moveTo(CGPointMake(self.size.width * 0.35,-50), duration:5.5)
block1.runAction(moveDownLeft)
Why won't the if statement work?
EDIT:
I have tried this, and even when block1 visibly has a y position lower than ptBlock1, nothing happens:
if block1.position.y < ptBlock1.position.y {
savior.hidden = true
}
else if block1.position.y > ptBlock1.position.y {
savior.hidden = false
}
this object goes off the screen (into negative y coordinates)
You're making a false assumption there. Off the screen is not necessarily negative y coordinates.
The position of an SKNode is not measured with respect to screen; it is measured with respect to its superview, which is the SKScene. And the SKScene is much bigger than the screen! You need to convert from those coordinates to screen coordinates if you want to know what's happening relative to the screen.
(Just to give an example, if you make a new SpriteKit project from the template and log on touchesBegan to show the tap position, you will discover that a tap in the top left corner is at about {303,758}. So in that coordinate system an object is off the screen to the top if its y is greater than about 760. Contrast that with screen coordinates, where you are off the screen to the top if you are less than 0. These are very different coordinate systems!)

Amplitude of graph clips when magnified

This is the code for plotting I am using
figure
x = -pi:pi/40:pi;
plot(x,cos(5*x),'-ro',x,sin(5*x),'-.b')
hleg1 = legend('cos_x','sin_x');
The output comes like this:
When I try to stretch the time axis, what I get is like this:
But as can be seen, the amplitude gets clipped when I stretch the time axis. How do I avoid this clipping of amplitude when stretching time axis and v.V?
You can try using "Zoom In," the plus-magnifying glass icon and being very careful to select the entire vertical range of the image. To control the minimum and maximum values of the axes more precisely using the axis function.
figure
x = -pi:pi/40:pi;
plot(x,cos(5*x),'-ro',x,sin(5*x),'-.b')
hleg1 = legend('cos_x','sin_x');
axis([1.6, 3.2,-1, 1])

Rotating UILabels from any position to upright

I have a label that I rotate using
pieceBlack.transform = CGAffineTransformMakeRotation((M_PI * (180) / 180.0));
and that works perfectly, EXCEPT:
I rotate this label during the game to either right side up or upside down. How do I say, "Whatever angle you are at, go back to upright." I'm thinking maybe like an:
int PreviousAngle = ?;
pieceBlack.transform = CGAffineTransformMakeRotation(degreesToRadian(0-PreviousAngle));
so I guess what I'm asking is how you ask for the rotation angle. Or, alternately, maybe there is a sort of
pieceBlack.transform = CGAffineTransformMakeRotation(RotateToUpright);
From what I remember transform is always relative from the upright position (original), so 0.0f? So you can just do pieceBlack.transform = CGAffineTransformIdentity
What I did was to first position the (in my case) view in the "straight up" orientation. Then I used the CGAffineTransformMakeRotation to create the somewhat off-kilter view. Finally, I applied the identity transform to bring the view back to its straight-up position.
you don't want to set the transform, you want to modify it,
view.transform = CGAffineTransformRotate(view.transform, angle);
if you need to keep the old one around, then do

Frame by frame animation using an NSTimer following a circular path

I'm using an NSTimer to animate an array of objects across the screen. Currently they move from left to right. However, I would like them to move in a circular fashion instead. How can I do this?
scrollItems = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0
target:self
selector:#selector(scrollItems)
userInfo:nil
repeats:YES];
- (void)scrollItems {
for (UIImageView *anItem in itemsArray) {
CGRect oldFrame = anItem.frame;
anItem.frame = CGRectMake(oldFrame.origin.x+5, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
}
}
When I say circular fashion, I mean as if they were following the circumference of a circle. Thanks!
Basically the same way -- think you need to bust out the trigonometry.
http://en.wikipedia.org/wiki/Trigonometry
Right now you're just adding five to x to make it move. Instead you need to calculate a new x AND y based on sin cos and crap like that and some sort of counter to tell it where on the circle it should be.
Update: The unit circle might help too.
So at any time on the clock your object should be at some point on this circle, correct? So you have to go from time -> angle -> x & y coordinate on the circle. Working backwards, you can get an x y coordinate on the circle if you have an angle (a number between 0 and 360 degrees) -- that's the unit circle link.
So you need an angle. That angle will be a function of time, right? So at time 0 you could say that's an angle of 0, and then you know where on the circle you should be based on the formulas in the above links. At time 1, it could be an angle of 1, etc. Keep doing that over time and you're drawing a circle. You just need to figure out how to translate time into a number between 0-360. That function will determine the speed at which your object moves.
So basically you need something that can use time to calculate an x y. After that's working you could get clever and have that function also take in speed, center, and radius and return an x y based on those things. Up to you.
Sorry I don't have time to write this code, but it should be pretty do-able.