What would be a good variable name for a rectangle the describes an objects position and size? - variable-names

The title is fairly self-explanatory, but I'll reiterate: What would be a good variable name for a rectangle that describes an objects position and size.
EDIT - The object is a paddle for a Pong-like game, and there is already a rectangle named 'bounds' to restrict where the paddle can be moved to.
I ended up going with 'bounds' for the paddles position and size, and 'movableArea' to restricted where the paddle can be moved.

If it's a paddle, then why not paddleBound? That's not rocket science, it describes the object and its property and should be enough to distinguish it from anything else, except maybe the other paddle (then you can just use paddel1Bound or userPaddleBound for further distinction).

Given the context of your question, why not Paddle?

BoundingBox might be good.

How about boundingBox or boundsRect?

Apple's Cocoa framework uses frame and bounds (with slightly different meanings) for this kind of variable. I've always found them to be good. If you need just one, I vote for frame.

Well, if the variable is of type Foo I would choose
fooRectangle
Or something similar to that. It also depends on the language and what the conventions are and perhaps the context.

I prefer short. How about xyBox?

How about perimeter?

what about this ?
Rectangle nextBounds; // bounds where the paddle can be moved to
Rectangle bounds; // current bounds

Related

Unreal Engine 4 - Any suggestions on how I can I prevent my actor from "flying" by standing on top of an object while lifting it?

I have a code that changes the position of an object when grabbed to 100 units in front of the camera, this allows the player to stand on top of an object and pick it up causing him to fly towards wherever the camera is pointing.
Example: In this picture, I stood on top of a movable red rock. While on top I picked it up and moved my camera upwards which caused the rock to move to that position while carrying the actor. Because of this, I can quickly move to anywhere on the map by standing on top of an object and picking it up.
The skeletal mesh is unrelated to the grab function and the range of the grab is set to keep movable objects close to the skeletal mesh (like lifting this pebble) if that helps.
Any suggestions on how to fix this issue? Thanks in advance!
Assuming that your objects have some sort of toggle-able state that determines whether they can be picked up or not. One solution to the problem you are facing would be to cast a ray from the bottom of the player and if that ray hits an object that can be picked up, temporarily disable the ability to pick the object up. This introduces a new problem of stacking up two objects and moving the bottom object however. Alternatively you could also change objects so that when you are holding them, the collider is disabled on the object. There are many more ways you could go about solving this issue, but without knowing in detail what you are trying to accomplish by holding objects, it would be hard for anyone but yourself to choose the appropriate solution.

Having problems understanding body positioning in Box2d. Any pointers on how things work?

I'm struggling to learn and understand box2d. Here is my problem:
I'm trying to make a simple car, the car body looks like this for now:
Now I'm trying to add a wheel, I create the wheel body and I assume I'll link the wheel to the car body using a b2RevolutionJoint.
Until I get to that part I just want to be able to position the wheel in its place, so in relation to the bodyCar Body. How do I do this correctly?
What I've seen online is something like this:
bodyDef2.position.Set(axle2->GetWorldCenter().x + 1.3*cos(-M_PI/3), axle2->GetWorldCenter().y + 0.3*sin(-M_PI/3));
However, I don't understand the cos and sin parts of that expression.
What I'm trying to do is this:
backWheelDef.position = b2Vec2(carBody->GetWorldCenter().x - 20.0/PTM_RATIO,carBody->GetWorldCenter().y);
Since my carBody vertices definition looks like this:
b2Vec2 vertices[] = {
b2Vec2(100.0/PTM_RATIO,15.0/PTM_RATIO),
b2Vec2(100.0/PTM_RATIO,30.0/PTM_RATIO),
b2Vec2(50.0/PTM_RATIO,65.0/PTM_RATIO),
b2Vec2(20.0/PTM_RATIO,65.0/PTM_RATIO),
b2Vec2(0.0/PTM_RATIO,45.0/PTM_RATIO),
b2Vec2(0.0/PTM_RATIO,15.0/PTM_RATIO)
};
The result of the above way of positioning the wheel looks somehow correct (see below screenshot) but if you look at the above numbers it doesn't make much sense.
Since the carBody width is 100.0/PTM_RATIO I assume the GetWorldCenter().x would return a value equal to 50.0/PTM_RATIO.
So the wheel position would be after calculation at 30.0/PTM_RATIO, right?
Well, if you look at the result below the wheel x positioning seems to be at 20.0/PTM_RATIO.
Can someone please explain how things work with positioning bodies in relation to other bodies works in Box2D? Once I'm clear with these kind of things I'll move on to linking them using joints
Thanks a bunch!
LATER EDIT BASED ON iforce2d ANSWER:
Thank you iforce2d for answering and thank you for all the good insight you provide in the box2d world. What you're saying is perfectly true but this wasn't my question.
Once I've figured out that GetWorldCenter returns the center of gravity and GetPosition returns the position origin of the object it was easy to place my wheel exactly where I needed it to be in relationship to the carBody. Even though I still got the behaviour of it appearing under the body I knew this would be fixed once I add joints into equation.
Now I have another question that somehow relates to this positioning problem. Take a look at the image below:
Is this the right way my joints should look once I set their anchor points as below? I'm a little confused by them going from origin instead of them going from anchorPointA to anchorPointB
Thanks again!
You are placing the wheel inside the car body to begin with, so in the first two or three time steps the two bodies will move to correct the overlap. It probably happens so fast that you don't see it, but the tell-tale signs are there, namely the wheel being positioned exactly at the edge of the car, and the car body being rotated a tiny bit.
If you pause the simulation (just don't call Step) you should see the bodies where you expect to see them.
Once you add the joint, the default behavior is for the two joined bodies not to collide with each other, so you wont see this problem.

Look from a moving camera to a fix point opengl

My camera is place on a moving object, but it always be pointed to a point in scene. How can I do that? How can I calculate the perpendiculars? How, if the position of the observator always moves, the direction stay focused on that point?
My camera is place on a moving object, but it always be pointed to a point in scene. How can I do that? How, if the position of the observator [sic] always moves, the direction stay focused on that point?
gluLookAt().
How can I calculate the perpendiculars?
Cross-product.
Which version of OpenGL are you using. This depends a lot on which environment you are working on. If you are in OpenGL ES you need to do it yourself, otherwise you can achieve the wanted result by playing with glLookat. Let us know.

Cocos2d Joystick

I have been looking all over for help on how to make a CCSprite move and rotate with the movement of a virtual joystick. I have tried examples and sample code, but, none have worked for me. If someone could tell me how to implement a joystick into the HelloWorld layer, that would be wonderful. P.S. The joystick does not need to move the sprite with variable velocity, it just needs to move it in a direction at a constant speed.
Thanks in advance.
First of all, this is a poorly worded question. Normally I would vote you down for this but for some reason I am not going to today.
You say there is no need for variable velocity, but it needs to move in a direction at a constant speed. I assume then that you need a full 360 degree range. What you do is have a joypad sprite on your layer. When you touch the sprite you calculate the angle of the touch (ignoring distance from center since you don't care about variable velocity). Convert the angle to a CGPoint ( ccpForAngle(CGFloat) is helpful for that ) and then use ccpMult(CGPoint, CGFloat) to decide how fast to move your sprite. Then you can use CCMoveBy to move your sprite.
That's one way of doing it at least.

How to make a moving object "stick" to a stationary object in box2D

I have been experimenting with the box2D sample project within cocos2D for the iPhone and am wondering if box2D is the appropriate engine to use to make a moving object "stick" to a stationary object when the moving object is finished moving in a certain direction.
Here is a simplification of what I am trying to achieve: I have MovingObject, a dynamic rigid body, that moves vertically against gravity when enough force is applied to it. As MovingObject moves, it may overlap a static object, StationaryObject. When gravity diminishes MovingObject's velocity to zero such that it is no longer moving, I would like to have MovingObject remain where it is ONLY if it overlaps StationaryObject. If the object's do not overlap, MovingObject should start to move back down towards the ground per the force of gravity. During that descent, if MovingObject at any time overlaps StationaryObject, it should stop its descent and remain in that location as if it is stuck on StationaryObject.
I am able to get MovingObject to move per the forces I am applying to it, but not really sure how to make it stop and stay there once it reaches the top of its ascent, assuming it is overlapping StationaryObject.
Currently, I am experimenting with simple square/box objects but eventually both MovingObject StationaryObject will be defined as very different complex polygon shapes.
Thanks in advance for any insights and/or suggestions for achieving this.
Sounds like you'll want to change the type of fixture used for "MovingObject" while it "ascending" and then change it when it is "descending" so that it reacts differently (to overlaps).
by "overlap" it sounds like you want to achieve something similar to "one sided platforms" in a platform game (ie; Mario Bros.) - I would recommend looking into the solutions for one-sided platforms for starters.