Saturday, March 26, 2016

present perfect - When to use "verb + ed" not for the past but for the future?


I get always confused with the possibility to use verb + ed for the future. The text I'm writing brings the same problem and I'm not sure if I do a mistake if I write:



"Once we receive and review it, we will confirm your order by e-mail."




rather than



"Once we received and reviewed it, we will confirm your order by e-mail."



Which one is correct - can anyone please explain me the rule of how to use verb+ed in this case?



Answer



Your first version is acceptable, but the second is not.


I think what may be confusing you is the fact that regular verbs in English use the -ed form for two different entities:





  • The simple past tense ...



    We received your order yesterday.





  • The past participle, which is used with the auxiliary have in perfect constructions:



    We have received your order and will ship today.






In the sentence you are trying to write, the subordinate clause beginning once is related to the main clause we will confirm..., but it is not expressed with a future construction because it is an event which much occur before the action of the main clause. Consequently you may use either the simple present tense, as in your first example, or a present perfect construction:



Once we have received and reviewed it, we will confirm your order by e-mail.



pronouns - When to use "Me" and "I" in comparative sentences?



He is taller than me/I?



Also, what is the difference between the two:




1 - I love you better than him.


2 - I love you better than he.




Answer



Use the form that would make sense in the first part of the sentence. You would use "I am taller", not "Me am taller", so



He is taller than I [am tall].



In the second case, the distinction is




I love you better than [I love] him.



(That is, you are saying who you love better.)


vs



I love you better than he [loves you].



(You are saying who loves the listener better.)


word order - How can I say it? "the questions whose answers I don't know" or "the questions that I don't know their answers"?



This may be silly question, looks like the first option is obvious but when I was writing some time ago I couldn't figure out until I wrote it here. Still, I wanted to ask you to learn shortest and best way of articulation.



the questions whose answers I don't know


the questions that I don't know their answers




Answer



The question posits only two possible formations of this phrase:




  • The questions whose answers I don't know


  • The questions that I don't know their answers



Of these, the second is ungrammatical. The first is acceptable, although many English speakers intuitively feel that "something is wrong" about using whose to refer to things instead of beings (in spite of the fact that Shakespeare himself did so in ~1600CE!)


This usage can be avoided by (as noted in another answer) using the pronoun which instead...




  • The questions to which I do not know the answers




This may be preferable in formal writing. However, in idiomatic English, the most common form is...




  • The questions [that] I don't know the answers to



Friday, March 25, 2016

c++ - Implementing a camera / viewport to a 2D game


What is the most practical way to implement camera/viewport to a 2D-game?



I've read, that I should store the object world position instead of position relative to the screen?


Current situation:


I have implemented a simple 2D-game where I load objects and levels from XML-files. Currently the level XML-file looks like this:






...



All objects have a 2d-vector "position" storing their current location on the screen.


What I want it to be:


Viewport/gameworld illustration


In the picture:



  • Camera is either 800x600 or 640x480

  • Blocks and sprites are 16x16 pixels.

  • World size may vary

  • The coordinates probably should be normalized relative to the world, not to the screen?

  • Viewport position relative to player's x, y and moves when the player reaches camera dead zone (similar to this video).



I'm asking pseudo examples / articles, but if you need to know what I'm using for the development: SDL & C/C++.



Answer



You need to have every object positioned relative to the world instead of the screen. Your camera should also have its own world coordinates so it can be drawn at a relative position in the world. It may also be convenient to have your camera follow an object, so wherever the object is, the camera just uses its coordinates. Typically the camera's coordinates will position it from the upper left corner. This means the camera would have a world position of approximately (0,24) in the picture.


As for actually drawing the objects the camera can "see", you must draw all objects relative to the camera's world coordinates. To compute an object's screen position relative to the camera, simply do:


int screenX, screenY; //screen position of the object being drawn

screenX = object.x-camera.x;
screenY = object.y-camera.y;


Obviously some objects are not actually visible to the camera, so you may want to implement a view culling system.


lwjgl - Java JBullet Mesh collsion problem


I have a problem with JBullet mesh collsion. Everything works fine when I create a mesh from my object without scaling, but the problem starts when I want to scale the object. I also tried scaling in Blender, but it has the same problem. Here is my code for creating a mesh from an object:


    int numtriangles = mesh.vertices.length / 3;
int numverts = mesh.vertices.length;

ByteBuffer indexBuffer = BufferUtils.createByteBuffer(numverts * 3 * 4).order(ByteOrder.nativeOrder());

indexBuffer.clear();
for(int i=0;i indexBuffer.putInt(i);
indexBuffer.putInt(i);
indexBuffer.putInt(i);
}

ByteBuffer geometry = BufferUtils.createByteBuffer(numtriangles * 3 * 4).order(ByteOrder.nativeOrder());
geometry.clear();
for(int i=0;i
geometry.putFloat(mesh.vertices[i].getPos().x);
geometry.putFloat(mesh.vertices[i].getPos().y);
geometry.putFloat(mesh.vertices[i].getPos().z);
}

geometry.rewind();
indexBuffer.rewind();

TriangleIndexVertexArray trimesh = new TriangleIndexVertexArray(numtriangles, indexBuffer, 3 * 4, numtriangles, geometry, 3 * 4);
BvhTriangleMeshShape shape = new BvhTriangleMeshShape(trimesh,true);

return shape;

My scaling was something like this:


    for(int i = 0; i < vertices.length; i++) {
Vertex acc = vertices[i];

Vector3 pos = acc.getPos();
pos.x *= scale.x;
pos.y *= scale.y;
pos.z *= scale.z;

acc.setPos(pos);

Vector2 tex_coord = acc.getTexCords();
tex_coord.x *= scale.x;
tex_coord.y *= scale.z;
acc.setTexCords(tex_coord);

vertices[i] = acc;
}


The problem is when I scale the object, it no longer collides with other objects.



Answer



The scaling looks fine, but the calculation of indices doesn't look correct. I think it just happens to somewhat work by accident when the objects are small enough. This code:


for(int i=0;i   indexBuffer.putInt(i);
indexBuffer.putInt(i);
indexBuffer.putInt(i);
}

adds the same vertex index three times for the triangle meaning that only the first 1/3 of the vertices are referenced. As you are not sharing vertices between triangles, perhaps the code should be:



for(int i=0;i   indexBuffer.putInt(i);
}

Note that you probably don't want to scale the texture coordinates, although that doesn't matter for physics. Also the scaling code redundantly assigns the modified vertex back to the array even though in Java the variable is just a reference and you are modifying the original data. This should be enough:


for(int i = 0; i < vertices.length; i++) {
Vertex acc = vertices[i];

Vector3 pos = acc.getPos();
pos.x *= scale.x;

pos.y *= scale.y;
pos.z *= scale.z;
//acc.setPos(pos); // This is not needed either if getPos() doesn't create a copy. Most likely it doesn't.
}

word request - What is the place in the office people grab coffee and snack?


It is not necessarily a room but can be small area in the office, has a coffee maker, fridge, microwave, sink and cabinets holding seasoning, paper towels and utensils. Sometimes there is a vender machine too.


is it a pantry?



Answer



There is no single term; depending on the organization, the facility, and the primary use, that area may be the




  • break room (US) or restroom (UK) - a place, as you note, where one might go for a coffee break (and in olden days, perhaps a smoke break)

  • lunchroom - a break room with sufficient tables/counters and seating for people to eat lunch in, but can also refer to any place people take lunch, which might be a cafeteria or dining room (see below)

  • pantry - sometimes synonymous with the above, especially if on the smaller end of room sizes. But pantry has many different uses, and is more generally a storage area for dry goods attached to a kitchen or dining area (ranging in size from a particular cabinet to a walk-in closet).

  • canteen or mess - probably adopted from the military terms for a small facility with food or drink for sale, or a recreational area where food is served

  • lounge or staff room - a room reserved for employees to socialize, eat, or relax, especially if non-staff are present in the facility (e.g. retail store, school)


Some people may lazily call it a kitchen; however, as a kitchen is a room for preparing meals, having a "full kitchen" implies cooking equipment like an oven, range, or deep fryer, and not just a toaster or microwave oven. Conversely, if the area is used primarily for serving meals, it may be a refectory or dining room, or a cafeteria or commissary if the food is ordered a la carte from a counter.


word usage - What does "back east" mean?


How do I go back east if I've never been to the east? It does not make sense to return to a place you've never been.



Answer



In American English, we sometimes say up north, down south, out west, and back east when referring to directions. The words up, down, out, and back do not have any special meaning in this context, but are often used as a matter of convention. Additionally, the Eastern United States is sometimes referred to as back east.


According to this Ngram, it appears that this usage became more common in the latter half of the 19th century, began to decline between 1940 and 1970, and then became more widely used than before:


Ngram


Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...