Wednesday, February 28, 2018

3d - How to render metaballs?


How to render metaballs?
I am a Python programmer familiar with the Panda3d and Blender3d APIs. My math kinda sucks, but I know enough to write game logic code and procedural model generation code, as well as importers/exporters for the 3d modeller Blender. So you kind of get my level of experience. So can anyone explain or link to a tutorial which explains what needs to be done, without advanced math or with mentioning what math concepts are needed?


This is what I want to achieve:


http://www.youtube.com/watch?v=dEipENLes10
http://www.dailymotion.com/video/xn3xfn_mercury-meltdown-psp-un-trailer-pour-mercury-meltdown_videogames?search_algo=2


Though with probably more metaballs on screen at the same time.




architecture - Handling AI with ECS in a turn based roguelike


I am trying to implement the Entity Component System pattern to use in a roguelike game. Right now, I have 3 systems. Input, AI, and Action. The input system basically is just a system used by the player to get input from the keyboard. The AI system is for the NPCs. The action system processes anything with an Action component, which is used to describe either a move, an attack, an item usage, basically anything that advances the game time.


However, I am having trouble with implementing the correct behaviors. It is clear that the player should have a turn, getting his input. If the input is invalid, he repeats his turn, again and again until he makes a turn that passes time. Then the enemies should get their move from the AI system, and initiate it. So what the behavior should be like is this:


while(!input.passesTime())
input.getInput()
draw()
action.do(Player)
for all Entities with AI
AI.think(Entity)
action.do(Entity)

draw()

Notice how everything is intertwined and doesn't really make sense as a single (or multiple) system. How can I design this better? Note especially that I need to update the screen everytime, even with invalid inputs since they may write something out (e.g. "Nothing interesting happens").


After some thinking it seems clear that the renderer should also be a system, but this doesn't really clear up the requirements.



Answer



Note: I'm playing fast and loose with the pseudocode here, so let me know if anything is unclear.


Ideally, the player shouldn't be special - just another set of components. The main function of entities is to group components. You might think of it this way: components get updates, not entities.


From the good old Evolve Your Hierarchy article:


enter image description here


Updates flow down from the Component Manager, and entity association flows across.



So, you'd start from something like this:


while(running)
turn = timer.Now // or something, time management is another problem altogether
foreach ComponentType in ComponentManager ordered by ComponentType.UpdatePriority
foreach Component in ComponentType
Component.Update(time)
foreach Component in ComponentManager.AllComponents ordered by Component.DrawPriority
if Component is Drawable
Component.Draw(time)


Note the complete lack of references to entities in this loop! The update and draw methods are really the only two special cases you need, and we only tolerate draw being separate as an optimization in the face of system limitations (it's generally better to try and group draw calls, and draw doesn't need to be called every pass) - it's not architecturally ideal. If each component has a reference to its parent entity, it can talk to the other components on its parent entity and there's no need to pass the entity as an argument to its update method. There's no need to have special methods for each component either, since that could just be wrapped into a uniform set of method declarations:


Input.Update(time)
getInput()

AI.Update(time)
think()

Rule of thumb: if you can wrap it, you can combine it into a generic method shared by similar classes.


So, your class hierarchy should look something like


class Component { Update(), parentEntity }

class Drawable : Component { Draw() }
class Entity { Components }
class AI : Component { Update() { /* think stuff */ } }
class Action : Component { Update() { /* do stuff */ } }
class Input : Component { Update() { /* get input and pass it on to other components */ } }
// etc.

Since this is a turn based game, you'll probably want a game keeper component like


class GameKeeper : Component
{

Update(time)
{
if isOdd(time) currentTurn = Player
else currentTurn = Cpu
}
// or use events
TurnFinished(entity)
{
if entity == PlayerEntity
currentTurn = Cpu

else currentTurn = Player
}
}

Then


class AI
{
Update(time)
{
gamekeeper = FindComponent(GameKeeper)

if gamekeeper.currentTurn != Cpu
return
// otherwise think stuff
action = parentEntity.GetComponent(Action)
action.Do("Some action")
}
}
class Action
{
Do(message)

{
// Get ready to do whatever is in the message
}
Update(time)
{
gamekeeper = FindComponent(GameKeeper)
if gamekeeper.currentTurn != Cpu
return
// actually do all the things
}

}

architecture - Implementing a 3d tile engine


I have a pretty decent experience with tile based 2d games and I would like to try to create a mixed 3d-2d game. To 3d elements will be very simple (ground, walls and water), all other elements will be 2d sprites drawn onto this 3d map. (I am envisioning something similar to Final Fantasy III for iPad, top down view, always the same angle)


Now, here is my question: What are the technical aspects of implementing a 3d tile engine? Are there some good examples on how to do this? Basically I would like to create the maps the same way that I would do in a 2d tile based game.



Answer



It's actually quite similar to a 2D tile engine. You need to create the level somehow (i.e.: procedural generation or a map saved into a file that you created in an editor). Then you need to read that data, create the tiles and transform them to the appropriate locations and rotations. Draw only the tiles or polygons that are visible on screen (frustum culling) to keep the performance snappy.



Depending on whether your play area includes tiles at varying heights, you will need to find a solution for defining the collision bounds of the floor, walls, and platforms. Include collision data in each tile or, better yet, simplify that data and store it elsewhere to enjoy both memory and performance savings.


I hope this answered your question!


word choice - When to use "of", "in" and "at"?


I never know how to use prepositions like of, in or at.


What's the rules for each one of then?


My last doubt was about this sentence:




  • Order of importance

  • Order in importance

  • Order at importance


What's the correct option? Could you help me with the rules for each one of them?


Thanks a lot!



Answer



There won't be any simple rule we can tell you here that will tell you the right way to use words like these in every case. I can tell you this:





  • Most of these short prepositions have multiple meanings. The exact count will vary according to which dictionary you're looking at, but, according to this dictionary, of has 9 meanings, at has 6, with has 10, through has 10, in has 17, and on has 17 as well.




  • In addition to these high numbers of basic definitions, most of these words are used in idioms and phrasal verbs as well. Most people will tell you that on means “atop of” (and it does, when we say something like, the book is on the table), but, in addition to that meaning, we say things like on the radio, on the telephone, on the bus, on time, on trial, on hold, and on account of, and none of those expressions imply that anything is atop of anything else.




  • There are times when more than one word can be used, and the difference in meaning would be slight or negligible, such as, we had to meet Bob at the church on Oak Street (I could just as easily say, we had to meet Bob in the church on Oak Street; the latter would imply that we met inside the church, as opposed to outside in the parking lot, but, grammatically, I can still meet Bob at the church by meeting him inside the church).




  • When trying to determine the most common word used in an expression, Ngrams can be a good tool to use. When using Ngrams, though, be sure to look through the results as well, to find matches in contexts you might not have thought about. Such knowledge might prompt you to change your Ngram search to something more specific.





difference - I had something done vs I got something done


I have discovered that when you dont do something yourself but you make someone else to do it, you can say either:


I had my hair cut. OR I got my hair cut.


I wonder whether those two have exactly same meaning and usage. Is one form more common than other? More formal? More suitable in some situations?



Answer



Meaning: In the context of hair cuts specifically, you can use both without concerns as it is (usually) obvious that people get their hair done by others. (Unless it's very obvious someone did it themselves :))


However, in other situations (especially formal) I would be a little bit more attentive to which one of those I use:



Hey Sam, what about the mail I asked to be sent by this afternoon?




If Sam did it himself, he'd usually say:



I got it done



(If Sam doesn't have to use either of "got it/had it" he'd just say "I did it/I sent it" to avoid any potential confusion)


If Sam had someone do it for him, he'd usually say:



Don't worry, I had that one done / I had it done / I had it sent



Or




I got someone to do it for me


(more casually: I got someone to do it)



"Got it done" usually means that the speaker carried the action himself. "Had it done" almost always means that someone else had done it on the speaker's behalf.


Formality: "I got my hair cut" is the more casual way to phrase it.


Tuesday, February 27, 2018

word meaning - What is the difference between "some" and "little"


What is the difference between "knowing little knowledge" and "knowing some knowledge"? I'm confused.


At the afternoon club, the speaker talked about 'how fairy tales began'. This is a very interesting subject. For me, I am not in the category "I have NO knowledge of the subject matter" but I am in the category of having some knowledge of the subject matter ie I know how fairy tales began. Which is a better description?




meaning - Is there a rule which may indicate us when to use "BROAD" and when to use "WIDE"?


Could anybody tell me please if there is a rule which may indicate us when to use "BROAD" and when to use "WIDE?


1st example: I know it is correct to say "broad daylight" but is it wrong to say "wide daylight"?


2nd example: "world wide" is correct, but what about, "world broad"?


3rd example: "Wide-awake" is correct, but could "broad-awake" be also correct?



Dictionaries are unable to explain this or if there is a rule. Can you help please?




Why does Unity in 2d mode employ scaling and the default othographic size the way it does?



I previously used SFML, XNA, Monogame, etc. to create 2d games, where if I display a 100px sprite on the screen, it will take up 100px. If I use 128px tiles to create a background, the first tile will be at (0, 0) while the second will be at (128, 0).


Unity on the other hand, has its own odd unit system, scaling on all transforms, pixel-to-units, othographic size, etc, etc. So my question is two-fold, namely:



  1. Why does Unity have this system by default for 2d? Is it for mobile dev? Is there a big benefit I'm not seeing?

  2. How can I setup my environment, so that if I have a 128x128 sprite in Photoshop, it displays as a 128x128 sprite in Unity when I run my game?


Note that I am targeting desktop exclusively.



Answer



Handling 2D coordinates and scaling in Unity is fairly simple, but non-obvious and as you've noticed it's unlike how other dev tools work. Why this happens is because Unity was a 3D engine that recently had 2D graphics grafted in.


In particular, 1 unit in Unity is not necessarily 1 pixel in the image. When you import images as 2D Sprites there's actually a Pixels-to-Units setting that could be made 1:1 but I recommend leaving it at the default 100:1 for a couple reasons (the physics engine doesn't work right at 1:1, and the default is better for compatibility with others' code).



This scaling setting means that all positions are divided by 100. It's pretty easy as long as you always remember the scaling; when you want to move a sprite 256 pixels (say) then you move it 2.56 You may also want to write a utility function to round numbers to 2 decimal places/the nearest pixel: Mathf.Round(float * 100) / 100f




As for setting up a pixel-perfect camera, first off set it as an orthographic camera. When you select the camera, in it's settings is a drop-down for Perspective or Orthographic projection; perspective means things will look 3D, while orthographic displays the scene flat. Right under this drop-down is Size; set the camera's orthographic size to half the pixel dimensions of the screen you want.


For example, let's say you want a pixel-perfect 1024x768 screen. Well that means the camera height should be 384 pixels. Divide that by 100 (because of the pixels-to-units scale) and you get 3.84 for the camera size. Again, that math is simply SCREEN_SIZE / 2 / 100f




(I was waiting to see what other answers come first, but it's been a couple days. I've been doing 2D in Unity for a while using 2D Toolkit, but am relatively new to the built-in 2D features)


Monday, February 26, 2018

When do I copyright a game?




I don't know how to copyright a video game idea.


I don't know if I should make a game document and get that copyrighted first or make the game then copyright it.


The main gist is.. I am lost.




unity - MySQL for MMO-Development... What do i have to consider ?


Im currently developing an little mmo. Its pretty basic, players can walk around... gather some resources... build some simple buildings and craft things.


Before i began to develop i read a lot about benefits using MySQL... Now im not sure if MySQL was the right choice for such a project.


Currently i store player specific data in real time, that means... once a player crafted, builded or gathered something, a server request is send which triggers a MySQL - Query to insert a new Row into the specific table. This happens everytime a player moves, crafts, gathers or builds something.


I dont only store player-specific data in those tables... also world specific data, for example if one player visits a zone which was last updated 6 hours ago, i refresh this zone with resources and mobs. The server is generating them and after that, it inserts them as a bulk into the database.


With only one active player this works fine... but i have no idea if this will still work with dozens or hundreds active players at the same time. The serverside itself is able to handle them... but i have no idea if the database is able to.


I also heard bad stuff regarding table locks... That this is somekind of major iusse using MySQL, how does this effect dozends of database actions per seconds ? And could possible "share" be a solution for this ?


What else do i need to consider while using MySQL for a mmo ?



Answer




Overusing the database like this is usually a very bad idea.


Database queries always require a network roundtrip between game server and database server. Even under ideal conditions (both run on the same physical server), those latency times are still magnitudes larger than accessing data you have in RAM.


So only use your database for data at rest. Use it to suspend the states of players who are currently not online. But any data about the players currently in the game should be in the game servers memory.


You might want to regularly suspend the ingame players so you don't lose too much game progress in case of a server crash. But this should happen every few minutes at most.


Sunday, February 25, 2018

mathematics - Comparing angles and working out the difference


I want to compare angles and get an idea of the distance between them. For this application, I'm working in degrees, but it would also work for radians and grads. The problem with angles is that they depend on modular arithmetic, i.e. 0-360 degrees.


Say one angle is at 15 degrees and one is at 45. The difference is 30 degrees, and the 45 degree angle is greater than the 15 degree one.



But, this breaks down when you have, say, 345 degrees and 30 degrees. Although they compare properly, the difference between them is 315 degrees instead of the correct 45 degrees.


How can I solve this? I could write algorithmic code:


if(angle1 > angle2) delta_theta = 360 - angle2 - angle1;
else delta_theta = angle2 - angle1;

But I'd prefer a solution that avoids compares/branches, and relies entirely on arithmetic.




Saturday, February 24, 2018

conjunctions - "as essential a part of the weekly shop"



To the Dutch, milk and cheese are staples, as essential a part of the weekly shop as rice is for a Chinese shopper or teabags are for an Englishman.



This is a sentence from an article on CNN. I don't understand why it is not "an essential part of the weekly shop".


Can you tell me about any rules or grammar in this phrase, please?



Answer



I've posted an answer to a related question once. Let me quote the related part again here:




14 adjectives (3): position after as, how, so, too
After as, how, so, too and this/that meaning so, adjectives go before a/an. This structure is common in a formal style.
​  as/how/so/too/this/that + adjective + a/an + noun
​  I have as good a voice as you.
​  ...


(Practical English Usage by Michael Swan)



It's a normal as ... as pattern as Stephie said.
What's probably not normal for many learners is the pattern adjective + a/an + noun.


But if we think about it, it's probably not that strange. For example, I'm sure that you're fine with this one: I have as many books as you (have). It could be a little tricky for learners when the noun inside of as ... as is singular, but It's just that we don't hear it as often as as + adjective + as (e.g., This book is as good as that book).



(To the Dutch, milk and cheese are) as essential a part of the weekly shop as rice is for a Chinese shopper or teabags are for an Englishman is perfectly grammatical in English.


meaning in context - "The finer points"


According to definitions 1 and 6 for "point" in this dictionary:



def 1: a single fact, idea, or opinion that is part of an argument or discussion
def 6: a particular quality or feature that something or someone has




The definitions include the following example sentences:



def 1 sentence: They spent the evening discussing the finer points of (=the small details of) world politics.
def 6 sentence: They would spend hours discussing the finer points (=small details about qualities and features) of various cars.



It seems that the sentence for definition 1 could have the meaning of definition 6 and the sentence for definition 6 could have the meaning of definition 1. So, if I just write the following:



They spent hours discussing the finer points.



it seems there is no way to determine which definition of "point" to use here. Am I wrong?





Multi-tile agent path-finding algorithm?


Suppose we have a uniform rectanglular grid as shown below. The a is an agent, o is obstacle and g is goal. What are the options of handling multitile agents (e.g. dragons or tanks)?


.  .  .  .  o  .  .  .
. . . . o . g .
. a a . . . . . <-- too tight
. a a . o . . .
. . . . o . . .

. . . . . . . . <-- should go through this gate
. . . . . . . .
. . . . o . . .

Update: Found this article on clearance-based pathfinding from Red Alert 3. It covers not only the clearance - size, but also a capability - ability of certain units to use certain terrains.



Answer



The simplest approach I can think of is to designate one tile of the vehicle as the basis point which determines where the vehicle is, and for each potential position in a path, calculate whether the vehicle can fit in the space around that tile, and if not, reject that position as a possibility. Basically the check for whether a tile is passable or not changes to a check whether the given vehicle collides with anything while in this position or not.


For example, if you chose the top left of vehicle 'a' as the basis tile, when you evaluate a node you'd also check the one below it, the one to the right, and the one below and to the right. In this case the obstacle below the basis tile would collide and so this position would be rejected. (In fact, you'd not even get that far, as all positions 1 square to the left of the small gate would also be rejected.)


writing - When we write, do we have to write "OK" instead of "Ok" or are both correct?


I'm confused when I have to write "Ok" in a writing, because I don't know if "OK" and "Ok" are both orthographically correct or just one is.



Answer



OK is the abbreviation for oll korrect or orl korrect representing all correct. There are numerous explanations for the origin of the expression as suggested by the linked Wikipedia article.


You don't write Usa or USa for USA because USA is the abbreviation for the United States of America.


However, there are many forms of abbreviations in English and there is no hard-and-fast rule. For example, you abbreviate mister to Mr. or Mr and Doctor of Philosophy to PhD.


You could write Ok or ok in a text message or informal writing, but you should use one of the following three in formal writing. I would prefer OK to O.K..



OK



okay


O.K.



difference - "Mobile homes" in American and British English


I'm always getting these types of mobile homes mixed up. Could someone please explain the difference between the following?



  1. A mobile home. Is this any home that can be towed by a car? Is this commonly used in both dialects?

  2. In the US: recreational vehicle sometimes called an RV.

    Which of the two names is more common in the US? Are British people familiar with this term? If not, what's the most common name for this type of home in the the UK?


  3. A caravan, either the colourful gypsy caravan, or the British English one. I don't think Americans use this term. What would it be called in the US? Is it No.4?




  4. A trailer is this also another name for a "recreational vehicle"? What's the difference?




  5. In Italy the term ‘il camper’ is used for most types of holiday homes driven by motor vehicles. Do British people and Americans use this term? What is the difference between a camper and a caravan? Is one term more outdated than the other?






Answer



I can give you a British English definition as I own such vehicles...


A caravan is a trailer towed by a car:


Caravan


A camper van (or campervan) is a van of ~1 ton converted for sleeping & cooking. These are typically VW Transporters or Mazda Bongos. There are still huge numbers of lovingly preserved VW campervans on the roads (I have a classic T2 and a T5):


Campervan


A Motorhome is a purpose built vehicle, larger than a campervan. These are coachbuilt onto a commercial chassis. The chassis are usually Peugeot or Fiat. They come in varying sizes but are rarely more than 3tons:


Motorhome


You will find people "in the scene" who get very picky about how their vehicles are described. Some people will get upset if you refer to their motorhome as a camper for example.



We British do recognise the term RV as being an American equivalent. However, in Britain, when applied to British vehicles, the term is usually only used for the very large:


Large RV


Friday, February 23, 2018

Is there subject missing in as-clause?




Perhaps my favourite thought in the book - certainly the one that resonates with me most - is the passage where Anne talks of longing to have a dress with puffed sleeves, a desire which, of course, Marilla will not even entertain. Anne declares that she will just imagine that her dress has puffed sleeves, which works very well until she arrives at Sunday school. ‘They all had puffed sleeves. I tried to imagine mine were puffed, too, but I couldn’t. Why couldn’t I? It was easy as could be to imagine they were puffed when I was alone in the east gable, but it was awfully hard there among the others who had really truly puffs.’


-- Introduction by Lauren Child, L. M. Montgomery, Anne of Green Gables



It seems like subject "I" is missed after as, and the as-clause is, so called, the real subject of the sentence. Is this right?



Answer



It does imply a deleted subject, but that subject is not ‘I’


As can be, as could be was a common colloquial construction down into the early 20th century, but you don't hear it now so much as you used to. It means approximately as it is possible to be and implies a deleted ‘generic’ subject. It is used after an adjective and implies an as before that, which may be deleted.



It was easy as could be to be imagine ... = It was as easy as it could be to imagine ... The deleted subject is quasi-anaphoric here, since it is the same it as begins the sentence.


Your little girl’s just sweet as can be! = She’s just as sweet as [any such child] can be.




You sometimes see this with the adjective duplicated, for emphasis:



He’s mean as mean can be.



A similar construction is used in a non-comparative sense with other modals. See this question on ELU for That’s as may be = ‘That may be true’. You occasionally run across That’s as will be = ‘We will eventually see whether that comes to pass or not’.


In all of these be signifies


articles - D.Trump was elected president or "a" president


Some of you told me that when we put an article before president (a), we are referring to a specific position, but when we don't put an article, that means we are referring to a general position.



Trump was elected president.




Is president here is a general position?




past tense - I didn't ('go' or 'went') to party?




  1. I didn't go to party.

  2. I didn't went to party.





Thursday, February 22, 2018

xna - Orienting a model to face a target


I have two objects (target and player), both have Position (Vector3) and Rotation (Quaternion). I want the target to rotate and be facing right at the player. The target, when it shoots something should shoot right at the player.


I've seen plenty of examples of slerping to the player, but I don't want incremental rotation, well, I suppose that would be ok as long as I can make the slerp be 100%, and as long as it actually worked.


FYI - Im able to use the position and rotation to do plenty of other things and it all works great except this last piece I cant figure out.


Code samples run in the Target's class, Position = the targets position, Avatar = the player.


EDIT


Im now using Maik's c# code he has provided and it works great!




Answer



There are more than one ways to do it. You can calculate the absolute orientation or the rotation relative to your avatar, that means your new orientation = avatarOrientation * q. Here is the latter one:




  1. Calculate the rotation axis by taking the cross product of your avatar's unit forward vector and the unit vector from avatar to target, the new forward vector:


    vector newForwardUnit = vector::normalize(target - avatarPosition);
    vector rotAxis = vector::cross(avatarForwardUnit, newForwardUnit);


  2. Calculate the rotation angle using the dot-product



    float rotAngle = acos(vector::dot(avatarForwardUnit, newForwardUnit));


  3. Create the quaternion using rotAxis and rotAngle and multiply it with avatar's current orientation


    quaternion q(rotAxis, rotAngle);
    quaternion newRot = avatarRot * q;


If you need help finding the avatar's current forward vector, the input for 1. just shoot :)


EDIT: Calculating the absolute orientation is actually a bit easier, use the forward vector of the identity-matrix instead of avatars forward vector as input for 1) and 2). And don't multiply it in 3), instead use it directly as the new orientation: newRot = q





Important to note: The solution has 2 anomalies caused by the nature of the cross-product:




  1. If the forward vectors are equal. Solution here is simply return the identity quaternion




  2. If the vectors point exactly in the opposite direction. The solution here is to create the quaternion by using avatars up axis as rotation axis and the angle 180.0 degrees.





Here is the implementation in C++ that takes care of those edge cases. Converting it to C# should be easy.


// returns a quaternion that rotates vector a to vector b
quaternion get_rotation(const vector &a, const vector &b, const vector &up)
{
ASSERT_VECTOR_NORMALIZED(a);
ASSERT_VECTOR_NORMALIZED(b);

float dot = vector::dot(a, b);
// test for dot -1
if(nearly_equal_eps_f(dot, -1.0f, 0.000001f))

{
// vector a and b point exactly in the opposite direction,
// so it is a 180 degrees turn around the up-axis
return quaternion(up, gdeg2rad(180.0f));
}
// test for dot 1
else if(nearly_equal_eps_f(dot, 1.0f, 0.000001f))
{
// vector a and b point exactly in the same direction
// so we return the identity quaternion

return quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}

float rotAngle = acos(dot);
vector rotAxis = vector::cross(a, b);
rotAxis = vector::normalize(rotAxis);
return quaternion(rotAxis, rotAngle);
}




EDIT: Corrected version of Marc's XNA code


// the new forward vector, so the avatar faces the target
Vector3 newForward = Vector3.Normalize(Position - GameState.Avatar.Position);
// calc the rotation so the avatar faces the target
Rotation = Helpers.GetRotation(Vector3.Forward, newForward, Vector3.Up);
Cannon.Shoot(Position, Rotation, this);


public static Quaternion GetRotation(Vector3 source, Vector3 dest, Vector3 up)
{

float dot = Vector3.Dot(source, dest);

if (Math.Abs(dot - (-1.0f)) < 0.000001f)
{
// vector a and b point exactly in the opposite direction,
// so it is a 180 degrees turn around the up-axis
return new Quaternion(up, MathHelper.ToRadians(180.0f));
}
if (Math.Abs(dot - (1.0f)) < 0.000001f)
{

// vector a and b point exactly in the same direction
// so we return the identity quaternion
return Quaternion.Identity;
}

float rotAngle = (float)Math.Acos(dot);
Vector3 rotAxis = Vector3.Cross(source, dest);
rotAxis = Vector3.Normalize(rotAxis);
return Quaternion.CreateFromAxisAngle(rotAxis, rotAngle);
}

passive voice - Being taken and being beaten


In the previous question I was told that these sentences are clumsy and their meanings are confusing:




  • Being taken to the hospital, he survived.





  • Being beaten by the snow, he died.




Can I convert these sentence into meaningfull sentences as follows:




  1. Being taken to the hospital, he died.




(To mean: while he was being taken to the hospital, he died)




  1. Being beaten by mother to her son, the father arrived.



(To mean: While the son was being beaten by his mother, the father arrived)


and,


Do I have to use "while" in front of "being+past participle in above sentences to imply those intended meanings?




articles - Software, countable or uncountable?


I have come across an article titled " Scientists have invented a software that allows you to see several minutes into the future".


Software is an uncountable noun. Don't we usually say" a piece of software" instead of "a software"?




Answer



Yes, good catch. There's a mistake in the article you read. It is likely that the person who wrote the article is not a native speaker of English.


Another way to write it would be



Scientists have invented software that allows you to see several minutes into the future.



3d - How can large terrains be represented in multiplayer games?


To give you a bit of context, I often try and imagine how big games are working, especially networked and multiplayer games. This is how I came to this question: how do big 3D multiplayer games load their 3D, predefined maps? (I am not talking of generated ones, such as in Minecraft, but defined maps that represent, for example, a kitchen).


The most viable hypothesis to me are:





  • Some basic map terrain is loaded in a .obj file (with just variations of height and of ground material), and then more data (like trees) is added according to another file, stored in a format like xml, which also contains paths to other obj files. This techniques therefore allows modifications of terrain, as well as something like serialization to send data to a new client joining (but it's really heavyweight and hard to implement). Finally, you can base player position on which tile they are, and make easier collision & al (for RTSs for example).




  • A map containing all data in a single .obj file is loaded by all clients, and they are just allowed to move inside it (is this the case in FPSs like Quake?)




But I think both of these techniques aren't optimized enough for commercial or public use. Do you have any idea of how can these games load their map data?




Single clear word for 'hot food'


The question
In my native language we have two ways of saying the food is hot. One meaning spicy and one meaning too/very warm.


I am now looking for a way to use this sentence:




The food is ...{single word here}...



I want the meaning to be clear (the food is warm to the point where caution is recommended). If there is not a single word for this that is also fine, I could then at least start looking for better workarounds.


Thoughts so far
I always used 'hot' but that can easily be confused with spicy so I am currently using workarounds.


'Warm' can mean 'nice and warm' or 'too warm', so I am not satisfied by that either.




Wednesday, February 21, 2018

idioms - Have a seat, guys (have seats?)



Have a seat, guys



I think "have a seat" is a fixed phrase that does not change whether you address someone or a group of people.


Is that correct?



If you have more to add to the post, please do so as I would love to know more.




How to iterate over 25 Sprite Objects (Unity 5 - C#)


I wanna show a minimap on the screen. The minimap would look like this (bottom right corner, this was done time ago in Visual Studio):


Minimap


Have two problems with that, I have 25 Image objects created in the scene and 25 in the playercontroller script:


public Image minimap0, minimap1, minimap2, minimap3, ... , minimap24; 


but I can't make to change its sprite, and also, I don't know how to change all 25 objects sprite with a "for" loop (the foor will look like this http://imgur.com/qfi1Ht1 ).


The map is stored in an array for checking positions.




physics - Calculating initial velocities given trajectory parabola


I'm working on a volleyball game but my maths/physics knowledge isn't quite up to par. I need some help with the following problem:


The player can hit the ball from anywhere on the left of the court into one of three points on the right:



    P    | x  x  x

The ball travels in a parabola defined by the three points, all of which are known:



  • The players X coord and height (Xp, Yp)

  • The point just above the top of the net (0, Yn) (assume the left of the court is negative along the x axis)

  • The point where the ball impacts the ground on the other side of the net (Xi, 0)


I need to calculate the initial X/Y velocities when the player hits the ball so that the ball, affected only by gravity, follows that parabola. EDIT Alternatively, the velocity magnitude and angle from which the X/Y component velocities can be calculated.


I'm able to find the function of the parabola using pen and paper but since this involves "saving" equations with unknown variables I have no idea how to translate that to code (how could you have variable a = 2b for example if b is undefined?). I'm not even sure if finding the function is necessary for this problem.



Any help?


EDIT: I just came to the realisation that if I can calculate the flight time then I can divide the distance traveled each frame along the x axis and just plug that into the parabolic function to get the ball's y coordinate. I guess that's my next avenue of research.



Answer



To simplify the math, let's translate everything so the projectile starts at the origin (subtract player position from the other points). Translating the whole problem doesn't modify the velocity, so we don't need to do any compensation at the end.


P1 = point above the net - player position (reached when t=t1)
P2 = target point - player position (reached when t=t2)
v = initial velocity vector
g = gravitational acceleration vector

Then the general form of our parabola is...



P(t) = t * v + t*t * g/2

We can substitute t1 & P1, t2 & P2 to get...


P2/t2 - t2 * g/2 = v = P1/t1 - t1 * g/2

Since gravity only acts on the vertical axis (in this case), the x component is a bit simpler:


P2.x/t2 = P1.x/t1
t1 * P2.x = t2 * P1.x
t1 = t2 * P1.x/P2.x


(If by chance anyone wants to apply this formula to a case with arbitrary gravity direction, you can first form a local coordinate system with one axis parallel to the gravity direction and one axis perpendicular, solve there, then transform the result back to the original coordinate system)


Now we can substitute this into the above formula for the y axis and solve until we get...


t2 = sqrt(2 * (P2.y - P1.y*P2.x/P1.x)/(g.y*(1 - P1.x/P2.x)))

(If the inside of the sqrt is negative, then there is no ballistic arc joining the three given points with this gravity value. There might still be a solution if the point above the net is moved vertically)


Note that, because both P1.x and P2.x appear in denominators, this will behave badly if the player (and their target) can get right up to the net. You can either force the player & target to keep some minimum distance to the net, or fall back on a different approach for close-to-net shots.


Once you have t2 in hand, you can solve for v:


v = P2/t2 - t2 * g/2;

Note that this gives a lower bound for the time to hit the target. Increasing the time will result in higher arcs with more clearance above the net. (ie. they pass above P1 instead of passing through it)



Here's an animation of this method in action, moving the three points freely:


Drawing a parabola through three given points


gerunds - Stop+ Ving and Stop+ to+infinitive?




I have two questions here:



  1. To which action we can use Stop + gerund?

  2. And to which action we can use Stop + to + infinitive?



Answer



Stop:




  • Notice the difference between stop doing something and stop to do something - We stopped taking pictures means ‘We were no longer taking pictures.’;We stopped to take pictures means ‘We stopped what we were doing so that we could start taking pictures.’




(Oxford Learner's Dictionary)


Compare:


He stopped to look at the window shop. (He was walking and he stopped in order to look at the window shop)


He stopped looking at the windows shop. (He was looking at the window shop and decided not to look at it any longer)


word meaning - What does "have a pop-up feel" mean?




Support for the Rohingya cause across the region has a pop-up feel.



Source: Nouzie


I looked up pop-up in Merriam Webster:



1: pop fly


2: a component or device that pops up


3: a pop-up book


4: a pop-up window on a computer screen




I guess pop-up feel has to do with the first definition, so does it mean the support of the Rohingya is very high, as a pop fly is? Or does it mean something else?




word usage - 'Would' vs 'should', expressing expectation on the part of the speaker


Page 111 (77, Should expressing probability), Oxford Learner's Grammar - Grammar Finder:



We can also use should to say that something is probable, either in the present or the future.



I posted the letter ages ago. They should have it by now.


The journey normally takes four hours, so we should get there about six.




In the negative we use shouldn't.



We're nearly at the front of the queue. We shouldn't have to wait much longer.



Should has the additional meaning of ‘if all goes well’.



There are no reports of delays. The train should be on time.



But we cannot use it to predict that something will go wrong.




There are reports of delays. The train will probably be late. [NOT The train should be late.]




I understand this inferential usage of should and use it all the time. And I remember that would has such usage as well. It can be used to express presumption or expectation: That would be Steve at the door.


But few grammar books say much on this particular usage of would. It's probably the most intriguing and enigmatic usage of would, which prompts me to think when this usage is licensed in context: would it be possible to substitute would for should in the above examples?




I posted the letter ages ago. They would have it by now. #1


The journey normally takes four hours, so we would get there about six. #2


We're nearly at the front of the queue. We wouldn't have to wait much longer. #3



There are no reports of delays. The train would be on time. #4


There are reports of delays. The train would be late. #5




I don't think that "would" in all of these new examples have the same meaning as "should" in the original ones; so when is "would" licensed in the same way as in "that would be Steve at the door"?


Is this usage of "would" restricted to any verbs or contexts? I think it's not frequently used in this way.


Added:



9.8.3 Modal remoteness (from the Cambridge Grammar of the English Language, aka CGEL)


The tentative use:




i a. He'll be about sixty.


i b. He'd be about sixty.



The difference between present tense and preterite is much less tangible here than in (a) above: the preterite introduces a rather vague element of tentativeness, diffidence, extra politeness, or the like.


The intended context for [i] is that of answering such a question as How old is he? (we are not concerned here with the interpretation of [i b] as an implicit conditional, “He’d be about sixty now if he were still alive”).


In such a context the unmodalised He is sixty makes an unqualified assertion. Example [i a] is less assured: it involves what we have called the central-epistemic use of will.



The CGEL suggests it's a different usage of "would" from the hypothetical one, but fails to explain when "would" could be used that way.



Answer




These are all meaningful, but the meaning is changed and the context in which they could be used would be changed. "Would" is more often used to discuss expectations (that one feels certain about) in projected courses of action, rather than hopes or expectations in the current situation. You wouldn't use "would" there except in limited circumstances, when you are very confident in your predictions. I think a lot of this falls out of the use of "should" to describe model behavior or what is 'right' (like def. 3 here). Incidentally, I think (without proof) that that is why we don't use "should" to describe expectations that go awry, like the train being late: we certainly don't think that our hopes or expectations ought to be denied!




  1. with "should" is a prediction; with "would" the speaker is certain enough to, for instance, discount the possibility of it not having been received. ("They would have it by now, so that can't be the reason they haven't responded...")




  2. "should" states a probable expectation, while "would" is more like a certainty in a hypothetical plan ("We would get there by six, which would give us time to change before dinner...")




  3. is tough. "We wouldn't have to wait much longer" is an acceptable utterance with an appropriate context: if I'm making a case for my plan (staying in line) over your plan (leaving the line). The implied full thought is "we wouldn't have to wait much longer [if we agreed to stay]." Here we are discussing the expected-to-be-certain details of possible plans, rather than stating our hopes about the future.





  4. would work if you'd said "there were no reports of delays, the train would be on time [and that is why I am worried that your sister hasn't arrived yet]". This is related to sentence 1; I am stating a prediction about which I feel certain enough that I discount the train being late as a possible reason that your sister is delayed, and start worrying that something else could have happened to her.




  5. Meaning is completely changed--we don't use "should" to emphasize things that happen contrary to expectation. Sometimes "The train would be late!" (with emphasis) is used expressing frustration that the train is late. The resulting statement is whining. A more full example: "The train would be late on the day I have an interview! This always happens to me!"




So: the distinction as I see it is pretty much what your edited addition says. "Should" suggests a more tentative attitude than "would," which may be from genuine uncertainty, or from an attempt to be more polite or more emotionally removed.


Both "should" and "would" are used to discuss an event about which the speaker is not completely certain or confident. But "would" seems to have the implication of talking about the details of a hypothetical world, future course of action, proposed plan, etc. "Should" is used to make less confident predictions about the future.



Tuesday, February 20, 2018

grammar - How can I identify a word that ends with "-ing" as being a noun, a verb, or an adjective?


How can I distinguish between words which have the -ing in a sentence that are nouns, verbs, or adjectives?


For example sometimes -ing come with word to give us a noun, and sometimes a verb or an adjective.



That interesting snake.
That crawling snake.
That barking dog keeps everyone awake.



Is there any rule to determine whether a word with -ing is a noun, verb, or adjective?




grammar - The usage of "also": is it idiomatic put "also" at the end of a sentence in writing?


This video (https://youtu.be/38-K2rPu8fc?t=167) is talking about the usage of "also" and gives this example



She wrote three emails to him but he didn't answer, he ignored her calls as well.




And then the speaker substituted "also" for "as well", and said



"He ignored her calls also." It sounds weird but it's possible.



That does sound weird for speaking, the question is for writing.


Is it idiomatic put also at the end of a sentence in writing?


Note: My another post (The usage of "also": could someone please give an example to illustrate where is the location "after the verb to be when it is a full verb"?) is relevant though, they are talking about different questions. This one is focused on the location of the end of a sentence.




word usage - Is it correct to use an expression "we denote something by x"?


Consider the following two sentences.



(1) We denote the set of natural numbers by N.


(2) N denotes the set of natural numbers.



Both expressions are very common in math papers. According to the Oxford dictionary, the second expression is correct. See http://www.oxforddictionaries.com/definition/english/denote.


However, I prefer the first expression because of the following. To use the second expression, the symbol N should have appeared before without definition. Instead, I could use an expression such as




We let N denote the set of natural numbers.



But if I use this expression many times, somehow I feel I make duplications.


Now I am afraid if the first expression is incorrect. I googled and found some answers in the following links, but they are not very convincing to me.


http://forum.wordreference.com/threads/we-denote-by-n-an-integer-instead-of-n-denotes.2379959/


http://www.waywordradio.org/discussion/topics/going-against-convention-while-writing-in-your-field-denote-by/




plural forms - There's vs There are



For example:



There's two options here



or



There are two options here



I hear a lot of people say the first line (or something similar), but isn't that incorrect? Isn't it plural and therefore you should use "there are"?



Answer




Here's an edited version of a post I did for ELU on a similar question (which got closed):


The existential construction takes there as a subject. There has no meaning, and often the verb takes its agreement from the complement of the verb BE. So if the Noun Phrase after BE is plural, the verb will usually be in a plural form. If the Noun Phrase is singular it will usually be singular:



  • There is an antelope over there.

  • There are some antelopes over there.


Notice, however, that in the examples above, the subject and the verb BE are not contracted. In normal speech these will nearly always be contracted. We will use there's instead of there is. It is also quite common nowadays to see them contracted in writing, normally in informal texts, although you can find instances in prestigious newspapers like the Times, for example.


Now when the subject there and BE are contracted like this, the verb doesn't need to agree in any way with the following Noun Phrase. Therefore with regard to the Original Poster's example, if they had said:



*There is two options here.




... this sentence would be regarded as ungrammatical by most, if not all speakers. However because they did contract there and BE, it is grammatical:



There's two options here.



This makes this sentence similar to a famous lyric from one of John Lennon's songs:



Imagine there's no countries.



Or usages such as:




There's times when I've wanted to box his ears



Having said this, despite the fact that this is a well documented aspect of the grammar, some prescriptivists are bound to take offense at this. They will insist that it's ungrammatical to use a plural noun after there's. This will be despite the fact that they quite subconsciously actually use plural nouns after there's themselves quite frequently. They will appear about five minutes after I post this answer. They do make life fun though!


There are some other special situations where we might use there is with a plural noun phrase, even though it is not contracted. For example How many people live in your house? Well, there is me, my grandad, my mum and my aunt. If you'd like to read about these exceptions, there's some good posts here!.


unity - Ignore physics material on raycast shooting?


I created a cone in blender and added it to the head of an NPC in Unity as a field of vision detector. I disabled the mesh and just left the mesh collider. Now i realized i cant shoot the NPC when he is looking at me and the cone is in between us.


I have seen i can assign a physics material to the mesh collider.. Can i put a specific physics material on the cone and ignore it when doing a raycast (shooting) from the player on it (the npc)? I only found friction and bounciness options.




Monday, February 19, 2018

word request - What is this type of road called in English?


I’m looking for a word or a phrase for describing this kind of road which usually is constructed in the mountain areas, but not only:


enter image description here
image a representative sample from Google images, query = transfagarasan


In my language we call this serpentine a word used as a noun (not adjective) to describe its shape.


If I wanted to write an article about this road, a road constructed in the mountains provided with many turns and angles like in the above link, which word would be more appropriate to use?



Answer



Preface ADDED 14 Jan/Jan 14, 00:11 GMT/UTC: This answer, as the OP Lucian Sava is well aware, has been written from an AmE perspective. Actually, it is written from the perspective of the variety of AmE that I speak. I think Lucian gets by now that English usage is not universal, as I had already indicted in my anwer. Let the conversation continue, by all means!





Serpentine is fine, but in English I am pretty sure we would use it as an adjective describing the road. Such a road is also called, in familiar terms, a curvy mountain road. More technically, it is any road that contains many switchbacks or hairpin curves


Switchback can refer to entirety of such a road. But this may not reflect universal usage.


I think serpentine (adjective) would be the more universally recognized word.


You can do an image search for both "switchback road" and "serpentine road" and get many of the same images.


Thus saith the snake:


enter image description here


enter image description here


enter image description here


articles - "A fear of something" vs "fear of something"


According to the Cambridge Dictionary, the word "fear" is both countable and uncountable. So, when referring to the fear of flying, can I say:



I have fear (uncountable) of flying?






c++ - Rectangles render with gaps in between them (Box2D)


Right now I create my boxes where 1 meter is 85 pixels. Gravity is 10. And


                        fixtureDef.restitution = 0.1f;
fixtureDef.friction = 0.5f;

fixtureDef.density = 1.0f;

The problem I'm having is illustrated in the image I have provided: http://www.box2d.org/forum/download/file.php?mode=view&id=1044&sid=86e8772dc965cba215f9a16cca2839e4


As you can see, there is a small gap between many, but not all the crates. What could cause this?


Thanks



Answer



I guess that's some issue in box2d, there is such a bug to increase performance. since more accuracy needs much more computational power. to fix that issue I guess you only need reduce box physical sizes (for example you can create a 84px*84px rectangle for a 86px*86px image). you can also fade the pixels in the edges to get better results.


What is the difference between "I am from China" and " I come from China"?



I am from China.


I come from China.



What is the nuance between them? likewise:



Where are you from?


Where do you come from?




Are there any nuance between them?




Sunday, February 18, 2018

Entity Component System: system and components relation


I'm planning to develop a game in C# (but I don't think that language matters) and I'll be using Entity Component System since I know by design that my game will have a lot of different game items with different twisted behaviours and logics. I have some experience using Unity ECS which I find very easy and intuitive. I've also programmed games in the past using the old "inheritance approach" and I found that pattern very not scalable.


As far as I know, a pure ECS (which is not what Unity implements) works like this:



A GameObject is just a collection on Components, it may be seen as a wrapper class or as a shared index in some parallel arrays of Components.


A Component is a collection of data (basically a record) which holds the data needed by its relative System to handle it. It does not implements game logic itself.



A System is a world object which loop through each GameObject which has a component it can process and update game logic of that component.



My point is: if the Systems are the ones responsible for the actual game logic update (practically speaking, the game logic code is written inside the system), is there a 1:1 relation between every component and every system ? Let me explain with an example: let's say I have 2 components:



  • RenderSpriteComponent

  • RenderLightSourceComponent


The first one does a simple 2D sprite rendering (using OpenGL or whatsoever); the second one send a light source to the rendering shaders. They do similar operations but with some actual differences. My question is: since they behaviour is different, should I implement two different Systems which will handle them separatly? If not, should I add a bunch of IF statements or overloads to handle those two components inside the same System?


From my point of view both ways seem unnecessary, especially if the ECS should improve code scalability. Using one of those approach would force me either to implement a different system for each component I have (implying a lot of GameObjects loops) or either to fill my Systems with if and overloads making them impossibile to understand after a certain point.


Furthermore, from what I can see and understand, Unity implements a different version of this pattern in which every component implements its own logic (in the Update method) and the GameObject is a wrapper class which has an internal list of components to update. Systems don't exist at all (or if they do they do, they do so for other reasons). This implementation looks easier and more "elegant" from my point of view, but I can't understand why it's not so spread and everyone sticks to the "classic" ECS implementation which has those "problems" I've described above. At the same time, I do not have control over the priority of the components updates, which can be useful in some cases.



I understand there isn't an "absolute" better way to design your game structure, but I'd like to know how is generaly implemented. Or which factors would make a way better than the other.




Saturday, February 17, 2018

phrase usage - Is "prefixed by" correct?


When I write the following sentence, the grammar/spelling checker running on my Mac always suggests me to use prefixed to or prefaced with.



Functions implemented by a module should always have their names prefixed by the module name.




What I mean is that, if the module name is user, the function name should not be load(), but user_load().


Is it correct to use prefixed by, or should I use another phrase?



Answer



Both prefixed to and prefixed by are correct, but they have different meanings.


If A is prefixed to B, A is the prefix and B is what the prefix is added to. In this case the end result is A_B. To use your example, you could say that user is prefixed to load() to create user_load().


If A is prefixed by B, B is the prefix and A is what the prefix is added to. The result is B_A. For your example, you would say that load() is prefixed by user to create user_load().


To state this in more general terms for your entire project, you might make either of these statements:



Each method name related to the user object is prefixed by the string user.


The string user is prefixed to each method name related to the user object.




And concerning the sentence in your question:



Functions implemented by a module should always have their names prefixed by the module name.



It is indeed correct, because the suffix (function name) is prefixed by the prefix (module name).


Checking for collisions on a 3D heightmap


I have a 3D heightmap drawn using OpenGL (which isn't important). It's represented by a 2D array of height data. To draw this I go through the array using each point as a vertex. Three vertices are wound together to form a triangle, two triangles to make a quad. To stop the whole mesh being tiny I scale this by a certain amount called 'gridsize'.



This produces a fairly nice and lumpy, angular terrain kind of similar to something you'd see in old Atari/Amiga or DOS '3D' games (think Virus/Zarch on the Atari ST).


I'm now trying to work out how to do collision with the terrain, testing to see if the player is about to collide with a piece of scenery sticking upwards or fall into a hole.


At the moment I am simply dividing the player's co-ordinates by the gridsize to find which vertex the player is on top of and it works well when the player is exactly over the corner of a triangle piece of terrain.


However...


How can I make it more accurate for the bits between the vertices? I get confused since they don't exist in my heightmap data, they're a product of the GPU trying to draw a triangle between three points. I can calculate the height of the point closest to the player, but not the space between them.


I.e if the player is hovering over the centre of one of these 'quads', rather than over the corner vertex of one, how do I work out the height of the terrain below them? Later on I may want the player to slide down the slopes in the terrain.



Answer



Trying to interpolate across the triangles and working out which triangle to use was working, but it was strangely jittery if I used the data to move a player across the surface of my heightmap.


A bit of Googling turned up this page http://www.gamesandcode.com/blog/xna-project/rolling-the-ball which shows some XNA code for rolling a ball across a heightfield.


In that the code uses bilinear interpolation to work out the height based on the whole 'quad' which is accurate enough for what I want (and now I think about it, is probably what OpenGL is doing to draw these pieces of geometry anyway).



Here is the code I managed to create


(position.x and position.y are the player's co-ords, gridsize is the width of the 'quads' in GL co-ords)


    float xpos = position.x/gridSize;
float ypos = position.z/gridSize;

double intpart;
modf(xpos, &intpart);
float modX = (position.x - intpart * gridSize) / gridSize;
modf(ypos, &intpart);
float modY = (position.z - intpart * gridSize) / gridSize;


float TopLin = Lerp(GetHeightAt((int)xpos, (int)ypos),
GetHeightAt((int)xpos + 1, (int)ypos), modX);
float BotLin = Lerp(GetHeightAt((int)xpos, (int)ypos+1),
GetHeightAt((int)xpos + 1,(int) ypos+1), modX);
return Lerp(TopLin, BotLin, modY);

Lerp is a simple function that interpolates from a to b in steps of t (0 ... 1):


float Lerp (float a, float b, float t)
{

return a + t * (b - a);
}

shaders - How to make unit selection circles merge?


I would like to know how to make this effect of merged circle selection. Here are images to illustrate:


enter image description here enter image description here


Basically I'm looking for this effect:


enter image description here


How the merge effect of the circles can be achieved ? I didn't found any explanation concerning this effect. I know that to project those texture I can develop a decal system but I don't know how to create the merging effect.


If possible, I'm looking for purely shaders solution.



Answer




There are a few tricks you can do:


Z-buffer


After you have rendered all other objects, for each unit render a transparent circle of smaller size with max Z value. Then render selection circles decals on the ground. Since they are below in Z-order, they will be discarded when under units.


Being fully transparent means that the circle gets written only to Z-buffer (max Z value). Now when you render decals, they are tested against Z buffer values, and if they are passing the test they get rendered (which happens only outside of the circles)


Stencil


Same as with previous approach, but this time use a stencil buffer. Render smaller circles for units with some stencil value, then render selection decals. Setup stencil to discard any elements with your stencil value.


countability - Listing differnet kinds of an uncoutable noun. Are they countable or uncountable?


How do you I refer to different kind of an uncountable noun? For example, this is a part of my writing:




Using oil (coconut oil, olive oil) to moisturize your skin after bath. Those oil...



I want to explicitly refer to two kinds of oil to avoid other oil like engine oil mistakenly. Does those suit here? Are they countable? I think it's yes (look, I use they and them to refer to them in this sentence and the previous one). However, isn't that after using those, we should use the plural form of the noun? In that case, oils, not oil, should be use, right? And in that case, is oil a countable noun now?



Answer



Yes, you can use a plural. In this case, you're no longer talking about oil itself but about two different types/kinds/sorts of oil. With this construction, the noun becomes countable and can be put in the plural.


So, you should say: those oils Be sure not to forget the plural s after oil or your sentence will not be grammatically correct.


How can I figure out whether a word is an adverb or an adjective?


How can we confirm the word modifying an adjective is an adverb which may well be adjective sometimes?


In this sentence, what are the parts of speech of 'bright' and 'red'?



She wore a bright red beautiful dress.



Could someone please come up with an example that clearly identifies adjective vs. adverb which is really confusing for me to decide?





sentence construction - Adjective Used as an Adverb?




That cake looks good.



In formal proper grammar, may good (adjective) get used as an adverb? Or, may you read it as, That cake (noun phrase, nominal[?], argument[?]), looks (verb, predicate[?]), good (subject compliment[?].? How may I discern this, grammatically?




Friday, February 16, 2018

ios - In 3D camera math, calculate what Z depth is pixel unity for a given FOV


I am working in iOS and OpenGL ES 2.0. Through trial and error I've figured out a frustum to where at a specific z depth pixels drawn are 1 to 1 with my source textures. So 1 pixel in my texture is 1 pixel on the screen. For 2d games this is good. Of course it means that I also factor in things like the size of the quad and the size of the texture.


For example if my sprite is a quad 32x32 pixels. The quad size is 3.2 units wide and tall. And the texcoords are 32 / the size of the texture wide and tall.



Then the frustum is:


    matrixFrustum(-(float)backingWidth/frustumScale,(float)backingWidth/frustumScale,
-(float)backingHeight/frustumScale, (float)backingHeight/frustumScale, 40, 1000, mProjection);

Where frustumScale is 800 for a retina screen. Then at a distance of 800 from camera the sprite is pixel for pixel the same as photoshop.


For 3d games sometimes I still want to be able to do this. But depending on the scene I sometimes need the FOV to be different things.


I'm looking for a way to figure out what Z depth will achieve this same pixel unity for a given FOV.


For this my mProjection is set using:


    matrixPerspective(cameraFOV, near, far,  (float)backingWidth / (float)backingHeight, mProjection);


With testing I found that at an FOV of 45.0 a Z of 38.5 is very close to pixel unity. And at an FOV of 30.0 a Z of 59.5 is about right. But how can I calculate a value that is spot on?


Here's my matrixPerspecitve code:


void matrixPerspective(float angle, float near, float far, float aspect, mat4 m)
{
//float size = near * tanf(angle / 360.0 * M_PI);
float size = near * tanf(degreesToRadians(angle) / 2.0);
float left = -size, right = size, bottom = -size / aspect, top = size / aspect;

// Unused values in perspective formula.
m[1] = m[2] = m[3] = m[4] = 0;

m[6] = m[7] = m[12] = m[13] = m[15] = 0;

// Perspective formula.
m[0] = 2 * near / (right - left);
m[5] = 2 * near / (top - bottom);
m[8] = (right + left) / (right - left);
m[9] = (top + bottom) / (top - bottom);
m[10] = -(far + near) / (far - near);
m[11] = -1;
m[14] = -(2 * far * near) / (far - near);

}

And my mView is set using:


lookAtMatrix(cameraPos, camLookAt, camUpVector, mView);

* UPDATE *


I'm going to leave this here in case anyone has a different solution, can explain how they do it, or why this works.


This is what I figured out. In my system I use a 10th scale unit to pixels on non-retina displays and a 20th scale on retina displays. The iPhone is 640 pixels wide on retina and 320 pixels wide on non-retina (obsolete). So if I want something to be the full screen width I divide by 20 to get the OpenGL unit width. Then divide that by 2 to get the left and right unit position. Something 32 units wide centered on the screen goes from -16 to +16. Believe it or not I have an excel spreadsheet do all this math for me and output all the vertex data for my sprite sheet.


It's an arbitrary thing I made up to do .1 units = 1 non-retina pixel or 2 retina pixels. I could have made it .01 units = 2 pixels and someday I might switch to that. But for now it's the other. So the width of the screen in units is 32.0, and that means the left most pixel is at -16.0 and the right most is at 16.0.


After messing a bit I figured out that if I take the [0] value of an identity modelViewProjection matrix and multiply it by 16 I get the depth required to get 1:1 pixels. I don't know why. I don't know if the 16 is related to the screen size or just a lucky guess. But I did a test where I placed a sprite at that calculated depth and varied the FOV through all the valid values and the object stays steady on screen with 1:1 pixels. So now I'm just calculating the unityDepth that way.



If someone gives me a better answer I'll checkmark it.



Answer



I'm answering this myself since no one else has touched it in a month.


I'm not sure why it works. If I ever get a chance to go through all the math to figure it out. But this is the code that I worked out, and it works across all FOV's. I tested it by sliding through all FOV's and placing my sprite at unityDepth, which changes for each FOV. The sprite stays at pixel for pixel the whole time with no jello or distortion.


The way I do it in this app is 'centerField' is a zDepth of what I'm focusing on. Then instead of having a huge frustum that goes from .01 to whatever, I only go a range around that. The reason for that is to add resolution steps to my depth buffer. But that's a different discussion. You could replace the near and far (centerField+350) with whatever values you normal use. It doesn't effect this z depth unity issue.


GLfloat centerField = cameraPos.z - camLookAt.z;
GLfloat near = centerField-150;

if (near<1.0) {
near=1.0;

}

matrixPerspective(cameraFOV, near, centerField+350, (float)backingWidth / (float)backingHeight, mProjection);
matrixCopy(mProjection, pProjection);

matrixMultiply(mProjection, mView, mViewProjection);

unityDepth = mViewProjection[0]*16;
focusZ = -unityDepth;

Meaning of the phrase "little too"?


Does the phrase 'little too' mean same as 'very', or is it mild form of very ? For instance, I am little too comfortable talking to you. Does it mean same as 'I am very comfortable talking to you' ?




conversation - Should I say "I don't know" or "That I don't know"?


When someone asks a question, is the reply, "That I don't know" correct? Or is the simpler "I don't know" a more correct or proper response?



Answer




Normally you just say:



I don’t know.



Sometimes when you want to draw attention to the thing unknown, you might venture to add an object:



I don’t know that.



But it would be rare indeed to apply inversion to put the now-important bit first:




That, I don’t know.



How to move monsters in a C++ game?


I'm creating a dungeon crawler in C++ and I'm almost done but I need to make the monster move and I'm at the end of my wits.


This is my map:


Char Map[10][10];

and this is how I initialize the positions of the monsters:


void fieldinfo::RandomizeMonsterPositions()
{

amountEnemies=10;
srand(time(0));

for(i=0; i map[rand()%9][rand()%9] = enemy;
}
}

fieldinfo is the name of my class.


Each time the player moves, the map is redrawn with the updated players position and I need the monster to move every time the player does (randomly or not I don't care).





flash - Easing Functions


I started to involve myself with easing functions (Flash AS3), came about in trying to understand TweenLite and Robert Penner's website: http://www.robertpenner.com/easing/



The question I have is what is the math basis for these functions. I've seen other sites modify the functions to create custom easing function.




nouns - Bumper sticker: "Eat Local"


For a great while, I have always thought that the bumper sticker "Eat Local" was grammatically incorrect. I was under the impression it should say "Eat Locally."


But, now, for some reason, I am starting to reconsider.


Which is correct?


Thank you.




Thursday, February 15, 2018

mathematics - Predicting physics/trajectory for pool/billiards games


I'm thinking of making a quick proof of concept of a billiard-style game mechanic, where the player has perfect information of what is about to happen. Here's a good example:


enter image description here


I'm only mildly familiar with physics in both Unity and Flixel-Box2D, and I can't really off the top of my head imagine how to do this.


Should I even use physics at all, or should I just use basic math?



Answer



To generate those lines you need to run the complete simulation of the whole shot every frame, as if you'd just hit the cue ball. This requires keeping two copies of the table state - one for display and one for simulation. For each frame of the simulation you just store the position of each ball, and at the end use that data to draw lines with. This simulation wants to happen quickly enough to maintain an interactive frame rate, although you can work round spikes in compute time with a thread.


The physics for a basic 2D simulation aren't too complicated if you don't care too much about accurately simulating a real pool table. It gets significantly harder to simulate it well when you take in to account jump shots and swerve shots as the balls can then move along curves instead of straight lines. The shot where you break the pack is also difficult to simulate correctly as there are going to be lots of touching, or almost-touching balls, which may trip up a physics simulation.



I'd suggest trying out a few physics libraries to see which one gives you the best results. Setting up a box full of spheres and hitting one of them should be fairly simple in any decent physics engine.


prepositions - When to use "from" or "by"


Which is the correct usage here?


Shaken by the experience, Tom decided to go home.


or


Shaken from the experience, Tom decided to go home.


What rule do we use to know which preposition to use?



Answer



There is no rule.



There are sometimes partial rules; but mostly it is a matter of learning what preposition a particular verb, adjective, or noun takes for its indirect objects. That needs to be learnt just as much as the spelling.


In this case, the iWeb corpus has 82 instances of "shaken by the experience" and 7 of "shaken from the experience". So both are used, but "by" is much more common.


opengl - How can I calculate a terrain's normals?


Im trying to implement basic lighting in Opengl 3+ (a sun) with this tutorial :


http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=11


Im building a basic terrain and its working well. Now im trying to add normals, and I think its not working well :



Terrain


Terrain in wireframe


As you can see I dont think my normals are good.


This is how I get them :


for(x = 0; x < this.m_size.width - 1 ; x++)
{
for(y = 0; y < this.m_size.height - 1 ; y++)
{
immutable uint indice1 = y * this.m_size.width + x;
immutable uint indice2 = y * this.m_size.width + (x + 1);

immutable uint indice3 = (y + 1) * this.m_size.width + x;
immutable uint indice4 = (y + 1) * this.m_size.width + x;
immutable uint indice5 = y * this.m_size.width + (x + 1);
immutable uint indice6 = (y + 1) * this.m_size.width + (x + 1);

Vector3 v1 = vertexes[indice3] - vertexes[indice1];
Vector3 v2 = vertexes[indice2] - vertexes[indice1];
Vector3 normal = v1.cross(v2);
normal.normalize();


normals[indice1] = normal;

indices ~= [indice1,
indice2,
indice3,
indice4,
indice5,
indice6];
}
}


I use this basic shader : http://ogldev.atspace.co.uk/www/tutorial18/tutorial18.html or in the link I posted at the top.


Thanks.



Answer



By looking at your picture your problem seems that you need to smooth(average) your normals. That is when a vertex is shared by multiple triangles and yet has one normal you have two options to deal with this problem:



  • Smooth edges: You calculate the normal of each vertex for each adjacent triangle and then average them.

  • Hard edges: You duplicate each vertex, especially at the edges where the normal greatly varies between triangles. It practically has 3 different normals (though it's not actually) but then you have the effect of hard edges.


I provided the full code for smooth normals here. And more detailed explanation for this issue here.



word request - What to call it when someone always looks for greener pastures?


Someone who always looks for the "better" and more ideal places (to live), jobs, things to buy that fit his taste/mood etc. He is always looking for better because he always feels it's "not enough".




unity - How can I randomly generate objects inside of a Complex Area?


In my game, I want to generate randomize enemies inside of this green area that I made with a custom editor tool. enter image description here


enter image description here





Unity, Steam and updaters!


I am probably asking a question answered here already; but I have yet to find the answer! Can anyone here help me with how updates work for your games? I know that through visual basic you can create batches to make shorter updates and everything like that but overall I am completely confused:/



How to get your game from Unity to Steam and how can you update the version and files efficiently?



Answer



If you publish your game through Steam you don't have to provide your own update mechanism – I'd even strongly suggest not doing so. While this gives some control away from you (i.e. you have to wait for Valve to push updates), it let's you forget about all the update handling and your players also won't hit problems in case they verify Steam's cache integrity (which might cause Steam to revert the game to a previous state, which will then have to be patched once again).


Basically you just create your game with no update mechanics in place. If you publish a new version, eversyone's installation will be updated without you having to worry about it.


If you want to prevent players from using outdated versions, just include some version/protocol check when one connects online.


As for publishing on Steam, check out Steam Greenlight, if you don't have any publisher handling this for you.


It basically works like any workshop showcase. Once your game has attracted enough attention, Valve should contact you with further details and how to proceed (signing contracts and stuff).


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