Thursday, November 30, 2017

idioms - "It's time ... 'verb'/'verb-ed' ..."



It's time colleges helped you compare apples to apples.


(The Boston Globe)




If the time is a present moment, why does the journalist use "help" in the past tense? Or is "helped" subjunctive?




meaning - I went to the doctor's



I have run across such a sentence:



Yesterday I was ill, so I went to the doctor's.



What is the function of possessive here, that is doctor's?




Meaning of "any one time"


Please help me with the exact meaning of the phrase "any one time" in the text below.



You don't think he'd had a good look at me any one time and thought the original was even worse than that poor picture, so he backed off?


"Casting away" by Alice Munro




I searched other forums and found out it means "at any given moment" but I think it's not true for this particular context, I think it means "even for once". Am I right?


Thanks in advance.


Edit: I changed the title and content by dropping at because according to snailplane's suggestion, at is not connected with any one time in this context.




Wednesday, November 29, 2017

licensing - Do you need a license for weapon models?


When creating your own model for a weapon, say the M4 carbine, and using the model in your game. Do you need a license to use it commercially? I know that racing games like GT5 has a license for each and every car, but the same apply for weapons?



Answer




I am not a lawyer and you should consult one for real, accurate legal advice.


The name and design are likely trademarked (you can see here for example that there have been trademark issues with the M4 in the past; other guns will likely have similar issues).


EDIT: It is possible that as far as a trademark is concerned I may have been misinterpreting things, and it may be okay depending on your circumstances. However, you will still potentially need to worry about other intellectual property restrictions (such as any copyrights held in relation to the item in question) which do apply regardless of whether or not your product is commercially available.


At the end of the day, if you violate somebody's intellectual property laws and they call you on it you can be in a world of hurt so it's best to get real legal advice because the risk is pretty severe. There's a good set of articles on intellectual property issues by a Real Lawyer here.


meaning - what is the difference between "yet" and "still"?


what is the difference between "yet" and "still"?


When we can use "still"? and when we can use "yet"?


Are they synonyms or not?


"The plan could yet succeed." Can I use "still" in that sentence instead of "yet"?


"I still don't understand." Can I use "yet" in that sentence too?



Answer




In their closest meanings, "still" is used for a situation that is ongoing or unchanged at any point in time, or regardless of any factor, stated or otherwise:



She still loves you. If you lose all your money, she will still love you. Even when you were abusive, she still loved you.



"yet" has a similar interpretation, but describes the state of a something, within a process, at any given time within a progression, up to that point in a process:



He is yet a child. -or- He is a child yet.


He's still a child.



In another usage, it is closer to "already." In questions, it asks whether something has happened "already" or up to the time of questioning, and additionally implies that the addressee is expected or required to do it:




Have you called your mother yet?



Here the speaker possibly commanded or just expects the addressee call his mother, or was informed of the his intention to call his mother, and is questioning whether he has done it. "Already" doesn't have this force - it merely questions the completion of the action logistically:


Have you already called your mother? I wanted to say hello to her. (=Am I too late?)


Note that the idiom "have yet to" is used with the above meaning to express that something expected still hasn't been done:


He has yet to call his mother. (= He's supposed to do it, but hasn't done it.)


I have yet to see that movie. (= I've been meaning to see it, but haven't gotten around to it.)


"Not yet" - or "yet" in any negative context - is the opposite of "already:"




My father already sent me a birthday present.


My father hasn't sent me a birthday present yet.



Finally, "yet" can function as a conjunction like "but, however" that emphasizes a result obtained or a situation that arises despite certain factor(s):



He's only been speaking English for a year, yet he sounds just like an American.


I've asked you a million times not to lock the door, yet every time I come home, it's locked.



Note that "still" can replace "yet" here with the same meaning.


opengl - Changing player color without multiple player bitmaps




Possible Duplicate:
How to colorize certain parts of a model - like RTS games have those team colors?



Ok, so here is my current situation. I have a player model, fully UV mapped, and textured. At first I made multiple bitmaps for the character representing multiple colors for each team in the game. (red, blue, green, yellow, etc) Well, as my player count build up, space lowers. So I needed to make a new method of keeping the game effecient, clean, and fast. So I thought of the idea of having a color mask (alpha map covering the areas to be colored). I am using OpenGL, and I just have NO idea on where to begin!


So I ask you, are there any libraries? methods? anything that could help me do this?




Tuesday, November 28, 2017

tense - "Now" vs "by now"


Consider these examples:





  1. By now the desk should be looking significantly tidier!





  2. By now, the failure of regulators to contain dangerous forces should be well accepted.




  3. By now I own some forty copies of the magazine.




  4. By now the blue of twilight is glowing.





  5. He used leverage, but by now applied concerted discipline to contain his risks.





I wonder if I can use "now" instead of "by now" to convey the same meaning.


I would think "by now" refers to a moment until now, but why not use past tense or present perfect tense in the these examples?



Answer



Part I - by now vs now These sentences may all be uttered with bare now, no by, but they will mean something slightly different.


Bare now simply describes the present state. By now focuses on the process by which the present state was achieved. It emphasizes change of state over time, in the course of the process, and it leaves open the possibility that the process will continue in the future.






  1. By now the desk should be looking significantly tidier! ... This emphasizes that the disk looked significantly less tidy in the past—and may look even tidier in the future as the process continues.




  2. By now, the failure of regulators to contain dangerous forces should be well accepted. ... This emphasizes that the regulators' failure was not 'accepted' in the past, but has come to be accepted over time.




  3. By now I own some forty copies of the magazine. ... This emphasizes that your process of acquisition took some time, and leaves open the possibility that you will acquire yet more in the future.





  4. By now the blue of twilight is glowing. ... Without more context, it is difficult to say why the author wants to focus on the change over time; but just for instance, he might be a cinematographer describing the changing quality of illumination he must capture ... and we must replace the polarizing filter with a two-stop ND grad. (NOTE:I made that up. If a Real Photographer wants to correct the technical details I will be grateful.)




  5. He used leverage, but by now applied concerted discipline to contain his risks. ... This emphasizes that he was less concerned in the past to contain risks, and leaves open the possibility that he will be yet more disciplined in the future.





Part II - tense change A change from simple present→simple past changes only the time reference: you assert that the eventuality obtained in the past rather than the present. Now or by now have the same significance as in the present, but refer to a past rather than a present Reference Time: they might be replaced with (by) then.



5. is already in past tense. 3 and 4 are pretty simple: you just change the present-tense forms (3pr, 4pr) to past-tense forms (3pa, 4pa):



3pr. (By) now I own some forty copies of the magazine.
3pa. (By) now I owned some forty copies of the magazine.


4pr. (By) now the blue of twilight is glowing.
4pa. (By) now the blue of twilight was glowing.



But the two with should are tricky, because that past-form should may represent either a realis or an irrealis. I'm going to cast these as reported speech so the time references are clearer.



1pr. (Tom reports that) by now the desk should be looking significantly tidier!

2pr. (It is clear that) by now, the failure of regulators to contain dangerous forces should be well accepted.



With a realis, should is identical in the past tense, so if 1pr. means “he is confident that the desk now looks tidier”, the past realis version 1pa-r will mean “he was confident that the desk now looked tidier” and will be expressed this way:



1pa-r. (Tom reported that) by now the desk should be looking significantly tidier!



But if 1. means “he feels the desk should look tidier than it does”, the past irrealis version 1pa-i will mean “he felt the desk should look tidier than it did” and will be expressed this way:



1pa-i. (Tom reported that) by now the desk should have been looking significantly tidier!




The corresponding versions of 2 are



2pa-r. (It was clear that) (by) now, the failure of regulators to contain dangerous forces should be well accepted.
2pa-i. (It was clear that) (by) now, the failure of regulators to contain dangerous forces should have been well accepted.



Part III - perfect recast A change from simple present→present perfect is quite different. (Again, I’m going to skip #5, which is in the past tense rather than the present; if you find it presents issues distinct from those addressed here, I’ll be happy to address them in a separate question.) The two versions without modals have significantly different meanings than their simple present versions.



3prpf. By now I have owned some forty copies of the magazine. ... This implies that you have disposed of some copies, which is not the case with the simple present version. This is an implicature, not an entailment—it may be cancelled—but there is no reason for you to employ the present perfect unless you in fact no longer own some of those forty copies.


4prpf. By now the blue of twilight has been glowing. ... This falls very odd on my ear. Without now or by now the sentence might (just) be employed to report a previously unobserved recurrent phenomenon: the blue of twilight used to appear dull, but for several nights recently it has appeared to glow. But with either now or by now it demands a complement defining the other end of the timespan: By now the blue of twilight has been glowing for several hours. (Perhaps this is that same videographer shooting in the far north, where twilight continues through the night in summer!)




As for the two sentences with should, you know that these cannot be literally recast in the present perfect. There is no such thing as perfect modal, because modals are defective—they have no past participle to enter into a perfect construction. The closest you can get is a modal perfect, in which the modal takes a perfect construction as its complement:



1prpf. By now the desk should have been looking significantly tidier.
2prpf. By now the failure of regulators to contain dangerous forces should have been well accepted.



I have already indicated what these signify in an irrealis context (see 1pa-i and 2pa-i, above). If the should bear a realis significance, you have the same problem as with 4prpf—you need to pin down the front end of the timespan.


Monday, November 27, 2017

Dungeons in a 3d space game



I'm in the process of creating a prototype for a 3d space game (3rd person). My question is this:


How can a 3d space game have Zelda-like (or similar) dungeons in open space?


Problems:





  1. Space has no walls (obviously) - how to restrict movement?




  2. No movement restrictions - no doors.




  3. No doors, no interesting mechanics of opening them.





  4. No backtracing (for example after acquiring new power at the end that enables access to a place at the beginning of the dungeon).




More info: The Legend of Zelda: Oracle of Ages and Seasons' dungeon design - to see how some Zelda games do it.


The dungeon should be in 1 star system.


The EVE Online example is a good one, in the sense that it has been done before and it works, but for me it always somehow felt like cheating because in EVE you can travel anywhere... but not to a pocket of space right behind the dungeon gate. Even if you had a bookmark there.


And since my game will most likely feature even more free-form travel then EVE (think Elite: Dangerous) then what I'm saying is I'm looking for something that could improve that can be found in EVE.



Answer



Level designers I've spoken with often lament how difficult it is to create interesting challenges & spaces in open areas, so you've definitely set a hard problem for yourself.


That said, the core structure of something like a Zelda dungeon is often about finding a number of MacGuffins (items required to progress) or switches (locations where you modify some dungeon state) in a particular sequence. And so even without walls, you can still introduce structure via the dependency graph of these actions.



Let's run through an arbitrary example (which may not directly align to your gameplay or fiction):




  • The player wants to get to a warp gate to go to the next space sector (something to act as an end goal, you can replace this with whatever...)



    • Because there's no walls, they can just fly up to it, so we have it begin in a powered-off state to put some challenge in their way.




  • To activate it they'll need to turn on three power-beaming stations around the map.





  • One station is missing an energy crystal, so they need to go to a nearby asteroid field to collect one.




  • Another station has a turret that keeps you from getting close. The player needs to go back to the asteroid field and tow an asteroid they can use as a shield.




  • The final station is damaged, but the spare parts to fix it are in locked chests at the other two stations. The player collects a maintenance key at this station that lets them access the chests.





  • spare parts collected, they can return to the third station, repair it, then head to the warp gate to escape (and maybe fight the space monster boss lured to it by all the activity)




This lets us construct a reasonably interesting dependency graph without a hard wall that blocks the player anywhere, and gives them cause to re-visit a few previously explored areas in a new context.


Diagram illustrating dependency relationships in the scenario above.


Here the variety of interactions has to take up some of the slack left by variety of spatial layouts & approach, since we have fewer tools in open space to control the latter. (Though that doesn't preclude you from introducing constrained spaces at key sites along the graph, like big space stations or wrecks the player needs to navigate into through a controlled number of doors - I avoided such cases above just to show you can get interesting dependency relationships without always going to interior spaces)


The other side of this challenge is landmarking. It's extremely easy to get lost and disoriented in space. If the player is to feel like they're purposefully solving challenges, rather than just chasing a waypoint, you'll need to give them tools to understand where they are and let them plan.


In the example above, we led the player to the asteroid field landmark to find the energy crystal, which ensured they knew it was there when they later needed an asteroid (or vice versa). Coming back to a recognizably familiar landmark like that, with a new purpose in mind, can really help a scenario feel like a space the player is exploring and mastering, rather than a sequence of arbitrary roadblocks.


Consider using things like gassy nebulae, debris fields, space stations, planets, etc. to give players these kinds of landmarks they can recognize.



ipa - How to interpret pronunciation marks (such as "ləʊðd")


In questions such as this one (What’s the pronunciation for loathed) answerers often answer pronunciation questions with special characters, as Matt does for that question by using ləʊðd. Though I already know how to pronounce the word loathed, I for the life of me can't look at those special characters and figure out how the pronunciation comes from them! How exactly do they work? Is there a reference somewhere for how each character is to be pronounced, so I can get a better handle on this system? It makes it hard for me to read questions and answers containing these symbols when I don't understand them.



Answer



The characters are from the International Phonetic Alphabet or IPA. To cover it fully would take more space that we've reasonably got here, but the Wikipedia link above should help you out if you care to dig in. Also, here is a link to the offical chart of the symbology.


And one more: this Merriam Webster pronunciation guide might be a better place for a first look.


3d - How to texture a surface generated by marching cubes algorithm?


I'm working on a voxel game, and I have some problems with texturing. I have read the related questions on this stack exchange, but they seem adressing a generic problem (using triplanar texturing), and I think mine is simpler.


Polygonization output


You can see that the resulting geometry contains a limited set of polygons. Last I checked I saw only 44 of them. My idea was to uv map these polygons to a regular texture using a static map table, without having to use any triplanar texturing (currently, every polygon is mapped to the same values, so it's ugly).


My questions :



  • Is it valid ? It seems much simpler than triplanar texturing, but I can't find a single resource on the subject, so I'm wondering if it's a right approach.

  • Where can I find / How can I generate a UV map for this kind of geometrical figure ? I have tried to use blender but it seems like my blender-fu is not strong enough. Is there some simpler software to generate UV map with models like this one ?




Sunday, November 26, 2017

modal verbs - What is difference between "Can", "Could", "Will", "Would", "Shall", and "Should"?



I can work.
I could work.
I will work.

I would work.
I shall work.
I should work.




c# - When a sprite is rotating to follow an angle, how to prevent it from reversing direction after a point?


Below is a section of my code which handles a player's sprite rotating towards an angle after a user touches the screen:


touchState = TouchPanel.GetState();

Vector2 touchPosition;

if (touchState.Count > 0)
{
touchPosition = new Vector2(touchState[0].Position.X, touchState[0].Position.Y);
targetPosition = Math.Atan2(player.Position.X - touchPosition.X, player.Position.Y - touchPosition.Y);

if (angle_radians < targetPosition)
{
angle_radians += 2 * fps;

}

if(angle_radians > targetPosition)
{
angle_radians -= 2 * fps;
}

player.Angle = angle_radians * -1;
}


The problem I'm having is that when the angle goes past a certain point (I believe 3.15 radians?), the logic no longer functions correctly and the sprite reverses direction in a 360 circle until it meets the target position again.


I know there is something I'm missing from this logic, and I can see the problem, but I'm not sure how to approach handling it.


How would I prevent the sprite from reversing direction?


Thanks


EDIT: I tried the solution below but I only receive a positive number from 0-6 for angle_distance, what have I done wrong?


            if (touchState.Count > 0)
{
touchPosition = new Vector2(touchState[0].Position.X, touchState[0].Position.Y);
targetPosition = Math.Atan2(player.Position.X - touchPosition.X, player.Position.Y - touchPosition.Y);
angle_distance = targetPosition - angle_radians + Math.PI;

angle_distance = angle_distance - Math.Floor(angle_distance / 2 / Math.PI) * 2 * Math.PI;

if (angle_distance < 0)
{
angle_radians -= 2 * fps;
}

if (angle_distance > 0)
{
angle_radians += 2 * fps;

}

player.Angle = angle_radians * -1;
}

EDIT: I now realise my mistake, correct solution is below


if (touchState.Count > 0)
{
touchPosition = new Vector2(touchState[0].Position.X, touchState[0].Position.Y);
targetPosition = Math.Atan2(player.Position.X - touchPosition.X, player.Position.Y - touchPosition.Y);


angle_distance = targetPosition - angle_radians + Math.PI;
angle_distance = angle_distance - Math.Floor(angle_distance / 2 / Math.PI) * 2 * Math.PI;

if (angle_distance < Math.PI)
{
angle_radians -= 2 * fps;
}

if (angle_distance > Math.PI)

{
angle_radians += 2 * fps;
}

player.Angle = angle_radians * -1;
}

Answer



First, find the signed distance between the two angles:


dist = targetAngle - currentAngle + pi
dist = dist - floor(dist / 2 / pi) * 2 * pi - pi


If it's negative, then subtract from the current angle to reach the other angle in the shortest time, if it's positive, then add to it.


c++ - Identifying Entity 'Types' in an Entity-Component System


If an Entity has no explicit 'type' (e.g. player) and is simply a collection of components, how do I identify the entities that my systems should and should not be working on? For example, in a game of Pong the paddle and ball both collide with the window boundaries. However, the collision handling systems for each will be different, therefore a system should not handle entities of the wrong type.


void PlayerCollisionSystem::update(std::vector entities) {
typedef std::vector::iterator EIter;
for (EIter i = entities.begin(); i != entities.end(); ++i) {

Entity *player = *i; // How do I verify that the entity is a player?

// Get relevant components.
PositionComponent *position = player->getComponent();
VelocityComponent *velocity = player->getComponent();
SpriteComponent *sprite = player->getComponent();

// Detect and handle player collisions using the components.
}
}


Both the player and the ball share the same relevant component types for collision handling yet their system implementations will be different.


If I have a container of all game entities, how do I identify specific types of entity without inheriting Entity or including a member variable such as std::string type, in which case an entity is no longer simply a collection of components?



Answer



Nicol Bolas' answer is straight on, but stepping aside and looking at your problem from a distance: you really don't need the type of the entity.


You only need to care whether "does the object have component X" or not and your problem is that you have not properly identified X. If two objects behave differently then give them different components or just put a boolean flag on the component if it to make it behave differently for different object configurations. Use the component system to make decisions about behavior, not the entity "type." That's the whole point of using components.


You are completely allowed to have a PaddlePhysics component/system and a separate BallPhysics component/system if they behave differently. Or you can break down the components into more granular pieces such that you have a Bounce component that only the Ball has and a StopAtBoundary component that both Ball and Paddle have if part of the behavior is complicated enough to justify sharing the code. Or you can just make a PongPhysics component that has a boolean flag Bounces set true for the Ball and false for the Paddle. You could even make a base WallCollision component and then derive that component to get a BallWallCollision that adds the extra behavior needed there.


Saturday, November 25, 2017

game design - Is story more important or the gameplay more important?



Read this Slate article. In particular, the following struck me:



When he looks at video games from a critical distance, Bissell is concerned mainly with their lack of narrative meaning. Games ask us to save the princess, save the country, save the world, save ourselves—but no one plays games to achieve those ends. We play for the puzzle, for the physics, for the sense of being embedded in a fully realized world. Indeed, for me, the "story" usually seems like filler, even in games like Grand Theft Auto and RDR [Red Dead Redemption], whose stories are smarter than the rest of the video-game pack. RDR begins and ends every mission with cleverly scripted movielike "cut scenes" that provide some explanation for why your character is doing what he's doing—but the game also lets you skip the scenes, which I usually elect to do. Thus I can't really explain why my character is doing what he's doing. The real answer is he's doing it because I am making him do it, and I am making him do it only because I am having fun.


"This is one of the most suspect things about the game form," Bissell writes. "A game with an involving story and poor gameplay cannot be considered a successful game, whereas a game with superb gameplay and a laughable story can see its spine bend from the weight of many accolades—and those who praise the latter game will not be wrong." What's the solution to this quandary? Should games invest more in story, in an attempt to bring us narratives that are on the level of those of the other popular arts? Or should games abandon story—is the video game, as a form, simply incompatible with traditional concepts of narrative, and must game designers instead find other ways to invest their creations with lasting meaning?



As if Bissell's uncertainty is echoing throughout the game industry, there has arisen a tendency to make many big-budget blockbuster games heavily story-driven. Even Starcraft II has a fairly story-driven campaign.


Is a game without a high-quality narrative bereft of true value and meaning? Must games have any meaning at all in the literary sense in order to be considered worthwhile forms of entertainment? What about emergent narratives, where the player has a decisive role in determining the plot (ideally much more decisive than we've seen in any games so far released)? If games do not need a higher literary meaning, do they at least need to have some lasting emotional significance for the player?



Those are just some thoughts that the article raised. The real question can be summed up like this: what is the true value of a video game? Is a game to be valued on its dynamic interaction with the player, on its ability to present a narrative in a way other mediums cannot, or on its ability to provide simple pleasure?




adjectives - "-ic" vs "-ical", which to use


Is there a rule about when an adjective should end with "ic" or "ical"?


Geometr-ic

Analyt-ical
Theoret-ical
Kinet-ic



Answer



The NOAD says that the -ical suffix is used to form adjectives:



  • Corresponding to nouns or adjectives usually ending in -ic (such as comical corresponding to comic)

  • Corresponding to nouns ending in -y (such as pathological corresponding to pathology)


As for the words you list, the NOAD says:




  • Geometric and geometrical are both adjectives, with the latter being a derivative of the first

  • Analytic is another term for analytical

  • Theoretic is another term for theoretical

  • Kinetical is not a word listed by the NOAD


In some cases, a suffix is preferred over the other one, but there isn't a rule that explains in every case when to use one or the other.


modal verbs - A particular usage of "would" in the context: they did return my car, why would they do it?


The following dialog is taken from the movie Sin.City.A.Dame.to.Kill.For.2014:



Josh Brolin's first-person narration: I've taken a beating before but never like this. Never like this. The sounds go wet. Maybe he keeps hitting me. I don't know... ...I'm gone. Gone to that place where there's no pain or thought.


Josh Brolin's first-person narration: I wake up in mid air. The pavement rushes up to give me a big sloppy kiss. I'll be damned. Door to door service. Then I spot my Mustang, which makes no sense. Why would they return my car?


Josh Brolin: Get out of here.


Eva Green: No.


Josh Brolin: Put your clothes back on and get out of here, now!



Eva Green: No. You had your chance. You could've stayed away but you came for me. You still want me, and I'm yours, now!



I find that would confusing as well. Since they did really return his car, why use would there?


I think it should be: Why did they return my car?


Would makes return my car hypothetical or imaginary, I suppose. So what is the particular usage of would here?


Meanwhile, since the car return occurred before Brolin woke up, why not say "Why would they have returned my car" instead?




After I considered JGL's answer, I think the original line could be paraphrased in a similar way: they returned his car and now Brolin is wondering why they would have done such a thing.


So why would have done is used here instead of would do?



Answer




Given this context, what is the difference between "Why would they return the car?" and "Why did they return the car?" 


The question "why did they return the car?" requires a factual answer.  Why did they return it?  I don't know.  We'd have to ask them.  The only answer that's good enough is the actual reason for their action. 


The question "why would they return the car?" allows for speculation.  There could be any number of plausible answers.  Why would they return it?  Maybe I can guess a number of reasons.  Maybe I can't guess any.  A good guess explains why they would, even if it turns out that that's not why they did. 


If I can think of fifteen good reasons for returning the car, but they had only one reason when they returned it, then there exist fifteen answers to "why would they?" but only one answer to "why did they?" 


The question "why would they return the car?" works well as a rhetorical question.  A statement that means nearly the same thing as the rhetorical question is "I can't imagine any reason for them to return the car." 


 
One simple way to express this difference is to say that "why did they return it" is in the indicative mode, but "why would they return it" is in the subjunctive. 


meaning - Difference between "Have Thought", "Have Just Thought" and "Just Thought"?



I was told that use of present perfect is incorrect in the context below as thinking action is discrete event and there isn't any relevance with the current situation. (Context is a situation where I've been looking for my keys for the last couple of minutes and my friend informs me where the keys are. Just a minute ago my friend informs me the same information comes to my mind)


My friend: The keys are on the desk.


Me: I have thought the same thing.


I was told that instead of "I have thought the same thing" it is correct to use "I thought the same thing" or "I was thinking the same thing."


My questions then concern the two examples below:


Example 1


My friend: The keys are on the desk.


Me: I have just thought the same thing


Example 2


My friend: The keys are on the desk.



Me: I just thought the same thing


Similar to the use of "I have thought the same thing" is Example 1 incorrect to use (present perfect + Just)? Does present perfect fit semantically in this context with or without time adverb "just"?


Can I use Example 2 (simple past +just)? Because several resources indicate that present perfect + just and simple past +just essentially mean the same thing. Is there any semantical difference between Example 1 & Example 2?




3d - How to achieve a Neon-Light effect?


I'm wondering how to achieve a neon-light type effect. For example, in Pac-Man Chamipnship Edition:


PacMan CE


Or in Geometry Wars:


Geometry Wars


Is that a Bloom Effect? Or what techniques would I have to look for?



Answer



Here you go :)



GPU Gems - Glow Effect


With that many entities with a glowing effect on the screen (especially in Geometry Wars), it's more often than not a shader effect that's similar to the shader described in that paper.


Friday, November 24, 2017

terminology - What is it called when two or more nouns comes in a row?





  • an office worker

  • a jewelry maker

  • a potato peeler

  • a shopping list

  • a swimming lesson

  • a walking holiday



What is it called in English when two nouns comes in a row as in the above examples?



Answer




They're called noun adjuncts. From that Wikipedia article...



a noun adjunct or attributive noun or noun (pre)modifier is an optional noun that modifies another noun; it is a noun functioning as a pre-modifier in a noun phrase.
For example, in the phrase "chicken soup" the noun adjunct "chicken" modifies the noun "soup".



algorithm - How to implement A.I. for checkers/draughts?


I saw this checkers game and I wondered how the A.I. was implemented.


How should I implement an A.I. for checkers (draughts, dama, dame)? Are there any known algorithms?




Very thnaks full to all. I m very wonder to see this Tic Tac Toe game tutorial blog post.


So, i want dama game algorithm open source code and blog post.. Is there any helpful link or any doc file..? please let me know..



Answer




Oh I do love these games!


So first things first, in order for a computer to play a game, it needs:



  1. a structure to work with

  2. rules to play by

  3. a win condition to work towards


Let's tackle this one piece at a time.




Structure



Since the board is an 8x8 grid (but could easily scale), and each grid space may exist in only one of five states, let's define those states:


[EMPTY, WHITE_PIECE, BLACK_PIECE, WHITE_PIECE_PROMOTED, BLACK_PIECE_PROMOTED]

Respectively ENUM'd to:


[0, 1, 2, 3, 4]

Now that we know what each space can be we need some way to represent all the spaces, or the board if you will. Almost every strong language will support a multi-dimensional array (an array where each element is an array holding data). So take the following slack-code for defining our array:


BOARD_ARRAY = array(8, 8)

This will give us an 8 x 8 array in which we can store integers (our enums from before):



(
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
)


Now you can already see how that this is beginning to look like a board! I've never played the variant mentioned in the youtube video but it appears to start with 2 rows of white pieces one row from the bottom, and 2 rows of black pieces one row from the top. Which would mean when we start a game our array should look like this:


(
[0, 0, 0, 0, 0, 0, 0, 0],
[2, 2, 2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],

[0, 0, 0, 0, 0, 0, 0, 0],
)

(Remember 2 represents 'BLACK_PIECE' and 1 represents 'WHITE_PIECE')


So now the computer has a structure to work with. Step 1 complete!




Rules


Let's imagine you had an actual board set up in front of you, playing against a master player. If you tried to move one of his pieces, you'd get your hand slapped. If you tried to move a piece in a way you couldn't, you'd get your hand slapped. If you tried to cheat well... you get the idea. But the problem is, computers don't. So it's our job to provide strict rules to play within.


We need to create a way to check if any given move is 'legal'. Which means we first need some way to represent a 'move'. One way would be to use array positions; For example to move a piece from [0, 0] to [0, 1], we could create a function that will update the board given that move. So back to slack:


MY_MOVE = array( [0, 0], [0, 1] )


The above represents one piece, moving one space down from the top corner of the board (assuming 0, 0 is the top left corner). You may also notice I chose to use a multidimensional array for the move. This is because pieces may theoretically move a great number of times in one turn (for 'jumping' other pieces). So let's pretend at 0, 1 there was an opponents piece, meaning we would land at 0, 2:


MY_MOVE = array( [0, 0], [0, 2] )

Pretty simple eh. The program should understand that if we skip a space we are jumping another piece (or else it's an illegal move, and should throw an error). Now let's jump two pieces:


MY_MOVE = array ( [0, 0], [0, 2], [0, 4] )

This gives us a way to describe any move on the board. Yay! Now since I don't fully understand the rules of the exact game in question (although I've played a bit of Canadian checkers in my day) the exact move legality will need to be defined by you. A good flow up to this point would look like:


FUNCTION_FIND_ALL_LEGAL_MOVES( MY_BOARD ) Returns: array ALL_LEGAL_MOVES
FUNCTION_FIND_BEST_MOVE( MY_BOARD, ALL_LEGAL_MOVES ) Returns: array MY_MOVE

FUNCTION_DO_MOVE( MY_BOARD, MY_MOVE ) Throws: error ILLEGAL_MOVE Updates: MY_BOARD
repeat from start for each turn

The above assumes you can cycle through each piece to find all it's legal moves, then given a collection of all the legal moves somehow choose the best one (strategy here). The move is then applied to the board, or throws an error. Then the next player takes their turn. So we have an AI that knows how to play! Joy! Moving on.




Winning


Simple games are wonderful, because winning is defined by a very simple state. Ain't no white pieces on the board? Well I guess you've won! This is implemented in step 2 when we choose the best move to take us closer to the winning condition.


To make some very intelligent AI you could keep a database that stored every possible board as a state, with every possible move from every possible state, to find chains towards winning.


You could also create strategies, like: if there is a piece that WILL be jumped, save that piece or if a piece is able to jump more than one other piece do that jump.





That should give you a good jumping off point, it is only one method of literally unlimited possibilities. You could theoretically build a giant robot to draw with crayons then conduct spectral analysis on the drawing to choose moves... but it wouldn't work very good, or fast. This way has worked in the past, and worked well (: Hope that helps!




A Few Words On Implementation


Checkers is what is referred to as a 'solved' game, in that we can calculate every move with no unknowns. But that's a whole whack of moves! So there is no way to do it all manually... if only there was some... oh right we're programmers. fist pump


SQL is a wonderful tool for storing all these seemingly endless moves. For those with no experience with SQL, mySQL is a free (fairly easy to use) and open source SQL server. SQL is used for managing databases, sorta like a spreadsheet on steroids. It is also able to hold seriously large amounts of data and work with it very quickly.


So how can we use this? Since we know that if the board is in an exact state (each piece in a certain position) we can calculate all the available moves, and save them. For example:


+Board State+          +All Possible Moves+               +Best Move+
([0,0,1,2,3],[3..) ([0,1],[0,2]), ([7,6],[7,7],[5..) ([7,6],[7,7])
([0,0,2,2,3],[3..) ([0,1],[0,2]), ([7,6],[7,7],[5..) ([5,5],[5,4])
([0,0,1,3,3],[3..) ([0,1],[0,2]), ([7,6],[7,7],[5..) ([4,4],[4,3])

etc...

So when the computer needs to make a move it simply looks up the board state (stored as the primary key) in the database, and can either choose the best move (should be unbeatable) or one of the other moves to make a more friendly AI.


Great now let's build this database. First we need to calculate every board state. Which can be done with a great big nasty loop, if someone wants to spend some time and work it out that would be awesome. Look at the array as one big number, then count upwards, except in base 5 (0, 1, 2, 3, 4), and condition that each player may only have 16 pieces.


At this point we should have every board state stored and can go through calculating all possible moves.


Once all possible moves are calculated comes the fun part of pathfinding the best possible moves. This is where my knowledge begins to fall short, and things like Minimax or A* start to come into play. Sorry I can't be of more help on that :/


prepositions - How to use "by" and "until" in these specific contexts?



  • I've watched 10 movies until now.

  • He should have been here by now

  • I think in the first sentence, "by" doesn't work and using it will not be idiomatic. This applies to the using "until" in later sentence too. For me using "until" will not be be a correct usage. Instead the "until" in the first sentence and "by" in the second sentence fit the best. Am I right?





Thursday, November 23, 2017

antialiasing - MSAA/ CSAA / FXAA How to set the mode in OpenGL?


I'm learning OpenGL and something I am stuck with is AA. Specially when I want to turn it on and off at runtime. I know that I can set the samplecount when I create a FBO and blit it over to the final window. When I want to change the mode I switch the FBO and everything is fine. The question I am completely stuck with is, how do I change the mode and also important, how do I query the modes that the card supports. With mode I mean CSAA,MSAA,.. .I can't find a lot. At least I know that it is vendor specific. Hope anyone can point me in the right direction. Thanks



Answer




Multisampling is a property of the framebuffer. You enable multisampling by rendering to a multisampled framebuffer while GL_MULTISAMPLING is enabled. If GL_MULTISAMPLING is not enabled when you render to a multisample framebuffer, the pixels covered by that rendering operation replicate their data across all covered samples.


To make a framebuffer object a multisampled framebuffer, you attach multisampled images to it. They will all need to use the same sample count, and all images in the framebuffer must be multisample.


To make the default framebuffer multisampled, you must create your context with multiple samples. This requires the use of the WGL/GLX_ARB_multisample extension, as appropriate to your platform.


Nowadays, the general pattern is to leave the default framebuffer non-multisampled and create your own multisample FBO images. Then, you blit from your multisample FBO to the default framebuffer's back buffer to display the multisampled data.


CSAA is an NVIDIA thing, with an extension to govern its use.


FXAA is not a piece of hardware; it's an algorithm. Some drivers have control panel settings that back-door it in. That's generally a bad idea, since they can't tell when you're rendering the UI (something that shouldn't use the FXAA algorithm). So it's generally up to you to implement it.


phrase request - How can I ask a person in which order in his family among the siblings?


My colleague he have two brothers. I want to know, he is first/second/third son of his parents, ie., the order in the family among their siblings.


I can simply ask



Are you first son of your family?



It simply give some predictions, I don't want to that.



Is there a better way to ask the question?



Answer



You could ask "Are you the oldest child?" (or even "eldest child"). This seems to me to be more natural. Note the use of "the" before the adjective, which you omitted.


Pedants would note that "oldest" implies at least three children. If you know that there are only two children, then you could ask whether the colleague is the older child.


prepositions - Difference between (in / for / ∅ / during / over) the (past / last) three years



Microsoft has steadily improved its operating cash flows in the past three years.


Microsoft has steadily improved its operating cash flows in the last three years.


Microsoft has steadily improved its operating cash flows for the past three years.


Microsoft has steadily improved its operating cash flows for the last three years.


Microsoft has steadily improved its operating cash flows for the past three years. ("for" omitted)


Microsoft has steadily improved its operating cash flows for the last three years. ("for" omitted)



Microsoft has steadily improved its operating cash flows during the past three years.


Microsoft has steadily improved its operating cash flows during the last three years.


Microsoft has steadily improved its operating cash flows over the past three years.


Microsoft has steadily improved its operating cash flows over the last three years.



Which of them are idiomatic and preferred? Are they interchangeable?




translation - Meaning of expression " blanket rationale "



I strongly agree with this point, and don't buy the blanket rationale that speed trumps everything in a startup.



I couldn't find its meaning anywhere, what does blanket rationale mean?



Answer



A blanket statement is a generalization - something that covers everything, like a metaphorical blanket. There is an implication when using "blanket statement" that it may be an over-generalization. For example, "Snow is cold" is a fact; "Nobody who lives here can drive safely in the snow" is a blanket statement, and most likely not completely accurate.



A rationale is a justification, a reason to make a decision. For instance, I might put chains on my tires, and my rationale might be that heavy snowfall is predicted.


So, to put the two ideas together, a blanket rationale is a justification that may be based on an overgeneralization. In your example, the speaker believes that many startup companies justify decisions based solely on speed, and implies this is a flawed argument.


pronunciation - Is there a standard technique for practicing the "th" phonemes?



My son is still young enough to be practicing his pronunciation. He has trouble (not surprisingly) with th in particular. I have modeled the correct mouth shape for him but it still takes him a lot of effort to get the sound right. In regular speech, he just slurs the sounds into f or s depending on the word.


With his l sounds, we had a lot of success by singing "Skip to My Lou" a lot. I can't think of any children's songs that have frequent th sounds though.


Is there a current, accepted, standard technique to help him practice both the voiced and unvoiced th (which preferably don't involve sitting and saying "th, th, th" for a long time)?




Wednesday, November 22, 2017

definite article - (The?) Lions in the zoo are very aggressive




We use a plural count noun with no article if we mean all or any of that thing. For example:



Lions are very aggressive.


I don't like lions.




We only use the with general plural nouns when we are referring to a specific set within a general class of people or things. For example:



Books are so important in my life. (I mean all books in general.)


The books were all over the floor. (I mean specific books that you and I know.)






Let's say you and I are living in New York. There is only one zoo in NY. You and I know about that zoo but we have never been there.


Should I say




Lions in the zoo are very aggressive. (Lions that are in the zoo are very aggressive)



or



The lions in the zoo are very aggressive. (The lions that are in the zoo are very aggressive)





Similarly, should I say



Students in Accounting class are smart.




or



The students in Accounting class are smart.





the difference between present passive voice and present perfect passive voice


What is the difference in term of meaning between these: The order has shipped, that means you will receive it soon and it is shipped. Does it mean the same thing ?




unity - How can I implement a revealing light beam?


In SEARCHLIGHT, you control a ray of light that illuminates incoming enemies that are otherwise invisible in the night sky. Here is an illustration:


Illustration


How would I go about doing this, preferably in Unity? I imagine this is less about lighting and more about shaders, but I'm not sure on details. The fact that I know very little about coding shaders makes it worse.



If it is about shaders, what are the specifics? Is there a stretched quad that moves with said shader applied to it, or perhaps is using the Line Renderer a better option?


As a beginner, may I try to achieve a similar effect, or should I leave it for when I'm better?


(P.S.: The game was made in Unity. Here is its itch.io page.)



Answer



One way to implement an effect like this is with the stencil buffer.


This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.


You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader or Pass section:


Stencil {
Ref 1
Comp always

Pass replace
}

This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.


Then, for objects that should only show up inside the light beam, use:


Stencil {
Ref 1
Comp equal
}


This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.


Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.


unity - How to move points of a multi-segmented bezier curve to one side


I am trying to move points from a multi-segmented bezier curve to one end of the curve using the following code which modified for my use from here. Only the last segment seems to give the desired behaviour. All other segments, basically just disappear or skip through briskly.


public Vector2[] MultiSegmentCubicCurveReduction(Path curve, float start, float end)
{
List pointsForSubpath = new List();


float oneMinusStart = 1f - start;
float oneMinusEnd = 1f - end;

float scale = (end - start) / (curve.NumPoints - 1);

for (int i = 0; i < curve.NumSegments; i++)
{

var a =
oneMinusStart * oneMinusStart * oneMinusStart * curve[3*i] +

3f * oneMinusStart * oneMinusStart * start * curve[3 * i + 1] +
3f * oneMinusStart * start * start * curve[3 * i + 2] +
start * start * start * curve[3 * i + 3];

var b = a + (3f * oneMinusStart * oneMinusStart * (curve[3 * i + 1] - curve[3 * i]) +
6 * start * oneMinusStart * (curve[3 * i + 2] - curve[3 * i + 1]) +
3 * start * start * (curve[3 * i + 3] - curve[3 * i + 2])) * scale;

;


var d = oneMinusEnd * oneMinusEnd * oneMinusEnd * curve[3 * i] +
3f * oneMinusEnd * oneMinusEnd * end * curve[3 * i + 1] +
3f * oneMinusEnd * end * end * curve[3 * i + 2] +
end * end * end * curve[3 * i + 3];


var c = d - (3f * oneMinusEnd * oneMinusEnd * (curve[3 * i + 1] - curve[3 * i]) +
6 * end * oneMinusEnd * (curve[3 * i + 2] - curve[3 * i + 1]) +
3 * end * end * (curve[3 * i + 3] - curve[3 * i + 2])) * scale;


pointsForSubpath.AddRange(new List() { a, b, c, d });
}

return pointsForSubpath.Distinct().ToArray();

}

UPDATE


The brisk movement I was having earlier was actually a reduction of control points to four regardless of the number of segments. Now I am getting the following behaviour. All the points for the first segment converge to one end point whiles all the points of the remaining segments converge to the other end point, resulting in a straight line.



Answer




The code in the linked answer moves the endpoints of a single segment of a Bézier curve.


Using it on all segments simultaneously as you do here doesn't make sense. At most you want to be changing one segment at a time - the flaming tip of the wick as it burns down. Segments in the middle of the chain shouldn't change at all until their neighbouring segment on one side or the other is completely consumed.


So, let's sketch out how we'd solve this problem.


First, let's assume we have a BezierSpline type that provides an ordered, resize-able sequence of BezierSegment entries. Let's also associate with each segment an (approximate) arc length. We can use this to get a more uniform rate of motion as we contract the curve. (You can always translate this into a raw position array later, but talking about it in an object oriented fashion makes the description a bit clearer for this answer)


With this in hand, we can make a version of the IntevalFromTo method from the earlier answer that operates on a spline, rather than on a segment, producing a new spline. The version I show here is O(n) in the number of segments in the spline - you could make one that's O(log(n)) with binary search if you have exceptionally long splines, but I'm keeping it simple for now.


BezierSpline IntervalFromTo(BezierSpline sourceSpline, float start, float end) {
// Ensure our start & end parameters are in a sensible range.
Assert(start >= 0 && start <= end && end <= 1);

// Convert our relative start & end values to absolute arc length measures.

float lengthStart = start * sourceSpline.totalLength;
float lengthEnd = end * sourceSpline.totalLength;

// Scan for the first segment in our new, contracted spline,
// skipping over segments that have been completely consumed.
int firstSegment = 0;
float accumulatedLength = 0f;
while(lengthStart >= accumulatedLength + sourceSpline.GetSegment(firstSegment).length) {
// This is simple, but not strictly numerically stable,
// so you may need to exercise more care if you need high precision.

accumulatedLength += sourceSpline.GetSegment(firstSegment).length;
firstSegment++;
}

// Translate our start point into the local parameter space of the first segment.
// (For better uniformity here, you can instead search for the point at which
// the arc length along this curve exactly matches the residual)
float localStart = Clamp01((lengthStart - accumulatedLength)
/ sourceSpline.GetSegment(firstSegment).length);


int lastSegment = firstSegment;
while(lengthEnd < sourceSpline.segmentCount - 1
&& lengthEnd > accumulatedLength + sourceSpline.GetSegment(lastSegment).length) {
accumulatedLength += sourceSpline.GetSegment(lastSegment).length;
lastSegment++;
}

// Translate our end point into the local parameter space of the last segment.
// (For better uniformity here, you can instead search for the point at which
// the arc length along this curve exactly matches the residual)

float localEnd = Clamp01((lengthEnd - accumulatedLength)
/ sourceSpline.GetSegment(lastSegment).length);


int segmentCount = lastSegment - firstSegment + 1;
var modifiedSpline = new BezierSpline(segmentCount);

if (segmentCount == 1) {
// We've reduced the spline to one segment!
// Use the single-segment version of IntervalFromTo in my earlier answer.

var segment = IntervalFromTo(
sourceSpline.GetSegment(firstSegment),
localStart,
localEnd
);
modifiedSpline.SetSegment(0, segment);
} else {
// Form a shortened start segment,
// using our IntervalFromTo method for individual segments.
var segment = IntervalFromTo(

sourceSpline.GetSegment(firstSegment),
localStart,
1f
);
modifiedSpline.SetSegment(0, segment);

// Copy all intact segments between the start and end, unchanged.
for(int i = 1; i < segmentCount - 1; i++) {
modifiedSpline.SetSegment(i, sourceSpline.GetSegment(firstSegment + i));
}


// And finally, cap it off with a shortened end segment.
segment = IntervalFromTo(
sourceSpline.GetSegment(lastSegment),
0f,
localEnd
);
modifiedSpline.SetSegment(segmentCount - 1, segment);
}


return modifiedSpline;
}

Tuesday, November 21, 2017

articles - difference between the two sentences ,totally confusing for me



What is the difference between "pieces of information" and "the pieces of information"
e.g.:



  • The wages of sin is death.

  • why not?___Wages of sin is death.



Is there any method to overcome these kind of problems?


Try to explain instead of pulling leg ....




Monday, November 20, 2017

software engineering - What are good games to "earn your wings" with?



I believe that in order to become a good game developer, you need to make games.



From a programmer's perspective, what are some good entry level games to get your hands dirty? What skills and challenges do each of these games teach you?



Answer



Breakout


Easy game since you don't have much state to worry about (it's an array of brick values -- if you only have one brick color, it's an array of flags), there isn't any AI, and you get to do a little bit of physics to get the ball to bounce correctly.


Solitaire


The rules are a bit more complex than Breakout and the interface to it is a lot different. It forces you to think about different methods of implementing a game. i.e, what works in one game isn't necessarily what you would use in another.


Pac-Man


This one is nice because you get to work on a little bit of AI. Having the ghosts follow the player (but not too well - you want the player to have a chance) can be quickly implemented, and you will have a fun little game that you can tweak and show off to friends and family (positive feedback is always a good thing when you are starting out).


I find that if you look for inspiration in early video games, you can find tons of ideas that are relatively simple to implement. Plus, you can get away with super simple artwork and sounds because you're copying something so simple anyway. This allows you to focus on the basics first -- getting your game loop up and running, figuring out how to get your pixels to the screen, playing a sound, keeping score, getting the player's input into the game.


It almost really doesn't matter which game you choose first -- just make sure you pick something simple that you can get quick results with, that way you can move on the next day and make another one. And another. And another -- the more you make, the more you'll push yourself, and eventually you'll be making complex games before you know it.



opengl - FrameBuffer Render to texture not working all the way


I am learning to use Frame Buffer Objects. For this purpose, I chose to render a triangle to a texture and then map that to a quad.


When I render the triangle, I clear the color to something blue. So, when I render the texture on the quad from fbo, it only renders everything blue, but doesn't show up the triangle. I can't seem to figure out why this is happening. Can someone please help me out with this ?


I'll post the rendering code here, since glCheckFramebufferStatus doesn't complain when I setup the FBO. I've pasted the setup code at the end. Here is my rendering code:



void FrameBufferObject::Render(unsigned int elapsedGameTime)
{
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
glClearColor(0.0, 0.6, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// adjust viewport and projection matrices to texture dimensions
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0, m_FBOWidth, m_FBOHeight);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, m_FBOWidth, 0, m_FBOHeight, 1.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

DrawTriangle();

glPopAttrib();

// setting FrameBuffer back to window-specified Framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0); //unbind

// back to normal viewport and projection matrix
//glViewport(0, 0, 1280, 768);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 1.33, 1.0, 1000.0);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

render(elapsedGameTime);
}




void FrameBufferObject::DrawTriangle()
{
glPushMatrix();

glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);

glVertex2d(0, 0);
glVertex2d(m_FBOWidth, 0);
glVertex2d(m_FBOWidth, m_FBOHeight);


glEnd();

glPopMatrix();
}



void FrameBufferObject::render(unsigned int elapsedTime)
{
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, m_TextureID);

glPushMatrix();

glTranslated(0, 0, -20);

glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1);

glTexCoord2f(1, 1); glVertex3f(1,1,1);

glTexCoord2f(0, 1); glVertex3f(-1,1,1);
glTexCoord2f(0, 0); glVertex3f(-1,-1,1);
glTexCoord2f(1, 0); glVertex3f(1,-1,1);

glEnd();
glPopMatrix();

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);


}



void FrameBufferObject::Initialize()
{
// Generate FBO
glGenFramebuffers(1, &m_FBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);

// Add depth buffer as a renderbuffer to fbo

// create depth buffer id

glGenRenderbuffers(1, &m_DepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);

// allocate space to render buffer for depth buffer
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_FBOWidth, m_FBOHeight);

// attaching renderBuffer to FBO
// attach depth buffer to FBO at depth_attachment

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_DepthBuffer);

// Adding a texture to fbo
// Create a texture
glGenTextures(1, &m_TextureID);
glBindTexture(GL_TEXTURE_2D, m_TextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_FBOWidth, m_FBOHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); // onlly allocating space
glBindTexture(GL_TEXTURE_2D, 0);

// attach texture to FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureID, 0);

// Check FBO Status
if( glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "\n Error:: FrameBufferObject::Initialize() :: FBO loading not complete \n";


// switch back to window system Framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

Thanks!



Answer



Everything was fine. The triangle I was rendering for the FBO was getting clipped which is why I was not seeing anything. A translate Z of -20 is all it took to get the triangle rendering properly.


A (obvious) thing I learnt: When the user FBO is not working properly, render it to the normal framebuffer and see if what you expect to show up in the user FBO, actually shows up there. If not, you have a problem in the way you are rendering to the user FBO.


Hope it helps someone.


What makes puzzle games addictive?



I'm currently developing a puzzle game for Android that is sort of along the lines of Alchemy.


I was wondering what makes games like Alchemy or Bejeweled so addicting? How do I keep players interested in the game to want to play it over and over? Is it the scores? Level advancement? The challenges? What should I be doing to try and keep a player engaged with a puzzle game since they are often quite repetitive?




directx11 - How best to handle ID3D11InputLayout in rendering code?


I'm looking for an elegant way to handle input layouts in my directx11 code.


The problem I have that I have an Effect class and a Element class. The effect class encapsulates shaders and similar settings, and the Element class contains something that can be drawn (3d model, lanscape etc)


My drawing code sets the device shaders etc using the effect specified and then calls the draw function of the Element to draw the actual geometry contained in it.


The problem is this - I need to create an D3D11InputLayout somewhere. This really belongs in the Element class as it's no business of the rest of the system how that element chooses to represent it's vertex layout. But in order to create the object the API requires the vertex shader bytecode for the vertex shader that will be used to draw the object. In directx9 it was easy, there was no dependency so my element could contain it's own input layout structures and set them without the effect being involved.


But the Element shouldn't really have to know anything about the effect that it's being drawn with, that's just render settings, and the Element is there to provide geometry.



So I don't really know where to store and how to select the InputLayout for each draw call. I mean, I've made something work but it seems very ugly.


This makes me thing I've either missed something obvious, or else my design of having all the render settings in an Effect, the Geometry in an Element, and a 3rd party that draws it all is just flawed.


Just wondering how anyone else handles their input layouts in directx11 in a elegant way?



Answer



The way I handle this is that I have a VertexFormat.h file in which I have a bunch of input layouts of different types (VertexPositionNormal, VertexNormalUV...) wrapped in structs for easy creation/destruction. It works pretty well even though it's ugly IMO. It's very easy to add a new vertex format to the file if you have a shader that uses a layout that is not currently supported. Then I have a VertexFormatManager that creates/destroys those layouts when I need them. So when I need to create one, I feed the shader byte code and a vertexformat ID to the manager and it creates it for me and stores it in a pool so that you only ever have one of each layout. Then you need to create your geometry. To do this, I have a Create method on my geometry class that takes an ID for a vertex format. In the create function it queries the vertex format manager with the given ID. The manager returns an integer that serves as a bitfield with a flag set for every type of element the input layout contains. So I could have something like this:


int bitfield = VertexFormatManager::QueryFormat( formatID );
if (bitfield & VertexFormat::NORMAL)
{
// do somethings
}

if (bitfield & VertexFormat::UV)
{
// do somethings
}
...

Each input layout element is created into a separate ID3D11Buffer. That allows me to build a mesh given any type of vertex format. Say you want to render a cube with a texture, it needs vertex positions and uv coords. You feed it the VertexPositionUV (as an example) format ID, and the query return a bitfield contain set bits for the POSITION and UV flags. That create two ID3D11Buffers: one for the positions, one for the uv coords. Then you attach both of these to the pipeline before drawing. The advantage of doing this is that if you want to do something like shadow maps, you can render a mesh with only its vertex position buffer set.


I'm not sure much of this is very clear, I'm at work and I'll try and do a proper write up later tonight. In the mean time, I asked this question a while ago and got this answer . It's good, but I find that the way I'm doing it now makes more sense, especially in the case of DX11.


Sunday, November 19, 2017

grammar - Can we use articles with adjectives?



https://m.9gag.com/gag/aGeAxDw In this video the girl says I think I can smell the spiritual


As far as I know articles can not be used with adjectives . No?




articles - 'more' vs 'the more' - "I doubt this the more because.."



[Last Para, J Blackburn's judgment:] The difference is the same as that between buying a horse believed to be sound, and buying one believed to be warranted sound; but I doubt if it was made obvious to the jury, and I doubt this the more because I do not see much evidence to justify a finding for the defendant on this latter ground if the word “old” was not used. There may have been more evidence than is stated in the case; and the demeanour of the witnesses may have strengthened the impression produced by the evidence there was; but it does not seem a very satisfactory verdict if it proceeded on this latter ground. I agree, therefore, in the result that there should be a new trial.



Why not simply more? I guess that it modifies the bolded doubt. Please explain this? Is it an adverb?





usage - Will or Be Going To





  • They ....... (play) golf this afternoon.

  • I'm bored, I think I ....... (do) a crossword puzzle.

  • They are making a lot of noise. They .......... (wake) the baby.

  • You've got a bad cold. I ........ (make) you some soup.

  • A:Would you like something to drink?
    B:I ..... (have) a cup of tea, please.

  • We hope the dog ........ (find) his way back home.

  • C:Look at that man on the ladder!
    D: Oh no! He ........ (fall)


  • E:I don't understand this maths problem.
    F: That's OK. I ...... (help) you.

  • G: Why are you wearing those old clothes?
    H: Because I ..... (paint) the kitchen today.

  • I: Mr James left a message for you. I think it's urgent.
    J: OK. I ...... (ring) him right away.



HELP ME PLEASE! Do I use will or be going to?




How do I best remove an entity from my game loop when it is dead?


Ok so I have a big list of all my entities which I loop through and update. In AS3 I can store this as an Array (dynamic length, untyped), a Vector (typed) or a linked list (not native). At the moment I'm using Array but I plan to change to Vector or linked list if it is faster.


Anyway, my question, when an Entity is destroyed, how should I remove it from the list? I could null its position, splice it out or just set a flag on it to say "skip over me, I'm dead." I'm pooling my entities, so an Entity that is dead is quite likely to be alive again at some point. For each type of collection what is my best strategy, and which combination of collection type and removal method will work best?





Saturday, November 18, 2017

grammar - What is the difference between two sentence in meaning?




  1. I have three sons who became a doctor.


  2. I have three sons,who became a doctor.



    I want to know the difference between two sentences. Please, tell me the difference in meaning.






grammaticality - “It” vs. “that”


Is this sentence correct?



I did it yesterday, but I’m not going to do it again.



I’m not sure about it. Should I replace “it” with “that”?




  1. I did it yesterday, but I’m not going to do it again.

  2. I did it yesterday, but I’m not going to do that again.


  3. I did that yesterday, but I’m not going to do it again.

  4. I did that yesterday, but I’m not going to do that again.



Are all versions correct?




Friday, November 17, 2017

In Unity, why do my animator states wait until the end of each animation to change?


I'm trying to make a simple idle-walk transition in Animator using Unity. I've set a script that changes the Speed value from the Animator, and it works perfectly when I move the character forward when the game is on.


The transitions work well between both animations, except that they don't start automatically after the speed has changed to greater than zero.



I've found out that it waits until the animation loop gets to it's end, which makes the game feel dull and not fluid at all.




I don't think there's an issue with the code, but I'm attaching it anyway:


#pragma strict
var anim : Animator;

function Start () {
anim = GetComponent("Animator");
}


function Update () {
var move : float = Input.GetAxis ("Vertical");
anim.SetFloat("Speed",move);
transform.Rotate(0,Input.GetAxis("Horizontal"),0);
transform.Translate(0,0,(Input.GetAxis("Vertical")*Time.deltaTime*move));
}


Thursday, November 16, 2017

conditional constructions - Using the past tense to describe unreal, hypothetical, or impossible situations


I know that when the situation is unreal, we use the "if" clause plus past tense.



If you didn't know English, you would not know how to solve these problems.

[The fact is that the person knows English and probably knows how to do the problem]



My question is that: Will it be ok if I also use past tense to describe an unreal situation without using "if".



He is pretending he didn't know how to speak English.



or



He acts like he didn't know how to speak English.
[the fact is that he knows English]





Answer




{He is pretending/he acts like} he didn't know English.



You may very well encounter past forms like this in speech, where realis and irrealis forms have to be juggled and chosen on the fly. But Standard Written registers call for a realis form here:



{He is pretending/he acts like} he doesn't know English.



Although the pretense of ignorance is known to the speaker to be false, it is presented by the pretender as true, and that is how the speaker represents it. The irrealis sense resides in the main-clause verb, pretend or act like.



In your conditional example, on the other hand, the speaker presents the condition as irrealis, hypothetical or counterfactual, so the condition is expressed with an irrealis form



If you didn't know English you couldn't solve these problems.



Subordinate clauses may fall outside the "scope" of an irrealis expression:



If I were you I would tell him that you won't go unless he gives you extra time off. ... not 'wouldn't go' and 'gave'.



c# - Unity prefab script "GameObjects" can't be ones on the scene?


Currently, I have an object on the scene, and one in prefab. I want the prefab's script to reference to the object on the scene through the


public GameObject obj;

code. However, when I tried to add the object in the editor, I cant seem to be able to select any objects from the scene, only ones in prefabs.


I am quite new at unity, so am I missing something really basic here?


Thanks for any help!




Answer



If you have the gameobject with the code attached selected, you can drag the gameobject in the scene using the hierarchy to the inspector.


Confusing I know, here is a picture:


enter image description here


EDIT: Strike that, this is more accurate:


With unity, you can not reference things in the hierarchy from a prefab. You need to somehow add it at runtime. A cheap way to do this is to store 'the gameobject in the scene' in a static variable. For instance something like:


public static GameObject thingonstage;
void Start(){
thingonstage = this.gameobject;
}


Then later, you reference the static global variable to get at it.


c++ - How are deterministic games possible in the face of floating-point non-determinism?


To make a game like an RTS networked, I've seen a number of answers here suggest to make the game completely deterministic; then you only have to transfer the users' actions to each other, and lag what's displayed a little bit in order to "lock in" everyone's input before the next frame is rendered. Then things like unit's positions, health, etc. don't need to be constantly updated over the network, because every player's simulation will be exactly the same. I've also heard the same thing suggested for making replays.



However, since floating-point calculations are non-deterministic between machines, or even between different compilations of the same program on the same machine, is this really possible to do? How do we prevent that fact from causing small differences between players (or replays) that ripple throughout the game?


I've heard some people suggest avoiding floating-point numbers altogether and using int to represent the quotient of a fraction, but that doesn't sound practical to me - what if I need to, for example, take the cosine of an angle? Do I seriously need to rewrite an entire math library?


Note that I am mainly interested in C#, which as far as I can tell, has exactly the same problems as C++ in this regard.



Answer



Are floating-points deterministic?


I did a lot of reading on this issue a few years back when I wanted to write an RTS using the same lockstep architecture you do.


My conclusions about hardware floating-points were:



  • The same native assembly code is most likely deterministic provided you're careful with floating point flags and compiler settings.

  • There was one open source RTS project that claimed they got deterministic C/C++ compiles across different compilers using a wrapper library. I didn't verify that claim. (If I recall correctly it was about the STREFLOP library)


  • The .net JIT is allowed quite a bit of leeway. In particular it is allowed to use higher accuracy than requires. Also it uses different instruction sets on x86 and AMD64 (I think on x86 it uses the x87, AMD64 it uses some SSE instructions whose behavior differs for denorms).

  • Complex instructions (including trigonometric function, exponentials, logarithms) are especially problematic.


I concluded that it's impossible to use the built in floating point types in .net deterministically.


Possible Workarounds


Thus I needed workarounds. I considered:



  1. Implement FixedPoint32 in C#. While this is not too hard(I have a half finished implementation) the very small range of values makes it annoying to use. You have to be careful at all times so you neither overflow, nor lose too much precision. In the end I found this not easier than using integers directly.

  2. Implement FixedPoint64 in C#. I found this rather hard to do. For some operations intermediate integers of 128bit would be useful. But .net doesn't offer such a type.

  3. Use native code for the math operations which is deterministic on one platform. Incurs the overhead of a delegate call on every math operation. Loses ability to run cross platform.


  4. Use Decimal. But it's slow, takes a lot of memory and easily throws exceptions (division by 0, overflows). It's very nice for financial use, but no good fit for games.

  5. Implement a custom 32 bit floating-point. Sounded rather difficult at first. The lack of a BitScanReverse intrinsic causes a few annoyances when implementing this.


My SoftFloat


Inspired by your post on StackOverflow, I've just started implementing a 32 bit floating-point type in software and the results are promising.



  • The memory representation is binary compatible with IEEE floats, so I can reinterpret cast when outputting them to graphics code.

  • It supports SubNorms, infinities and NaNs.

  • The exact results are not identical to the IEEE results, but that usually doesn't matter for games. In this kind of code it only matters that the result is the same for all users, not that it's accurate to the last digit.

  • Performance is decent. A trivial test showed that it can do about 75MFLOPS compared 220-260MFLOPS with float for addition/multiplication(Single thread on a 2.66GHz i3). If anybody has good floating point benchmarks for .net please send them to me, since my current test is very rudimentary.


  • Rounding can be improved. Currently it truncates, which roughly corresponds to rounding towards zero.

  • It's still very incomplete. Currently division, casts and complex math operations are missing.


If anybody want to contribute tests or improve the code, just contact me, or issue a pull request on github. https://github.com/CodesInChaos/SoftFloat


Other sources of indeterminism


There are also other sources of indeterminism in .net.



  • iterating over a Dictionary or HashSet returns the elements in an undefined order.

  • object.GetHashCode() differs from run to run.

  • The implementation of the built in Random class is unspecified, use your own.


  • Multithreading with naive locking leads to reordering and differing results. Be very careful to use threads correctly.

  • When WeakReferences lose their target is indeterministic because the GC may run at any time.


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