Monday, November 30, 2015

2d - rotation direction


I can't understand, which direction (clockwise or anticlockwise) I should rotate my object, after I apply force on it.


So, I have rectangle ABCD (A(1,1);B(-1,1);C(-1,-1);D(1,-1)), and I apply force V(1,1) to vertex D. Of course it should rotate anticlockwise, but what kind of algorithm should I use to define it? Think I already define object speed and direction, rotation speed, but I can't handle with direction.



Answer



You can determine the direction (and magnitude) of a torque by computing the cross product between the vector from the pivot to the point of application and the vector representing the force.


So, in your example:


pivot = (0, 0)

point of application = (1, -1) - pivot = (1, -1)
force = (1, 1)

Since all our vectors are in the 2D plane z = 0, we know our torque points along the z axis so we can compute just its z component:


torque = point.x * force.y - point.y * force.x
= 1 * 1 - (-1) * 1
= 2

So we have a positive torque about the z axis, corresponding to a counter-clockwise rotation in the xy plane. If the torque comes out negative, then the resulting rotation will be clockwise instead.


grammaticality - Me/my not knowing the truth?


A gerund is a verbal, and always functions as a noun. It is formed by adding "ing" to the verb. I have recently found out that gerund must be modified by a possessive noun or pronoun. However, it is important to distinguish between a present participle and a gerund, something I sometimes have trouble with.



The noun or pronoun before the gerund is called the subject of the gerund, and should be in the possessive form. However, what if there is a word of negation (no or not) positioned in between? Below are the two examples I thought of. I believe that both of them are gerunds and not participles. Which is the correct construction according to the above grammar rule?



  • She is worried about me not knowing the truth


or



  • She is worried about my not knowing the truth


Now, I know I should be confident in using the second example, given the rule. However, I just want to make sure that there is no exception or changed even when there exists a word of negation separating the noun/pronoun and the gerund.


Thanks a bunch in advance.





negation - How to choose a proper contraction "it's not" versus "it isn't"?


I'm aware that both it's not and it isn't are contractions of the same phrase, it is not.


Till today, I was convinced that choosing them depends on desired emphasis. This way, choosing it's not allows one to make an emphatic stress on not:



It's NOT my fault!



...and other than that it's just a matter of style, not grammar.



Recently, I was watching Monty Python's "Argument Clinic":



M: An argument isn't just contradiction.
A: It can be.
M: No it can't. An argument is a connected series of statements intended to establish a proposition.
A: No it isn't.
M: Yes it is! It's not just contradiction.
A: Look, if I argue with you, I must take up a contrary position.
M: Yes, but that's not just saying 'No it isn't.'
A: Yes it is!

M: No it isn't!



I was surprised they have never used it's not during the whole sketch.
This confused me a lot as it opposed my prior understanding: two people contradicting each other would rather use it's not.
More than that, at 01:42 they have used you did NOT and then you DIDN'T, which must indicate that the latter is more pathetic than the former.


So, how to choose a proper contraction between "it's not" versus "it isn't"? Which one is more emphatic, and how come a contracted variant looks more pathetic than the expanded one?



Answer



‘An A-Z of English Grammar and Usage’ by Leech and others suggests the following:



With be, use the contraction + not (e.g. That’s not right).



With have and modal auxiliaries, use the verb + n’t option, e.g. hasn’t, can’t.



The authors go on to say that forms such as She isn’t hungry, as opposed to She’s not hungry, are less common, and that forms such as I’ve not met him, as opposed to I haven’t met him, are much less common.


The authors don’t say on what basis they make their recommendations, but they are likely to be based on frequency of use. There doesn’t seem to be any difference of meaning or emphasis. I would just add myself that a contraction such as I’ve not met him sounds more formal, perhaps because of its lower frequency.


process - Are there any benefits for using the CPU instead of the GPU?


I've been researching processors and graphics cards, and I discovered that GPUs are way faster than CPUs. I read in this one article, a 2-year-old Nvidia GPU outperformed a 3.2GHz Core I7 Intel processor by 14 times in certain circumstances. If GPUs are that fast, why don't developers use them for every function in a game? Is it possible for GPUs to do anything other than graphics?



Answer



"I've read that F1 cars are faster than those we drive on the streets... why people don't use F1 cars then?" Well... The answer to this question is simple: F1 cars can't break or turn as fast as most cars do (the slowest car could beat an F1 in that case). The case of GPUs is very similar, they are good at following a straight line of processing, but they are not so good when it comes to choosing different processing paths.


A program executed in te GPU makes sense when it must be executed many times in parallel, for instance when you have to blend all the pixels from Texture A with pixels from Texture B and put them all in Texture C. This task, when executed in a CPU, would be processed as something like this:


for( int i =0; i< nPixelCount; i++ )
TexC[i] = TexA[i] + TexB[i];

But this is slow when you have to process a lot of pixels, so the GPU instead of using the code above, it just uses the next one:



     TexC[i] = TexA[i] + TexB[i];

and then it populates all the cores with this program (essentially copying the program to the core), assigning a value for i for each. Then is where it comes the magic from the GPU and make all cores execute the program at the same time, making a lot of operations much faster than the linear CPU program could do.


This way of working is ok when you have to process in the same way a very lot of small inputs, but is really bad when you have to make a program that may have conditional branching. So now let's see what the CPU does when it comes to some condition check:



  • 1: Execute the program until the first logical operation

  • 2: Evaluate

  • 3: Continue executing from the memory address result of the comparison (as with a JNZ asm instruction)


This is very fast for the CPU as setting an index, but for the GPU to do the same, it's a lot more complicated. Because the power from the GPU comes from executing the same instruction at the same time (they are SIMD cores), they must be synchronized to be able to take advantage of the chip architecture. Having to prepare the GPU to deal with branches implies more or less:




  • 1: Make a version of the program that follows only branch A, populate this code in all cores.

  • 2: Execute the program until the first logical operation

  • 3: Evaluate all elements

  • 4: Continue processing all elements that follow the branch A, enqueue all processes that chose path B (for which there is no program in the core!). Now all those cores which chose path B, will be IDLE!!--the worst case being a single core executing and every other core just waiting.

  • 5: Once all As are finished processing, activate the branch B version of the program (by copying it from the memory buffers to some small core memory).

  • 6: Execute branch B.

  • 7: If required, blend/merge both results.


This method may vary based on a lot of things (ie. some very small branches are able to run without the need of this distinction) but now you can already see why branching would be an issue. The GPU caches are very small you can't simply execute a program from the VRAM in a linear way, it has to copy small blocks of instructions to the cores to be executed and if you have branches enough your GPU will be mostly stalled than executing any code, which makes no sense when it comes when executing a program that only follows one branch, as most programs do--even if running in multiple threads. Compared to the F1 example, this would be like having to open braking parachutes in every corner, then get out of the car to pack them back inside the car until the next corner you want to turn again or find a red semaphore (the next corner most likely).



Then of course there is the problem of other architectures being so good at the task of logical operations, far cheaper and more reliable, standarized, better known, power-efficient, etc. Newer videocards are hardly compatible with older ones without software emulation, they use different asm instructions between them even being from the same manufacturer, and that for the time being most computer applications do not require this type of parallel architecture, and even if if they need it them, they can use through standard apis such as OpenCL as mentioned by eBusiness, or through the graphics apis. Probably in some decades we will have GPUs that can replace CPUs but I don't think it will happen any time soon.


I recommend the documentation from the AMD APP which explains a lot on their GPU architecture and I also saw about the NVIDIA ones in the CUDA manuals, which helped me a lot on understanding this. I still don't understand some things and I may be mistaken, probably someone who knows more can either confirm or deny my statements, which would be great for us all.


apostrophe - Can a possessive S be attached to nouns that are not human beings (or animals)?


Can a possessive S be attached to nouns that are not human beings (or animals)?


For example, instead of saying "the back of the chair", can I say "the chair's back"?


I remember learning that not everything can get a possessive s, but this issue is not clear to me.




articles - "English", "the English" or "an English"?



Well, one thing came in my mind when I've posted a comment on SO.


Comment is: Do you understand English?


Can we write the English or an English ?


I'm generally use Grammar Checker when i confuse, but when i pasted this three different sentences, it shows: No grammar or spelling mistakes found


So, which one is right, and grammatically correct?



Answer




'English' (as in language) is not a quantifiable noun.


You can't use an or the, which are articles used to refer to quantifiables with a non-quantifiable noun. Saying 'the English' or 'an English' (referring to the language itself in a general way, and not referring to a particular English) is just as wrong as saying 'the tea' or 'a sugar'. For these cases, the correct phrases would be 'the cup of tea' or 'a kilo of sugar', being 'cup' and 'kilo' the nouns you are using the articles with. Examples and further explanation on this can be found here.


However, if you'd like to use the, you can say 'the English language' but note that you are using the word as an adjective rather than a noun here, and that 'the' is referring to 'language' rather than to 'English'.


To particularly answer your question, the correct option is "Do you understand English?" and both of the others are wrong.


Hope this clarifies things for you.


Sunday, November 29, 2015

"Desolated"; past tense of an adjective?


He looks around the desolated street.


In this sentence, If I'm not wrong, 'desolated' is an adjective, right? Or is it a verb? In the dictionary 'desolate' is defined as an adjective. "Desolated" is defined as the past tense of "desolate".



  1. Only verb can be in past tense or even adjective can be in past tense?

  2. In the above sentence "desolated" is a verb or an adjective? My guess is it's an adjective here.

  3. Is "desolated" a past participle of the verb "desolate"?

  4. Is the above sentence wrong and should I have written the above as below?


He looks around the desolate street.



Mostly I'm sure my first sentence is correct, but I'm little confused.



Answer




Only verb can be in past tense or even adjective can be in past tense?



Correct.



In the above sentence "desolated" is a verb or an adjective? My guess is it's an adjective here.



Desolated is certainly an adjective in your sentence.




Is "desolated" a past participle of the verb "desolate"?



Yes it is. And as so many past participles, it can be used as an adjective. The street could also have been deserted, darkened, emptied, forgotten or populated. All past participles that can be used in this sentence as adjectives.



Is the above sentence wrong and should I have written the above as below?



No, it is just fine as you wrote it.


However, desolate on its own, can also be used as an adjective. And this is where the confusion starts.


There seems to be a nuance difference between desolate and desolated.



If you use desolated, you indicate that the state of the street is the effect of it having been desolated - or you could say ruined.


If you use desolate, it feels more as if you describe an overall attribute of the street, that might be comparable to it having been desolated, even if it has always been like that - a more apt synonym could be bleak in that case.


Adjective followed by multiple nouns - what is modifed


I ran into a grammatical construction which I don't know how to interpret. What confuses me even more is that, after extensive googling, I found none other confused by it, except one person who's question got downvoted (https://english.stackexchange.com/questions/259980/how-to-interpret-and-adjective-followed-by-two-nouns).


Even worst, I have an adjective and three nouns, let say main plugin file line. So if one has adjective+noun1+noun2+noun3 without clear meaning - which noun is modified with this adjective? Is it main line? Main plugin? Main file? Is there any such grammatical rule at all or is it just poor wording not covered by such?




indefinite article - "Part of the team" vs. "a part of the team"


I see both of these are used:






  • I'm part of Acme's technical team.




  • I'm a part of Acme's technical team.





Which one sounds more natural when introducing myself in an email? Is "Part" countable or uncountable in this context?




Answer



As a statement by itself,



I'm part of Acme's technical team.



is more natural.


But you could use an article as emphasis or when contrasting with other information.



He is a part of Acme's technical team, even though he does not contribute much.


(after making a big contribution) You see, I am a part of Acme's technical team.




unity - How to make prefabs independent?


I'm working on a Unity's Project and I want to modify a prefab, more precisely I want to change the texture of a prefab. The problem is that my modification is applied also to other prefabs. I read on the documentation how each of the buttons labeled Select, Revert and Apply works, and what I understood is that the modification should update only the selected prefab.


Here is the Prefabs' Manual which I read.


What am I missing?


PS: I'm not the author of the project, I have to apply some modifications only.



Answer



It's more likely that you're modifying the material the prefab is using, and other prefabs using that material are being affected. While you are correct that what you're doing shouldn't modify the other prefabs, those prefabs still share a reference to the same material. When modifying a material, it affects all objects and prefabs that reference that material.



You should make a copy of the material and reference the copy from the prefab you want to modify.


xna - 45° Slopes in a Tile based 2D platformer


I want to have simple 45° slopes in my tile based platformer, however I just cant seem to get the algorithm down. Please take a look at the code and video, maybe I'm missing the obvious?


//collisionRectangle is the collision rectangle of the player with 
//origin at the top left and width and height
//wantedPosition is the new position the player will be set to.
//this is determined elsewhere by checking the bottom center point of the players rect
if(_leftSlope || _rightSlope)
{
//Test bottom center point

var calculationPoint = new Vector2(collisionRectangle.Center.X, collisionRectangle.Bottom);
//Get the collision rectangle of the tile, origin is top-left
Rectangle cellRect =
_tileMap.CellWorldRectangle(
_tileMap.GetCellByPixel(calculationPoint));
//Calculate the new Y coordinate depending on if its a left or right slope
//CellSize = 8
float newY = _leftSlope
? (calculationPoint.X % CellSize) + cellRect.Y
: (-1 * (calculationPoint.X % CellSize) - CellSize) + cellRect.Y;

//reset variables so we dont jump in here next frame
_leftSlope = false;
_rightSlope = false;
//now change the players Y according to the difference of our calculation
wantedPosition.Y += newY - calculationPoint.Y;
}

Video of what it looks like: http://youtu.be/EKOWgD2muoc



Answer



From what I understand reading your question, you want to calculate the correct Y position, given a X position of the player. This is rather trivial. Have a look at this image:



slope


Assuming your slope-tile is at a given position x,y (origin is bottom left as in the image). You have the player position x1 and the width and the height of the sloped tile (u, v). x, y and x1 are world coordinates.


Given these parameters, your players Y-position (y1) would be:


y1 = y + (x1 - x) * (v / u)

If you're only dealing with 45 degree angles, then it gets even simpler:


y1 = y + (x1 - x)

If the slope is the other way round, it's:


y1 = y + (v - (x1 - x))

c++ - Proper way to handle destruction of game entities


Imagine a game world where loads and loads of entities are dynamicly loaded all the time, I would represent that as a list of entities perhaps, but what about removing them?


While when adding i could be pushing back the new entity, i could have the need to remove anywhere in the container. To avoid searching the element to find its position for removal, what choices do i have?


I tought that i could store the entity id as being its position in the container, creating a path for direct removal, but wouldnt that generate some kind of mutual dependency 'disorder' ?


I know the right way would be something like List.RemoveAt(whereToRemove); but what if only the entity knows when it should die?


Or am I just missing something and a list container would know when an object is destructed and reduce its own size?




Answer



Here are your conditions:




  • Other objects may still be dependant on your removed entity, after it is removed.




  • You want only the entity to specify it's own removal.





You can't have both. Why? Because code at a higher level than your entity itself (see examples below) decides when that entity needs to be used. Consequently, only code at that same level can determine whether your entity is fit for removal or not.


However, what can happen is that the entity can request it's own removal, by firing off an event which the higher level code is listening for. That higher level then stores this request for removal in a list.




Example 1: without events


You are checking collisions between entities in your world. This is handled higher up, usually in your main game loop, which checks every entity against every other. In this example specifically, when an entity collides with another, only that entity's internal logic can determine how much damage it has taken, and whether or not it has "expired". So lets follow the logic flow for collisions where you have four entities in your world, A, B, C, and D. A is our entity we are concerned with.


We check A for collision with B. There is a collision. A takes damage 50%.


We check A for collision with C. There is a collision. A takes damage 50%. Because damage reaches 0, A determines that it has "died". It removes itself from the list.


We check A for collision with D. There would have been no collision, but you'll never get that far: you get a runtime exception because your entities list has been modified in the midst of a traveral operation.


Example 2: with events


Same setup as before.



We check A for collision with B. There is a collision. A takes damage 50%.


We check A for collision with C. There is a collision. A takes damage 50%. Because damage reaches 0, A determines that it has "died". It fires an event to the entity management code to say, "Remove me ASAP". The entity management code looks at the entity reference sent as part of the event, and stores that reference in a list of entities to be removed.


We check A for collision with D. There is no collision, and the check works just fine.


Now, at the very end of the current game loop iteration, run through the list of entities to be removed, and remove every one of these from your main entities list.




You can see how this avoids the problem altogether. You needn't use events, you can use signals or something else, but the principle is the same -- don't remove entities until you can safely do so. The flipside to this approach, to keep things clean and orderly, is doing the same with entities to add -- make sure you keep references to them, and only add them at the start of the next game loop iteration.


Lastly, don't forget to flush both your to-remove and your to-add lists, each time you use them to perform additions / removals on your main entity list.


PS. Don't be afraid to seek through your main list to do individual removals. It's part and parcel of entity management, and even massive lists tend to be very fast to traverse -- after all, that's what they're engineered for.


Saturday, November 28, 2015

xna - Some questions about lists


I've been looking for articles or tutorials on this and I can't seem to find any, so I thought I'd ask here. I've created a bullet class in my game that is added and removed through a list. If I'm going to make these bullets work the way I want them to I need to be able to do two things:


One, I need to check if the bullets are colliding with each other and then remove the two bullets that are colliding. I've tried doing it by updating the bullet list with a for statement and then checking for collision with another for statement, but that occasionally crashes the game.


Two, I need to be able to check how far away every other bullet in the list is from the current one.


So how can I go about doing this?



Answer



The crash you are getting is probably because you are removing objects from the list while iterating through it. This will modify the Count of the list and the iterator will try to access elements that no longer exist.


The solution is to use a second list to which you add the objects that must be deleted.



for(int i = 0; i < bulletList.Count - 1; i++)
{
for(int j = i + 1; j < bulletList.Count; j++)
{
if(bulletList[i].CollidesWith(bulletList[j])
{
bulletsColliding.Add(bulletList[i]);
bulletsColliding.Add(bulletList[j]);
}
}

}

for(int i = 0; i < bulletsColliding.Count; i++)
{
bulletList.Remove(bulletsColliding[i]);
}
bulletsColliding.Clear();

Unfortunately, the problem with this is that you can get duplicates of bullets in your bullets colliding list if a bullet is colliding with more than one bullet at a time. Using C# lists the Remove function will only return false though.


Using flags to set the bullets to Alive or not can be a good idea to stop you from having to instanciate a Bullet if dead ones aleady exist. I would however just 'move' the bullets into a second list which is neither Draw()'n nor Update()'d, and move them back when you need to create a new bullet, and the list isn't empty.



You must be very careful though that the Bullet instance is properly reset before you re-insert it into the working list.




To check the distance between bullets, you can use Pythagoras' theorem. In 2D :


float Distance(Bullet a, Bullet b)
{
float xDistance = b.x - a.x;
float yDistance = b.y - a.y;

float sqDistance = (xDistance * xDistance) + (yDistance * yDistance);


return Math.sqrt(sqDistance);
}

In very time-critical sections, it is common to use squared positions of objects and not perform the square-root operation, as it is quite expensive.


iphone - Organize a game set


I'm developing a endless running game and I'm not really sure on how to make the set. The first approach was to make a BIG set like 10240x3072 pixels so that we have a nice portion of set. After having like 3 or 4 sets that go along with each other I would work on making their elements sequential and repeatable. However this is getting really heavy for the iPad 1 (it's running good in the iPad 2 and the New iPad) even though I'm splitting all the set in slices through Photoshop. For the implementation I'm using Cocos2D. Is there any better approach to make something like this but truly efficient for the iPad memory?


Thank you.




difference - quite a bit, quite a lot Vs very


Do quite a bit and quite a lot mean very large amount or quantity ?


I'm confused here because I think I can replace "Quite a lot or quite a bit" with" very". so, Do quite a bit and quite a lot mean very large amount in the the following can I replace "quite a bit" and "quite a lot" with "very" withouht changing the meaning of the sentences ?


1.She is quite a bit/lot younger than me.


2.It's is quite a bit/lot heavier.


3.It's quite a bit/lot smaller.



Answer





Do quite a bit and quite a lot mean very large amount or quantity ?



Yes. They mean a large difference though.



She is quite a lot shorter than me. He is quite a lot taller than me.



The first one means she is very small compared to me, and the second means he is very tall compared to me.



I think I can replace "Quite a lot or quite a bit" with" very".




Very is an adverb that gives emphasis. Quite a lot is an amount. They have near-enough the same meaning.



She is very short compared to me. He is very tall compared to me.



For your examples:



She is quite a bit/lot younger than me.



She is very young compared to me.




It's is quite a bit/lot heavier.


It's quite a bit/lot smaller.



You cannot use very here, because very just gives emphasis.



The rock is very heavy



However you are using heavier which means you are comparing it to something else.



The dog was heavier than the kitten. The elephant was heavier than the dog.







If "quite a bit/lot" gives the same meaning as "very", which one is suitable in which situations?



This is mostly a case of personal preference. There is a small nuance, so I will give some examples.


Let's compare these:



A. She is quite a lot shorter than me.


B. She is very short compared to me.




If you break the sentences up, you get this:



A. [She] [is quite a lot shorter] [than me].


B. [She] [is very short] [compared to me].



If you want to emphasise the difference in height, you should use A. The main topic of the sentence is "there is a height difference".


However, if you want to emphasise the amount that she is very short, you should use B. The main topic of the sentence then is "she is very short".


So, sentence A talks about the difference, and sentence B talks about the amount.


Here is another example:





  • The blue shoes cost $10. The red shoes cost $100.




  • A. The blue shoes are quite a bit cheaper than the red shoes.




  • B. The blue shoes are very cheap compared to the red shoes.





If you say A, then you are talking (and thinking) about the difference. You are saying that there is a big price difference.


If you say B, then you are talking more about the amount that the blue shoes cost.


In case A, you might think:



"The blue shoes are quite a bit cheaper than the red shoes. Therefore I think the blue shoes are best."



In case B, you might think:



"The blue shoes are very cheap compared to the red shoes. Maybe there is a reason they are very cheap. Perhaps they are not good quality.




The logic you use to think is up to you, but on the whole you would use them depending on which aspect you are talking about, to emphasise your meaning. However they are so similar that you may use them interchangeably.


The meaning may cause offence in some situations though so be careful. If you say:



"You are very short compared to me."



It may be a little offensive, because you are talking about the amount (the height) of the other person. They may be sensitive to talking about it.


Whereas:



"You are quite a lot shorter than me"




May be okay (for example, if you are tall). You are talking about the difference in height. So if you are tall, of course there is a big difference. You are not calling the person short, so it is okay.


Where can I find free music for my game?



I'm in need of some tunes for my game. Where can I procure some, preferably for free?




Friday, November 27, 2015

opengl - How to manage VBO geometry for constantly changing data?


Before going into specifics, I'm mostly interested in making simple 2D games with some 3D elements, not fancy AAA.


Based on what I've gathered, everyone seems to suggest to use OpenGL 3+ with shaders, instead of the 2.x style of glVertex/glBegin/glEnd. Now I do understand the reasoning behind moving to VBO and shaders, as it gives greater control and performance.


But it seems that it also forces me to produce all of the geometry beforehand, buffer is it somehow, generate the VBO, and then send all that to a single vertex/fragment shader to render it, correct?


It also seems that I need to have a single shader process completely different types of vertices, which means there has to be a lot of redundant information in the VBO? Or is there a way to have multiple VBOs? I know it is possible to have multiple shaders and swap them, but I haven't figured out when one would need that, considering I only have a single active VBO?


Now comes the real question.


Consider I'm making something like a procedurally generated growing plant, where each frame changes the whole geometry slightly (or just adds something). For simplicity, let's just say the plant is a bunch of colored ellipses. How do I structure the algorithm for "drawing" the plant? Would I just build the whole VBO from scratch, given that the vertex data changes all the time?


Also considering that the number of plants and their size can vary greatly, how do I avoid re-allocate memory for the VBO on each frame? Do I just use a large enough buffer, which would be able to store the maximum amount of geometry I can manage in my shaders (like a 512MB static array)?




Answer



Your assumption that there should be only a single VBO and shader is incorrect. You can, up to the limits of available memory, have as many VBOs as you want. For smaller games you can get away with having one VBO per drawable object, but ideally you should share VBOs between objects that require the same set of uniforms, shaders, and textures, so that each set of objects can be drawn in one shot using glDrawArrays or glDrawElements.


As far as structuring the VBOs in the case of your procedurally generated plant, it would probably be best to give each plant its own VBO, so as to not have to worry about moving vertices from other objects around to accommodate the increasing or decreasing number of plant vertices. You can allocate a "large" VBO up front to avoid reallocation as the plant grows, but 512mb would be way too much (and may even fail.) You can easily calculate the size of your vertex data, and estimate how large the plant could ever grow to be, and only make your VBO that big.


If your plant growth could be precalculated, you could load a VBO with all of the "frames" end-to-end before hand, and then just page through those frames at the appropriate rate with your calls to glDraw*, but if not, then yes, you should just refill the VBO every frame.


Implementing a wrapping wire (like the Worms Ninja Rope) in a 2D physics engine


I've been trying out some rope-physics recently, and I've found that the "standard" solution - making a rope from a series of objects strung together with springs or joints - is unsatisfying. Especially when rope swinging is relevant to gameplay. I don't really care about a rope's ability to wrap up or sag (this can be faked for visuals anyway).


For gameplay, what is important is the ability for the rope to wrap around the environment and then subsequently unwrap. It doesn't even have to behave like rope - a "wire" made up of straight line segments would do. Here's an illustration:


Ninja rope, wrapping around obstacles


This is very similar to the "Ninja Rope" from the game Worms.


Because I'm using a 2D physics engine - my environment is made up of 2D convex polygons. (Specifically I am using SAT in Farseer.)


So my question is this: How would you implement the "wrapping" effect?


It seems pretty obvious that the wire will be made up of a series of line segments that "split" and "join". And the final (active) segment of that line, where the moving object attaches, will be a fixed-length joint.


But what is the maths / algorithm involved for determining when and where the active line segment needs to be split? And when it needs to be joined with the previous segment?


(Previously this question also asked about doing this for a dynamic environment - I've decided to split that off into other questions.)





word usage - What's the difference between "either" and "neither"?



What's the difference between either and neither?
Can you provide me some examples?



Answer



Either means any one of two possibilities, whereas neither means none of them.


For example:



John: Would you like something to drink?
Jane: Either Coke or Pepsi would be fine.




Here, Jane would like something to drink—specifically, John can get her a Coke or a Pepsi. Generally, either excludes both options—John should not get her both a Coke and a Pepsi.


However, if the conversation were to go along these lines:



John: Would you like coffee or tea?
Jane: Neither, thanks.



Here, Jane does not want any of the two options offered her—she does not want coffee, and she does not want tea.


Both either and neither should only be used when there are two options. If there are three or more, analogous words would be any and none.


game design - Time based movement Vs Frame rate based movement?


I'm new to Game programmming and SDL, and I have been following Lazyfoo's SDL tutorials. My question is related to time based motion and frame rate based motion, basically which is better or appropriate depending on situations?. Could you give me an example where each of these methods are used?.


Another question I have is that, in lazyfoo's two Motion tutorials (FPS based and time based) The time based method showed a much smoother animation while the Frame rate based one was a little hiccupy, meaning you could clearly see the gap between the previous location of the dot and its current position when you compare the two programs.


As beginner which method should I stick to?(all I want is smooth animations).



Answer




What's being shown as "FPS based" there is . . . well, basically, it's awful. It's pinning the game's speed to the performance of one particular computer. If you upgrade to a nice fast computer, your game will suddenly run in turbo speed, if you downgrade to a slower computer you'll be grinding around in slo-mo.


The real choice is fixed time step vs. variable time step, and at that point I will defer to this excellent post which goes into great depth.


adjectives - Is this sentence grammatically correct? "You are so offended"


Is this sentence grammatically correct?




You are so offended.



(Since offended is adjective in past tense)




subject verb agreement - What my son likes the best on TV (are/is) cartoons?



What my son likes the best on TV (are/is) cartoons?




My approach:



What my son likes the best on TV is cartoons.



According to me, the sentence means he likes a single thing which are cartoons.


Can you solve this through other approach related to subject verb agreement and am I right in my approach?




xna - Code to generate a color gradient within a texture using a diagonal line


I want to generate a color gradient between two colors from x1,y1 to x2,y2. I'm unsure how to do this though. I can use Color.Lerp to get all of the color steps, but the problem is that I don't understand how to then apply that to a plane (the texture pixels) when the line would be at an angle.


If it was a horizontal/vertical line, that would be easy, because it's just plotting the same color along the appropriate axis. But if it's a diagonal line of any degree, that seems way more complicated and I'm unsure how to do calculate it.


As an example, here is a gradient from a picture editor program. It goes from green-to-red. The actual start and end positions are the circles. Therefore, the solid start/end colors continue solid outside of the gradient area.


gradient example



Answer




Here is one way to do it, the idea behind this method is rotating the whole image to make the line straight while working on it. I am only using half of the matrix because the line is flattened horizontally and so the Y coordinate doesn't matter to us then.


0. Convert your startPoint and endPoint into vectors:


float x1 = (startPoint.X / (float)width)  * 2.0f - 1.0f;
float y1 = (startPoint.Y / (float)height) * 2.0f - 1.0f;
float x2 = (endPoint.X / (float)width) * 2.0f - 1.0f;
float y2 = (endPoint.Y / (float)height) * 2.0f - 1.0f;

1. Find the angle between (x1,y1) and (x2,y2):


float angle = atan2(x1 - x2, y1 - y2);


2. Create half of a rotation matrix (We only need half for this)


float rx = cos(angle);
float ry = sin(angle);

3. Calculate start and end points in rotated space:


float start = x1 * rx + y1 * ry;
float end = x2 * rx + y2 * ry;

4.-. For each pixel:


for(int x=0;x
for(int y=0;y

4.1. Rotate the pixel so the line is horizontal


        // but we need vectors from (-1, -1) to (1, 1)
// instead of pixels from (0, 0) to (width, height)
float u = (x / (float)width) * 2.0f - 1.0f;
float v = (y / (float)height) * 2.0f - 1.0f;

float here = u * rx + v * ry;


4.2. Find the ratio between start and end


        float lerp = (start - here) / (start - end);

4.3. Interpolate between your colors and finish the pixel


        SetPixel(x,y, Color.Lerp(color1, color2, lerp));
}
}

c# - Rotating an object continously with OnMouseDown


I have a script that works but it does not do what I want it to do. My script makes an object rotate on when another is clicked. However, I want the object to continuously rotate until I click on the other object again. Right now when I click it rotates just a bit and stops.


Here is my script:


 public class Rotate : MonoBehaviour {
public float speed =50f;
public GameObject target;

public void OnMouseDown(){
target.transform.Rotate (new Vector3(0, Time.deltaTime, 0) * speed);
}

}

How can I make the object rotate continuously until I click it again?




word choice - interested in/to: what's the difference?


As title suggests..what's the difference? I heard that the difference is that with "in" you are talking about something that will or is lasting in the time, while "to" is something you do just one time.


So, the sentence "I am interested in starting my career in your company" is correct? Or maybe "I am interested to start my career in your company"?



Answer




Whether you use "in" or "to" depends on how you are using word that comes after it.


Interested in


When you use "interested in", you are usually talking about being interested in something (generally, a noun). For example, you can be interested in wine, or interested in cheese. Therefore, this sentence usually takes the form "[Someone] is interested in [something]."


There are times, however where the something you are interested in can be a verb. For example, you can be interested in swimming, or reading, or sleeping. In this case, the verb is acting like a noun. When a verb acts like a noun, it is called a gerund and almost always will end in "-ing".


Interested to


"Interested to" is a bit more complicated, because by itself it doesn't really make sense. The "to" is actually part of the verb that comes after it, like in "to read", "to see", or "to hear". This "to form" of the verb is known as the infinitive, and is used to add detail to (or modify) the word that comes before it.


This type of sentence usually takes the form of "[Someone] is interested [to do something]."


To really answer your question...


"Interested in" is used when what comes after it is a noun, or a verb acting like a noun (known as a gerund).


"Interested to" is used when what comes after it is a verb in its "to form" (known as an infinitive).



"I am interested in starting my career in your company" is the preferred construction. While "I am interested to start my career in your company" may be technically correct, you should not use it because people generally don't use "interested" with "to start". A more commonly accepted way to say it while still using the "to" would be "I am excited to start my career in your company".


Hope this helps, and good luck with your new career! :)


Thursday, November 26, 2015

unity - Rendering hundreds of animated characters in Unity3D


I am currently doing some research in anticipation to the development of a game where there is going to be hundreds of secondary entities which will interact with the player and among themselves (little soldiers with a very simple AI and not too many faces).



What I've found so far is that there is a way of avoiding the GameObject overhead, at least for the rendering bit of things, by using the Graphics class, with the Drawmesh method more specifically.


I've tested it and it's not too complicated. I could render any of my models using it and then make them move by rendering the graphics around coordinates in some non-unity "Character" object. The fact that the drawmesh call has to be every frame is actually quite convenient in this case !


However, I've ran into a problem : how do I deal with animated objects ? Now, I've also done some research on that, and what I've found is that you can "Bake" the skinned mesh into a mesh usable with Graphics.Drawmesh. Then I thought about rendering animated far away characters by updating their mesh with their current animation at a certain interval. This would make the character look wierd but at long distances and among many others it should render quite well.


But the thing is, since I don't want to create a GameObject for each entity, or more precisely only for the ones up close that need a collider and everything so the players can target them with a raycast. And I sure as hell don't want to create a skinned mesh renderer for each far-away character, as it would defeat the point of using Graphics.Drawmesh.


I've thought about one solution to this problem : I could have one "hidden" GameObject with the proper models and animations get requests from "Optimized", meaning far-away character to set himself to a certain frame of a certain animation, bake his mesh and send it back to whoever requested it. I did not run any tests with that solution (I came up with it while writing this) but I'm kinda afraid that updating the mesh of a single entity potentially hundreds of times per frame might lead to wierd behaviors. Besides, I'd have to put it far away so that it doesn't get found by the players.


So, my exact question is : Do you have any better idea as to how I could optimize rendering all those characters some other way, and if not, is there a way to ask Unity "what would this mesh look like on this frame of this animation", thus allowing me to avoid creating a Gameobject just for that.


Thanks a lot in advance ! Cheers !




2d - Falling Blocks and complex shapes



I currently have a simple Tetris-like game and have come across a problem I cannot solve.


Unlike Tetris where there is a single falling shape, I have multiple, potentially interlocking shapes that need to fall; I need to calculate their final positions. Consider the following:


examples of the falling blocks problem




  1. To calculate the final position of the green shape, I simply scan down for every square until I hit another square or the edge of the board. Done




  2. For multiple, simple shapes I work my way UP the board. Thus the red is found to not need moving, the orange goes down by one, the green down by three. Done





  3. I don't know how to treat the interlocked green and red shapes. Using the logic of #2 we would end up "stuck" floating mid-air. If I scan down for the green shape, I encounter the red and thus do not move, and vice-versa for the red. The solution might be to treat the two shapes as one.




  4. Similar to #3, in this scenario I could also succeed by treating the objects as one.




  5. Unlike #3 and #4 I could not treat the shape as one as the orange shape would end up floating one-square too high...





  6. Another variation of problem #6.




There could be other scenarios whereby I have many many shapes that interweave in more and more complex scenarios, but I think the above covers the most fundamental parts of the problem.


I feel like there's an elegant solution that I've yet to encounter / think up and would be very grateful at any insight, ideas or resources.


SOLUTION


The solution I've come up with is indeed elegant, based on @user35958's answer below, I have created the following recursive function (pseudo code)


function stop(square1, square2){
// Skip if we're already stopped
if(square1.stopped){

return;
}
// Are we comparing squares?
if(!square2){
// We are NOT comparing squares, simply stop.
square1.stopped = true;
} else {
// Stop IF
// square1 is directly above square2
// square1 is connected to square2 (part of the same complex shape)

if(square1.x == square2.x && square1.y == (square2.y+1) || isConnected(square1, square2)){
square1.stopped = true;
}
}
// If we're now stopped, we must recurse to our neighbours
stop(square1, squareAbove);
stop(square1, squareBelow);
stop(square1, squareRight);
stop(square1, squareDown);
}


Animated GIF showing each pass of the solution


To summarise:



  • When "stopping" a square, we also stop:

    • ANY square above it. ALWAYS.

    • Neighbouring square that we are connected to (ie the same shape).




  • We stop the entire bottom row, and the function recurs up through the squares.

  • We repeat until all squares are stopped.

  • Then we animate.


Animated GIF showing each pass of the logical sequence



Answer



Well, you don't exactly need to treat to shapes as one if there's a distinction between shapes that are moving and shapes that are at rest. A shape (A) could detect a shape (B) directly below it and if it's moving, then the B shape could then see if there's anything directly below it, and if there's an resting shape, then A and B are now resting, and if there's nothing, they both move down, but if there is a moving shape, then this new shape will be treated by A and B as A treated B, so it's sort of recursive. Keep in mind that for each step, the lowest shapes need to check for shapes below them first.


So, for problem #6, the green shape is the lowest moving shape, and it would see that the only shape that's directly below it is the red shape, so then the red shape would detect nothing directly below it, and they would move down. Once the green shape is adjacent to the orange shape, it would rest, and the red shape would move down and then detect the resting green shape, and it would rest too.


rpg - Strategies for monster targeting AI in a turn-based combat system


I am making a Final Fantasy-style battle system.


I have a random generator that select the monsters move when it is their turn; different moves have different chances to be performed. I also have reactions and conditional actions for the monster to create simulated intelligence... but what I can't figure out is targeting.


I could just choose randomly between the five player characters, but I was looking for something that would make the game more challenging by adding some kind of strategy to the monsters' actions.


I code in C++.



Does anyone have an idea how to implement a system for the monster to choose who to attack besides completely random?



Answer



My answer from this question would fit here.


To adapt for your problem: A monster would look to assign a score to each enemy. Pass the enemy to each of a collection of behaviour classes, which each return an integer score. Add all these scores together, and assign the final score to the enemy. Attack the enemy with the highest score.


This has the scope for different monsters having different behaviours, evaluating targets in different ways, and the personality extension I mentioned in the other answer could be modified at run time to alter target choice based on the monster's situation: maybe he becomes more aggressive as his health lowers?


From chaos' answer, you could keep a sticky target by remembering the score of the last target, and any new target would have to beat that score by some extra %.


Examples of the behaviours might be:



  • defenseless target behaviour: returns high scores for targets that are particularly susceptible to this monster's attacks - eg a mage vulnerable to red magic in a battle with a fire demon.

  • weak target behaviour: returns high scores for targets that are close to death


  • decapitation behaviour: returns a high score for the player or leader of the group

  • splash damage behaviour: if your game is a strategy-style rpg, that can make attacks across various team members, this behaviour could return high scores for targets that affect large numbers of bystanders, eg if a target is in the center of a tight group.


All of these behaviours are based on snapshots of the current game state, and require no long-term planning and little state on behalf of the monster.


More ideas: if your monster has multiple attacks, run this whole alg once for each attack, and pick the target/attack pair with the highest score. This was how I made enemy infantry select weapons on one big-budget FPS.


xna - How to add several GameComponents of the same type?


in order to load 3D-meshes to my project i created a BasicModel class. I made it a DrawableGameComponent so I can override methods like Draw & LoadContent. Plus I have access to the GraphicsDevice etc.


Now I realized that if I try to add several instances of the same GameComponent I get an exception that says that it is not allowed to do this.




  1. Was it even a good thing to do, making the Class a GameComponent?




  2. Is there a way to somehow differ single Components, so that I can add several copies of it to the game?





Thanks in advance.



Answer




Was it even a good thing to do, making the Class a GameComponent?



No. You should only consider using GameComponents for higher level concepts that sit directly on top of your Game class and will only require one instance to exist at any time.


Good examples are classes with Manager in their names such as a ScreenManager, InputManager or AudioManager, or classes that are built to be plug and play such as a FramerateCounter (see link) that you can easily reuse in any other project just by dropping it in.


So if for instance you created a scene graph class to store and manage the rendering and updating of your game world and all of its objects, you might consider making it a DrawableGameComponent. On the other hand, using it for each individual game object is not recommended at all.



Personally, I don't even use game components at all. I prefer having precise control over the updating and drawing of my classes, and if I need a reference to Game I can pass it on the constructor just as well without making the class a GameComponent. Don't let that discourage you from using them though, it's just a matter of personal preference, but just make sure you use them for the right task.


Where can I find free sprites and images?



I need sprites and images, such as characters, landscapes and others. Where can I find them?



Answer



Lost Garden has lots of free graphics that you can use in your games.


For RPG Games you have a cool 32x32 tileset and lots of free to use sprites, objects, icons, etc..


http://soundimage.org/ has a lot of cool textures that are free to use...many of them are seamless so they tile. They are on the "TXR" pages.



Wednesday, November 25, 2015

java - How to spawn multiple enemies?



I can store it in an array, ok, but after how can i paint it? Because if i do
enemy = new Enemy();
enemy2 = new Enemy();
i create two istances of the object, but afer how can i paint it?
I use:
g2d.drawImage(Enemy.getImage(), Enemy.getX(), Enemy.getY(), this);

But obviously it use the class, not the variable.
Images will not be overlyed because coordinates are random.
Excuse me my terrible english.




word usage - "I play tennis everyday" or "I play tennis every day"?


It seems that "everyday" is adjective.


But I saw a lot of people wrote "I play tennis everyday".


Is "I play tennis every day" the right way?



Answer



You are right, everyday is an adjective and it should not be used in this way.



Native English speakers learn most of their vocabulary by listening. When they write things out, they sometimes make mistakes with the spelling of words that sound the same: this is an example.


Here is some more information that clearly explains the difference between everyday and every day.


libgdx - ShapeRenderer efficiency on games


I want to draw a rectangle box to use as a text background for a visual novel library I'm writing, I wanted some flexibility of color and transparency and the ShapeRenderer class seems to fit the need but the doc brings this disclaimer:



This class is not meant to be used for performance sensitive applications but more oriented towards debugging.


If I use it as background the most action on screen would probably be the text scrolling over it. Can someone more experient on the engine tell me if it is viable to use it under those premises, or it is really for debug only?



Answer



It is probably fine for a desktop-only game if you don't draw too many shapes, but it can produce FPS stutter on some mobile GPUs and, iirc, doesn't cache any of the shapes between frames.


A better approach might be to allocate a Sprite with a small white texture that you upscale to the appropriate size. Set tint and alpha with Sprite#setColor


update:


It is possible to manually create a texture by using a pixmap. It is probably easier grabbing the background texture from a texture atlas, if you're using it - allowing libgdx to automatically manage the texture for you. Otherwise:


public static Texture createBgTexture()
{
Pixmap pixmap = new Pixmap(1, 1, Format.RGBA4444); // or RGBA8888

pixmap.setColor(Color.WHITE);
pixmap.fill();
Texture texture = new Texture(pixmap); // must be manually disposed
pixmap.dispose();

return texture;
}

You can scale the texture by using Image class, and then add it to your Stage, or you can get its Drawable using Image#getDrawable to draw in the SpriteBatch.


mathematics - Efficiently transforming a series of points into curves to be serialized


I’m working on a video game where I need to display a map (in 2D) of an actual big European city (Paris, London, Madrid… that kind of big) and the player, displayed as a simple dot on the map, can take different routes while following the street lines.


To do so I extract real data from OpenStreetMap.org. Thanks to it I have access to a ton of data and geographic information, and among them I have street visual settings given as series of coordinates (long/lat converted to X/Y points using the right projection). In OpenStreetMap a street is composed of a set of points so drawing a line between these points is enough to display streets.



However it represents a huge number of points to load which means a lot of time spent processing the data which means: not ideal. For example, a big city like Paris is composed of 65.000 street points. That is huge. In order to reduce this number and still being able to draw / follow street curves I’m thinking about using a graph only composed of points implied in street intersections alongside curve equations to describe the street display. This way a street composed of 2000 points would be not much bigger than one composed of 10 points in theory.



The initial technique The final goal


In this example my initial set is composed of 13 points (red crosses) to display a street. What I’m aiming to in this case is keeping only 4 points (intersections with other streets) and an actual “equation” (or something similar) between each couple of points in order to reduce the size on disk of the final map.


This is where I’m stuck. I suck at Math (and regret it every day). So I can’t figure what would be the best way to transform a series of points into a simple equation that would allow me to follow the actual street curve at runtime.


I don’t know how to do it… I’ve read things about Bezier curves, about Clothoids, Circular Arcs… but I don’t know where to start, what is the best solution here, how to convert my series of points using one of these techniques, or if it’s really the clever thing to do in order to reduce the size (in bytes) of the map…




prepositions - "to the north of London", "north of London", or "in the north of London"


Consider these sentences:




  1. The company's office is to the north of London.

  2. The company's office is in the north of London.

  3. The company's office is north of London.




As far as Grammar is concerned, I think all of them are valid. To show this, I just quote from the dictionaries:



  • "The Yorkshire Dales are twenty miles to the north of the city."

  • "there will be heavy wintry showers, particularly in the north."

  • "the town is twenty-five miles north of Newport."


Would you please tell me what is the difference between these sentences?



Answer



To the north of X and north of X means that it lies beyond X on its northern side (or "above" X on a map oriented with North up). Some would infer that something which is "to the north of X" is not very distant from or relatively close to X, whereas a place "north of X" could be quite far from X.


In the north of X means that it lies in the northern part of X.



Edinburgh is north of Manchester.


Dundee is to the north of Edinburgh.


Durham is in the north of England.


meaning - What does "some topic 101" mean?


One can often see expressions like "Biology 101". Also in in book and article titles like "Wine tasting 101." What does this mean? Does this have something to do with a class one takes? Can it mean something outside of registering for a class?



Answer




It is a reference to the introductory lecture course on many topics (particularly those that are very large, e.g. chemistry, physics). It means that the course is a basic course designed to teach you the beginnings and some of the fundamental components of the topic.


This reference has been adopted into the English lexicon to mean the basic rules and practices which every participant in that activity is expected to know and follow: "Not sleeping with the Ambassador's daughter is Diplomacy 101," "Wearing a lab coat and glasses is Lab Safety 101."


As was pointed out below, the first number in 'topic 101' is often to indicate that the course is recommended to be taken in the first year of a degree, reflecting its introductory nature. By contrast 'ENGL 462' would typically be taken in later years. This nomenclature is not universal in this application, courses can be numbered, lettered or alphanumerically coded as well, and sometimes 'topic 101' is the basics of a very advanced topic, so not truly a basic course.


Edit: added contributions from comments


Tuesday, November 24, 2015

Is Perfect Tense appropriate in "I have forgotten to post your letter."?


I was supposed to answer the question "Did you post my letter?" I answered "No. I have forgotten to." It was a wrong answer. The right one was "No I forgot to."



Can I use Present Perfect there? On one hand since now I remember that I was supposed to post the letter, absent of this knowledge does not prolong up to now. But on the other hand, there is a consequence of my forgetfulness that is relevant now—the letter is not posted.



Answer



I don't know who told OP that "No. I have forgotten to" was a "wrong answer", but it was bad advice.


Since the "forgetting" is still "relevant to the current moment", Present Perfect is grammatically/logically acceptable in such contexts.


But it is true that in practice most native speakers would use Simple Past "No. I forgot to", because very often the actual action described using Present Perfect continues into the present (i.e. - when you say "I have lived there all my life", it always means you still live there).


The tricky thing about forgetting to do something is that effectively it means you forgot about it. But as soon as you admit to having forgotten about it later, you're no longer forgetting. Because it creates a bit of semantic/temporal confusion, natives speakers tend to avoid the implications of Present Perfect here.


meaning - the sort of people that disillusion you about what a lot of golfing money can do for the personality


Here's from The Long Goodby by Raymond Chandler



At The Dancers they get the sort of people that disillusion you about what a lot of golfing money can do for the personality.



I wonder What this means, particularly what "golfing money" means.


A similar question was asked here. https://english.stackexchange.com/questions/198810/what-is-golfing-money



Answer




The Dancers is (likely - I haven't read it) a country club, which usually has a golf course. Country clubs cost a lot of money to join; on top of that, a golf game costs a lot of money for each game. Golf money would imply that someone has enough money to play golf.


In the US, an positive emphasis for many decades (perhaps centuries) was/is placed on being "self-made" - working hard enough to become rich, that is, having all the niceties of life, like a country club membership and golf money. One would think that the character formed from a solid work ethic would bring out good qualities in people. Chandler says it does not; in fact, a lot of money seems to bring out bad traits in people, hence the disillusionment.


Monday, November 23, 2015

How to make the game run at 60 FPS in Irrlicht?


I want my game run at 60 fps, but I don't know where to start, I have the simple loop:


while(device->run()){

How do I lock the frame rate to 60 FPS?




Is the usage of tenses correct in this sentence - "two days had passed since she had last eaten or slept"



Two days had passed since she had last eaten or slept.



Or should it be:



Two days have passed since she last ate or slept.



Or something else? And why? The combinatorial explosion of past simple, past perfect and present perfect is killing me.





prepositions - Between A,B,C & D


There are 4 players. And the question goes:


Who is the best player "between" Jenny, Sam, David, and Lucy?


Is the use of "between" correct after each names? Or if not, what is appropriate?



Answer



In your example, between can be used without loss of understanding



Who is the best player between Jenny, Sam, David, and Lucy?




However, between is usually used in binary choices



Please choose between A or B.



Among is more often used when choosing from a related "group"



Among the car manufacturers: Ford, Audi, Volvo, which do you think is best?


Among your choices are: watching tv, going bowling, or going swimming.
You can choose between watching tv, going bowling, or going swimming.




Also acceptable and understandable is



Between watching tv, going bowling, or going swimming, which would you prefer?



Using between among more than two choices tends to be more informal.


Sunday, November 22, 2015

xbox360 - Feasibility of an XNA game on PC


A friend and I are doing a 2D XNA game. Thus far, the API seems really cool and performance is acceptable. My question is more towards the release of it though. As other developers how have done games, how well have they done for you on PC (as far as downloads, sales, etc)? I know the statistics about the Xbox360 from seeing it personally but, I was curious as to how successful these were on PC?



Answer



I don't have any stats to compare the differences between XNA and non-XNA game sales - I'd suggest that data is impossible to come by - but I imagine it would show there is no difference for equivalent games. So let me answer your question with a run through of the major issues specific to distribution of XNA games on PC (particularly online):




First of all: For an XNA game to run the system needs to have installed: the XNA Framework, and the .NET Framework.


The XNA Framework is a fairly small download, easy to install, but will requires admin privileges - so will cause a UAC prompt as well as a EULA prompt. The framework is not upwards or downwards compatible - but can be installed side-by-side. (ie: a XNA 3.1 game needs XNA 3.1 and won't run on XNA 4.0).


The .NET Framework 2.0 is bundled on Vista and above, so I recommend targeting that (Project Properties -> Target Framework). [UPDATE: XNA 4 requires .NET 4, so this won't work any more]



The .NET 3.5 installation is very, very slow - I recommend avoiding it. I'm not sure about the full 4.0 installation, but the 4.0 Client Profile install is fast enough if you need newer .NET features (you probably don't - you can still use lambdas and extension methods in .NET 2.0).


A .NET Framework install will of course cause a UAC and EULA prompt. It can also cause a reboot.




Currently the "standard" way to distribute XNA games is with ClickOnce. You can do an online install - the downside is that your user gets a small "bootstrap" installer executable that pulls all the loose game files from your website. Alternately you can just distribute all those loose files and the installer in a zip. Neither of these is a self-contained executable file like users expect from most games.


A major pain of ClickOnce is that it will display several warnings about downloading unsigned software, which can look quite scary.


Another other downside of ClickOnce is that you don't have much control over things like, for example, what start menu entries you have.


The upside to using ClickOnce is that it's very easy to set up, and it will automatically download and install the required frameworks from Microsoft's website.


I am under the impression that these issues with ClickOnce can be solved by using an MSI instead - and it can still automatically download and install the required frameworks. I'm afraid I don't have specific instructions for this on hand.




If you do your own installation, or no installation at all, you need to be aware that your game executable will crash with an extremely unhelpful error message if the required frameworks are missing!





Oh, and your install might be a bit bigger (or a lot, if you include frameworks). If you're using XNA's built in content stuff (and why not, it's there and it's easy) your user might have more to download because the files aren't compressed as well as they might be if you handled it yourself (especially audio).




That's about it. Once the game is installed you're in pretty much an identical situation to any other game using native DirectX (ie: most of them).


(If you're doing something like CD-ROM distribution, instead of online distribution, you may face some of the same issues I described - but you can put everything that would otherwise need to be to be downloaded onto your CD instead, including the required frameworks.)


If you're doing downloadable shareware you're basically trying to get users along a chain from finding out about your software, to playing the demo, to buying the full game. The downside of XNA is that it makes the installation step in this chain a bit harder to polish - but it's still possible.


(IMO the upside of easier development and XBox compatibility is well worth it.)


So to bring this back around to your question: using XNA might make a tiny difference - but not enough that it matters. So any stats you find about PC game sales should be applicable to XNA games on PC.


opengl - What happens when a texture is too large for a device


The question is two fold:




  1. What happens on a device when a texture is too large for it to handle? Will it crash or simply downsize it?





  2. In Unity if I use texture atlases of size 4k and then set Texture Quality in the Quality settings as half res will it run normally on devices with maximum texture size of 2k?





Answer



According to this thread automatic downsizing may not work, but setting half res should work.


On a related note, do you really need textures that big? If all you want from a big texture is to use it as an atlas there is really very little reason to not just use 4 2k textures instead of one 4k.


And I assume that this is about writing games for phones, for PC graphics anything that doesn't support 4k textures is really ancient.


Saturday, November 21, 2015

rendering - How should I set camera in Blender for example to render a sprite which can be used in an isometric map?


I am trying to render some 3D model in blender and use them as a texture sprite in a game which uses Apple’s SpriteKit. I have an isometric map with tiles size : 32 as width and 24 as height, Since I use same size tile whole over the map (isometric) I need to use an orthographic projection I think! please tell me if I am wrong but I was pretty sure! anyway...


I am using Blender to render my sprites (3D models) but I can not set the camera direction to have the rendered image really fit with the map. The attached picture shows the problem, take a look at the building.


I have also attached the geometric math that I have used to create my render script in Blender.


I found out that if I use a 32,24 tile I need to look at from 29Deg 29Min 28Sec but it seems not alright as the iOS simulator shows!


Can anyone help me on this? How do I have to prepare my sprite to fit well on my isometric map?


Those who have experience with isometric map games are welcome to answer and I really appreciate it.


Here is the code I wrote in python to render the 3D Model, I have also set the camera to Orthographic manually.


Isometric Map


Math



import bpy
cam = bpy.data.objects["Camera"]
def look_at(cam, point):
loc_camera = cam.matrix_world.to_translation()
direction = point - loc_camera
# point the cameras '-Z' and use its 'Y' as up
rot_quat = direction.to_track_quat('-Z', 'Y')
# assume we're using euler rotation
cam.rotation_euler = rot_quat.to_euler()
meshObj = bpy.data.objects["plate"]

meshObj.rotation_mode = 'XYZ'
#meshObj.rotation_euler = (0,0,0)
d = meshObj.dimensions
# Finding maximum dim of the object
objectScale = 1
if d[1] >= d[2]:
objectScale = d[1] / 16
elif d[2] >= d[1]:
objectScale = d[2] / 16
cam.rotation_mode = 'XYZ'

cam.location = (20.416*objectScale,20.416*objectScale,20.416*objectScale)
#cam.rotation_euler = (0.7853,0.7853,0.5147)
cam.rotation_euler = (0.7853,0.7853,0)
look_at(cam, meshObj.matrix_world.to_translation())
alamp = bpy.data.objects["Lamp"]
alamp.location = (17.416*objectScale/4,17.416*objectScale/4,20*objectScale/4)
print("Scaling ",objectScale)
bpy.context.scene.render.filepath = "/Users/iman/Documents/Render/ISOBUILDING.png"
bpy.ops.render.render(write_still=True, use_viewport=True, scene="Camera”)

Answer




Well, the problem was that my sprites size weren’t a multiple of 32 so the scale and the geometric calculation were not as accurate as I expected to be. Theoretically it had to work! But it didn’t.


I used someones advises and it works fine now. here is the answer that I found for my question


http://flarerpg.org/tutorials/isometric_tiles/


And this is the result: Result


Hope it helps someone, and save some time for him/her.


pronouns - Difference between myself and by myself


Could you please explain me which option should I use?



I would like to have a green house with rare plants from all over the world. I could take care of them (myself / by myself)?



And why?



Answer



They're both correct, but they mean slightly different things.


In "I could take care of them myself", the myself emphasizes that I'd be the one taking care of them, as opposed to someone else. It doesn't really change the meaning of the sentence, it just emphasizes a certain aspect of it.


In "I could take care of them by myself", the by myself means "without help from others".



Friday, November 20, 2015

Effective marketing strategies for independent game projects




I would really like to hear how other independents generally approach marketing their game with limited resources. I know how critical marketing is since I've seen it first hand on several fronts. I've been part of teams that didn't put an ounce of marketing into their project and didn't come close to meeting expectations. I've also poured a lot of time into visiting forums to discuss our previous title which resulted in minor bumps over time.


I really think Wolfire is doing some amazing grass roots marketing with the way they are managing their community around their Blog. They've massed a following that is willing to pay (far in advance) them for their game before they finish it to help support them. That's awesome.


But how many people are really willing to divulge such information that early? Should that be a concern? Should I start talking about my next project before I really have anything implemented?



What has worked for you? I would be particularly interested to hear how people approach Apple's iTunes store. I believe we're looking at around 33,000 games on the store these days.



Answer



The Zero Budget Indie Marketing Guide is a great read. Besides that, definitely start building buzz as soon as you have anything to show, and do your best to keep the buzz up. Demos, trailers, articles, blog posts, whatever you can get to drive traffic and interest. From what I've heard, paid advertising is not very effective for indie games, so you may want to avoid it. Focus instead on building organic and genuine interest.


c++ - How to rotate blocks in tetris



I have a gameboard grid which is 20 rows high and 10 columns wide with the origin (0,0) being in the top left hand corner. I have a tetrimino in play, which is composed of four blocks. I have the x,y location of each block relative to the top left hand corner origin. I also have the position of the pivot, the point around which I wish to rotate which is relative to the top left hand corner origin.


Each block has an integer position in a gameboard square and thus the pivot has a fractional position inbetween blocks e.g (10.5,10.5)


My question is: Which formula can I use to rotate each block around the pivot?


I have already looked at existing similar questions and answers but could not find an answer that I could get to work.


Help would be much appreciated.




Is it reasonable to write a game engine in C?



Even though C++ appears to be king, from what I've been told C is still widely used in games, especially on the consoles. However, would writing an entire game engine in C be unreasonable today? What are, if any, some advantages that C has over C++? Why would someone possibly want to use C over C++?



Answer




However, would writing an entire game engine in C be unreasonable today?



It's reasonable, but the question is what does it buy you? You likely don't need the extreme portability C offers, and it's a shame to give up all of the features C++ offers unless you're really philosophically set against it.



What are, if any, some advantages that C has over C++?




Better compilation time?



Why would someone possibly want to use C over C++?



I think it's mostly an aesthetic choice. Many people like C because it's simple and minimal and feels clean. C++ has a lot of nice features (namespaces alone make it worth using), but it's also big and messy.


Thursday, November 19, 2015

sentence construction - "whose apple is that" or "whose is that apple"


Are both of the following sentence structures correct?



Whose is that apple?


Whose apple is that?




Can the word order be shuffled like this? There does not seem to be missing any clarity in either sentence.


I guess I would use such different word ordering to be able to put emphasis on certain words:



Whose is that apple?


Whose apple is that?



But is it allowed?



Answer



Both are correct. In:




  • Whose is that apple?


"whose" is an interrogative pronoun and, syntactically speaking, the subject complement (SC). This can be demonstrated by the fact that the natural reply will be:



  • It (=That apple)'s mine. ("mine" is a possessive pronoun and the SC of the sentence).


Instead, in:



  • Whose apple is that?



"whose" is an interrogative determiner that accompanies "apple". The whole phrase, "whose apple", is the SC. Proof of this is that the natural reply will be:



  • It/That's my apple. (where "my" is a possessive determiner that modifies "apple", with the whole phrase, "my apple", being the SC of the sentence.)


opengl - Why is programmable pipeline( GLSL ) faster than fixed pipeline?


So I'm teaching myself GLSL and am trying to figure out why it's suppose to be faster than the fixed function pipeline.


The reason I am having a problem is that from my understanding , the shaders you create are replacing sections of the pipeline that were there before. So, how's simply providing your own version speeding things up?


The only thing I can think is if you tried to supply say your own lighting equation before, you would have to do the calculation on the CPU, but now you can do the calculations on the GPU which will be faster.


Am I understanding this correctly?



Answer



Shaders you create aren't going to be your own version of fixed-function pipeline(FFP), but a custom vertex- and pixel-manipulating operations to achieve something cool and complex.


Many things you do via programmable pipeline(PP) will work faster than their possible FFP implementations, because PP reduces the number of passes or amount of combiner and cubemap magic required to render these hypothetical things in FFP.


Imagine implementing such a common thing as per-pixel lighting in FFP with only interpolated vertex data and sample texture in your hands. It's not even possible to do it "honestly", only hacks for special cases depending on faithful precalculated cubemaps and some serious blending. With PP it becomes a matter of colorizing a dot product between light direction and vertex normal.



All in all, PP turns slow and impossible into fast and possible. But if you decide to write a shader to implement the same algorithms used in FFP, you would find out that FFP will be slightly faster because it's very hardware-optimised.


path finding - How to handle pathfinding on a non-grid/non-node terrain map


I'm not sure if this is even path-finding. All I have is a 3D map that has hills, etc. I'd like the enemy to flock an object, but also walk around other objects. These blocking objects may be added after the path is calculated, which would cause a re-calculation of the path.



What algorithm am I looking at here?




modifiers - Does the sentence "I am surprised" have the pattern (S+V+C)?



I am confused about this sentence pattern (S+V+C):





  1. I am surprised [ to see you ].




  2. I am surprised [ at how many have never heard of it ].





  3. I am surprised [ by his response ].




  4. I am surprised [ that some people study the past ].





I think that the sentence "I am surprised" has the sentence pattern "Subject + Verb + Complement".


So the phrases following the complement should be adverb phrases, because they modify the complement (surprised), right?


But the sentence "that some people study the past" is a nominal clause. It should be unable to modify the complement (surprised).



So why are these following phrases able to modify the complement?



  • to see you

  • at how many have never heard of it

  • by his response

  • that some people study the past




british english - Have got in BrE



I am really confused now, so I've found out that:


Facts :


HAVE GOT is only used in the present and past form.


the plain "have" is used in all tenses.


HAVE GOT cannot be combined with the modal verbs such as :must, may, might, can, etc. and can't be combined with to+infinitive.


Only the plain "have" can be combined with the modal verbs & it can be combined with to+infinitive. ex. I want to have a pair of shoes (or) I want to have got a pair of shoes.


HAVE GOT and the plain "have" are used in BrE. (Do BrE natives use both ? Could you explain the differences between them?)


The pattern


A. HAVE GOT : I have got.. & I haven't got..& have I got (in the negative, haven't I got ___ ?)


B. HAVE : I do have.. / I have.. & I don't have.. & do I have? (negative, don't I have?)



C. past : I had got /(I did have) I had & I hadn't got /I didn't have & had I got (hadn't I got?), did I have? ( didn't I have?)


Are these facts correct? I await your explanations, thanks.




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...