Wednesday, July 31, 2019

phrase meaning - What do "have", "get" and "got" mean?


In my language have has exactly two different meanings. First is possess. In the following sentences I can replace have with posses,


I have a pen = I possess a pen
I have a car = I possess a car
I have this book = I possess this book


the second meaning is forced to do or must do. In simple language have means, that I have no other choice, I must do this. In the following sentences I can replace have with forced.


I have to go now = I am forced to go now I have to kill him = I am forced to kill him


I guess that in English have is not equivalent to forced to. Actually it seems that have in the above written two sentences means that I posses that job.



I have to go = I possess a job, and the job is to go
I have to kill him = I possess a job, and the job is to kill him


I also do not understand why sometimes in English got is used with have, e.g.


I have got to go now.
I have got this car.


What does got mean in: "I got to go" or "I get to go". Is get=got=have? As I understand get means possess.




npc - What behaviors should go into making a "non-perfect" AI combatant?


When making an npc combatant, it's easy obvious what to do to get a robot deathmachine by optimizing combat tactics, timing and attack types, but harder (and more interesting in a fight) to get an idiosyncratic, inpredictable enemy. What behaviors (algorithms?) are useful for creating a more organic, unconventional enemy?



Edit: My specific use case is with MMO-like enemies, e.g. World of Warcraft, although with less graphics involved. Note that that means both human and inhuman enemies (animals, monsters, etc)




Tuesday, July 30, 2019

meaning - Could you vs would you




  1. Could you write your name?




  2. Would you write your name?




When you are asked to do this, are there any situation in which you hear weird if either is used (but the other sounds pretty natural .)





grammaticality - About the sentence "Do you have any idea"



Are the following sentences grammatically correct?




  1. Do you have any idea to prove it?

  2. Do you have any idea how to prove it?

  3. Do you have any idea about proving it?





Monday, July 29, 2019

python - Finding vectors with two points



We're are trying to get the direction of a projectile but we can't find out how


For example:


[1,1] will go SE


[1,-1] will go NE


[-1,-1] will go NW


and [-1,1] will go SW


we need an equation of some sort that will take the player pos and the mouse pos and find which direction the projectile needs to go.


Here is where we are plugging in the vectors:


def update(self):


self.rect.x += self.vector[0]
self.rect.y += self.vector[1]

Then we are blitting the projectile at the rects coords.



Answer



To compute a direction you just need subtraction, and ideally normalisation.


self.vector = (mouse.position - player.position).normalize()

Note that your loop update should take the velocity and time between two frames into account:


self.rect.x += speed * timestep * self.vector[0]

self.rect.y += speed * timestep * self.vector[1]

meaning - what does this guy mean by "Pulling on my flameproof underwear"?


There is a guy who said something strange to me https://cs.stackexchange.com/questions/24137/is-the-way-an-os-schedule-threads-related-to-parallel-computing#comment48182_24137



Pulling on my flameproof underwear



What did he mean by that? thanks.


Btw, what is the purpose of making underwear flameproof?




multithreading - How many threads should an Android game use?



At minimum, an OpenGL Android game has a UI thread and a Renderer thread created by GLSurfaceView. Renderer.onDrawFrame() should be doing a minimum of work to get the higest FPS. The physics, AI, etc. don't need to run every frame, so we can put those in another thread. Now we have:



  1. Renderer thread - Update animations and draw polys

  2. Game thread - Logic & periodic physics, AI, etc. updates

  3. UI thread - Android UI interaction only


Since you don't ever want to block the UI thread, I run one more thread for the game logic. Maybe that's not necessary though? Is there ever a reason to run game logic in the renderer thread?



Answer



Google's Chris Pruett talks about this issue in his Replica Island blog. Because eglSwapBuffers() is a blocking call in the GLSurfaceView thread, having game logic code in another thread allows it to run while the swap buffers call is blocking. This is important if your game is complex and you want to achieve 60 frames per second.


You can download the source code for Replica Island and see how they did it. I've implemented something similar for my game (with the three threads you talked about) and it works great.



Can the solar system be accurately represented in 3d space using doubles (or longs)?


I would like know to how to best manage coordinates in a 3D game whose aim is to realistically model the entire solar system, yet be able to handle the smallest movements in a "ship" (ie: perhaps we can consider 1cm to be the smallest acceptable movement for a frame). Do 64-bit doubles (or 64-bit longs) support this, or do we run into overflow problems? If not, then should longs or doubles be used, or if so, then which alternative approach do you think is the most sensible for modelling positions in the solar system in a 3D game? (ie: only holding a bit of the system in the display at a time based on distance to ship, or having the system somehow represented in a different co-ordinate space etc)



Answer



There's already a good answer about integers, but I feel like floating-points shouldn't be eliminated. In his answer, Byte56 took the option to go for the maximum orbit of Pluto, probably taken from this excel sheet, so I'll stick to that.


That places the solar system boundaries at:


7,376,000,000 km = 7.376x10^9 km = 7.376x10^14 cm ≈ 7.4x10^14 cm


The Double-Precision floating-point format offers a maximum precision of 15 significant decimals. So you're lucky: if your origin is at the Sun's center and you use a position around Pluto, you can represent all centimeters, e.g. in C++:


printf("%.0Lf\n", 7.4e14);
printf("%.0Lf\n", 7.4e14 + 1.0);
printf("%.0Lf\n", 7.4e14 + 2.0);


Output:
-------
740000000000000
740000000000001
740000000000002

So if you can limit your game to the orbit of Pluto, then congratulations! You've got just enough precision with doubles to represent it.


Beware though, that's enough to represent it in a simulation, but don't expect to render this painlessly. You'll have to convert to 32-bit floats, maybe change your origin so you get enough precision on the close objects, and you'll probably have to rely on some Z-buffer and camera frustum trickery to get all this to render properly.


Now, if you want your astronauts to visit some far away comets in the Oort cloud, which is way bigger, then it's over. Around 10^16 cm, you start loosing accuracy:



printf("%.0Lf\n", 1.0e16);
printf("%.0Lf\n", 1.0e16 + 1.0);
printf("%.0Lf\n", 1.0e16 + 2.0);

Output:
-------
10000000000000000
10000000000000000 <-- oops
10000000000000002


And it gets worse further on, of course.


So if you're in this case, you might want to try some more advanced solutions. I suggest you take a look at Peter Freeze's article in Game Programming Gems 4: "2.3 Solving Accuracy Problems in Large World Coordinates". IIRC, he suggest a system that might suit your needs, it's indeed some kind of multiple different co-ordinate spaces.


That's just some hints, you'll probably have to use some recipe of you own to get this running. Somebody that already implemented that kind of stuff might help you more. Why not firing an email to the guys behind Kerbal Space Program for instance?


Good luck with your game!


prepositions - Prepositional Phrase - confused - at or in


Let's meet in the morning or at the morning.


in the afternoon or at the afternoon.


in the night or at the night.



in the park or at the park.


working in the background or at the background.



Answer



Let's take them one at a time:


Let's meet [in or at] the (morning or afternoon).

This is to meet at a general time in the next (most immediate) morning. "In" is the correct choice. The resolution applies to both 'morning' and 'afternoon,' as each refers to a non-specific time frame.


Let's meet [in or at] the night.

"The" here is where one might trip. For someone proposing a clandestine effort, to say "Let's meet in the night" is arguably plausible if uncommon. More conventionally, however, one would say "Let's meet at night," with no need to use the definite article "the," as each day has only one night.



Let's meet [in or at] the park.

You can make a valid case for either preposition. The park is a specific location when seen on a map, but any location within the park is also "in" the park.


working (in or at) the background

In most contexts, foreground and background are an abstract, relative relationship, not a fixed point, thus making it difficult to rationalize "at." If you have, for example, three layers, the middle is in the foreground relative to the rear-most layer, but in the background relative to the nearest layer. Also, since "working" implies a use of the word "background" in a notional sense of a secondary process or task, not a specific place, I would almost always recommend "in" as the correct choice.


sentence construction - mixed tenses/tenses agreement




  1. Would it be okay if I called you when I got back home?


  2. Would it be okay if I called you when I get back home?



Are both the above sentences grammatically correct? I'm still kinda confused with the tenses agreement thing. And how backshifting works. What i don't get is,do i have to convert the entire sentence to the past,or do i have convert certain parts of the sentence to the past. Or whether i should keep a sentence where i have past tense strictly to the past.


Like:




  1. I was walking down the street the other day, and it hit me how the world worked.

  2. I was walking down the street the other day, and it hit me how the world works.




Do I keep the sentence to the past? Or do I mix tenses?



Answer



It's worth remembering that morphologically, English only has two tenses (present, and "not-present").


By morphological I mean that verbs themselves are only modified for tense by adding -ed to make "non-present" (there's ing to make "continuous", but that's an aspect, not a tense). For all other "tense" differences, we need auxiliary verbs (be, have and things like will, would, should, could).


Probably because of that, we're quite happy to use got in the first example (it's a hypothetical/future situation, where got actually implies "not-present" rather than "past"). In the second example, past tense worked simply echoes the past tense struck me.


Note that present tense is also fine in both cases.


Sunday, July 28, 2019

Blender multiple animations and Collada export


Say I have a simple mesh in Blender, with two keyframes, like so:


Left right keyframe 1 Left right keyframe 2



Then, another animation for the same mesh, also with two keyframes:


Up down keyframe 1 Up down keyframe 2


Theese animations worke fine in Blender and I can switch between them in the Dopesheet, where they are called "actions":


Dopesheet


The problem arises, when i try to export this to the Collada format, for use in my game engine. The only animation/action that seems to be carried over, is the one currently associated to the mesh. Is it possible to export multiple animations/actions for the same mesh, to the Collada format?



Answer



The Collada exporter in blender does not support what Collada calls "animation clips", so only the current animation will be exported. You have a few options I can think of:



  1. Fix the exporter (or convince someone to do it for you).

  2. Write a script that loops through the actions and exports a new file for each action.


  3. Use the NLA editor to create a track that has all the actions in sequence.

  4. Export to another format that is easier to work with.


Obviously the first choice would be most appreciated by everyone else coming across this problem in the future.


interrogatives - How did you like the concert?



How did you like the concert? (Cambridge dictionary)



When there are interrogative words, inversions, gaps (I don’t know if there are gaps in this example), it’s just like getting through a long tunnel, in a foggy morning, on a calm highway. Next is my flash on the construction. Would you check what is wrong? First, I’d like to change the sentence into an in situ question to make my saying better.



You liked the concert how?



From this, I suppose that ‘the concert how’ is a small clause or verbless clause. I mean ‘you were pleasant that [the concert (is) how]?’ From the word, liked, the speaker expects the listener would have enjoyed the concert, yet he likes to know ‘the concert was how’ for the listener. So the replying words would be approving, descriptive words for the concert.



Answer




You liked the concert how? sounds very unnatural to a typical American. In most cases, the question would immediately identify the questioner as a non-native English speaker. How did you like the concert? is the correct and typical way to ask the question.


However, there is a case in which You liked the concert how? can be correct in conversational American English.



Person 1: How did you like the concert?


Person 2: I liked it. I plugged my ears and closed my eyes.


Person 1: You liked the concert how? (The vocal intonation heavily emphasizes how.)



Person 1 is essentially saying, I can't believe you enjoyed the concert like that. Can you confirm that you really meant what I heard? Person 2 has already provided some information. Person 1 is expressing disbelief or astonishment, and asking for clarification. You liked the concert how? is not the initial inquiry.


Here are some more examples:




The concert started when? (After hearing the concert started 3 hours late.)


The concert was held where? (After hearing the concert for a popular group was held in a too-small venue.)



These examples are exceptions, and are probably only used in informal, conversational English.


c++ - Surface creation algorithm using points cloud


I am looking for a realtime algorithm to create a 2D mesh using points. But I am quite confused. It seems that Delaunay triangulation can help me create mesh using point clouds, but Meta-balls seems also useful for isolated points for example. And what about concave shapes ?


I am looking for interesting links, white-papers, code sample, etc...


Here is an example of what I am trying to achieve. As you can see the aim is to create a 2D fluid surface.


In red should be the generated mesh, I tried to reproduce the special condition that could happen like concave shape, isolated points, etc. In black you can see the points used to create the shape.


example


Thank you.




Answer



You may do what you need in 2 step:




  1. Clustering: First you can cluster your point. There are many clustering algorithms which will put your points into multiple close-distance group. K-means is one of your options.




  2. Convex Hull: Then you can create Convex Hull for each cluster. such as: Gift wrapping algorithm, Quick Hull, Bridge, ...





There is a trade-off between simplicity and performance issue for named algorithms.


As you run these algorithms in real-time, your case go to performance-intensive category which need some research in order to find best algorithms for your game.


word usage - "There you go" or "There you are"


Suppose a friend advises you too much and you don't like it; you are tired and say to the third person who is a common friend for both of you. You begin to complain and say:





  • There you go, on his high horse again



I need to know if in the sentence above we can use 'are' instead of 'go' or not?



Answer



there you go can be used in three ways:


1) when giving something to someone, usually after a request for the thing, such as giving someone goods that they have bought


2) to mean "I told you so"


3) to express the fact that you cannot change a situation so you must accept it.


In British English, there you are can only be used for the first meaning, and possibly the second meaning. In the sentence that you quoted, the intended meaning is the third one, and so you cannot replace it with there you are.



unity - Moving autonomous robot form one location to another based on array


I have a 3D model of a house, and I want an autonomous robot to move from 1 object in this house to the next one. I have it moving to the first, but it won't move to the second one. This is my code:


using UnityEngine;
using System.Collections;

public class MoveTo : MonoBehaviour {

public Transform[] goals;


void Start () {
NavMeshAgent agent = GetComponent ();
agent.destination = goals[0].position;

if (agent.transform.position == goals[0].position) {
agent.destination = goals[1].position;
}

}

}

I'm a complete beginner in code, please keep that in mind :)



Answer



The Start method is only executed once at start and the NavmeshAgent won't start moving the object before the Start method finished. The moving happens between calls to Update.


So check if you reached the destination in your Update method, not your Start method.


I would also recommend you to use agent.remainingDistance to check if the destination is reached. Comparing positions for equality is quite error-prone because even though the == operator for Vector3 is overloaded for returning true even when the positions are just almost identical, Unity's definition of close enough might be different than yours. If you want to compare positions, at least do it by checking if their distance is smaller than what you would consider close enough for "being there".


Friday, July 26, 2019

It had been a long time since + Past Perfect or Past Simple


I would like to know which one is correct when the structure refers to a past event.


Past Perfect + Past Simple - It had been a long time since I met her.


Past Perfect + Past Perfect - It had been a long time since I had met her.




xna - Why even use shaders?


assuming I want my game to have a Cel-shaded look. There are plenty of tutorials how to implement Cel-shading in hlsl f.e. But what is the point? If I am creating my assets with Blender or 3d-max I have a lot of possibilities to add materials and shaders in the modeling software.


So why write shaders?



Answer



First, ok-to-good question. Definitely not a bad question. To answer it, you just have to know what a shader is and why you need one.


A shader is exactly what it sounds like - it "shades" vertices and pixels different colors. "Shading" isn't just "making it darker" (as the technical artistic term means I believe), it's application of textures, lighting, and everything else that gives a vertex it's final color.


"Shading" often makes the most sense if you think about some light source. You can't really have toon shading without a light source. You have to have light (and an angle to the light) to know how to shade an object in that light. And that's the job of the shader.


So, now you have a vertex/pixel shader that will do toon shading in Blender. Great. Why do you need to know HLSL if you can make a toon shader in Blender?


If Blender exports HLSL code that you can plug into XNA, then you don't need to write the HLSL yourself. You are correct. You wouldn't need to hear about, see, or touch HLSL code if Blender exports it for you. But I'm not sure if Blender can do that.


So if Blender does not HLSL shading code, then you need to write a toon shader in HLSL because all you'd get is the model and vertices and their respective solid colors, but you wouldn't get "how it should look at every single angle and under every possible light source" right - that needs to be computed at runtime (by a shader).



writing - Job Titles Capitalization


The rules for the capitalization of job titles are not very clear.
After I've read some internet articles (for instance, this Capitalization of job title question) I compiled some rules:


a) It goes before the name of a person:




Professor Adams or Director Joe Brown.



b) It goes immediately after the name of the person:



John Williams, Chairman, will attend the meeting.



Note: if it has "the", we do not capitalize:
Mrs Smith, the chairwoman of the company x, is retiring.

c) In signatures lines at the end of a letter or email:




Sincerely,
Sarah Stevens, President



But then, while browsing a well-known job search website I saw ALL the job titles capitalized in the jobs descriptions:



We are seeking to recruit an exceptional individual as Office Manager for the Registry team.


We are seeking to appoint a number of Teaching Assistants to support pupils' learning and to raise attainment.



and in a common English grammar book I see:




What do you do?
I am a receptionist.



Can somebody explain me the right to way to capitalize a job title?




Thursday, July 25, 2019

libgdx - How can I check if a player-drawn line follows a path?


I want to draw an invisible path that the user must follow. I've stored that path as points. When a player draws a line, how can I test if it follows the path I've stored?


Here's an example for tracing the letter A.


example trace


if((traitSprite.getX()<=Invisible.X  && traitSprite.getX()>=Invisible.X )){...}

(traitSprite is a sprite.)



Answer



Here's a vector-based solution. I haven't tried it, but it seems fine conceptually.




I gather you've stored the shape as line segments. Here's the letter A represented with three line segments.


line segments representing a letter


I've assumed that paths in the user's drawing are stored as lists of points.


We can "inflate" those line segments to allow an error margin when checking for nearness: whether the user's drawn path is near the correct lines error margin.


user-drawn path on top of letter with error margins


However, that alone is not enough. We also have to check for coverage: whether the user's drawing "covers" a large fraction of the shape. These drawings are bad, because even though they fit within the error margin, they're missing some part of the letter:


bad drawings


If we check both of those things, we can approximate if the player's drawing is good.



Checking nearness just means for each user path point, finding the distance between that and every line making up the letter, taking the lowest and checking it's less than the error margin.



Checking coverage is more complicated, but you can get a very good approximation with vector math if for each line segment, you find the nearest user-drawn path (green) and project its parts (dark green) onto that line segment (black), then check for how well the projected vectors (blue) cover it:


coverage-check by vector projection


To project a vector a onto another vector b, do


projection = dotProduct(a, b) / lengthSquared(b) * b

where dotProduct computes the dot product of the two vectors and lengthSquared is what it sounds like. Essentially, this finds the scalar value of how much a goes in b's direction and multiplies b by that to get a vector in the same direction. (Metanet Software's collision detection tutorial A has a nice visualisation of this in Appendix A § projection.)


The direction of the projected vector might not actually be important. If you just sum together the lengths of the projected vectors and compare them to the total length of the line segment, that will tell you what fraction of it is covered. (Except in odd cases—see §Limitations below).


In the above image, the path would cover about half of the segment. You could pick any tolerance value you want.



Curved letters



Line segments are sub-ideal: Many letters are curved! How do you represent a ‘P’ or an ‘O’?


You could use many line segments (maybe with a larger error margin).


letter P approximated with line segments letter O approximated with line segments


You also could start using Bézier curves instead of lines for a closer fit, but note that finding the closest point on a Bézier is much more complex—as are many other measurement operations.


Mismatches


Overly relaxed tolerance margins for distance from the lines and coverage of the letter could have unintended consequences.


For example, the player might have been trying to draw an ‘H’ here.


a letter H mistakenly recognised as an A


Loops and overlaps


loop and overlap in (possibly) recognised letter



Loops or overlaps in the player-drawn path could result in some parts of the drawing being counted twice when projecting them onto the nearest line segment.


This could be worked around by doing fancier processing on the projected vectors, perhaps storing exactly where the projected vector would be (store the direction of the projection too, and the closest point on the line segment to the point on the player-drawn line), then rejecting new ones that overlap it.


If the player drew a single path and it was processed starting at the end marked with the blue circle, the green parts of that path would be accepted and the red ones rejected, because their projection would overlap with some parts processed before.


rejecting loops and overlaps


The implementation has many technical subtleties that would probably belong in a different question.


Unpredictably adventurous players


A player might draw something weird that still passes.


trolololol


Although you could call that a feature! :)


costs - Where does the money to make a video game come from?


So 360/ps3 video games takes a few months to a few years to make I assume. If so where does the money to pay employees and costs of everything needed to make the game come from during those few months/few years?




c# - How do I build a 3D array result set from a compute shader in unity?


I took this right down to the absolute most basic scenario but for some reason I can't get anything back from the GPU when this completes, could someone explain what I am doing wrong ...



Here's my CPU code:


using (var debugBuffer = new ComputeBuffer(27, sizeof(int)))
{
var kernel = compute.FindKernel("DoStuff");
compute.SetBuffer(kernel, "debug", debugBuffer);
MeshGenerator.Dispatch(kernel, 1, 1, 1);

var debug = new int[3, 3, 3];
debugBuffer.GetData(debug);
debugBuffer.Release();

}

And here is my GPU code:


#pragma kernel DoStuff

RWTexture3D debug;

[numthreads(3,3,3)]
void DoStuff (uint3 id : SV_DispatchThreadID)
{

debug[id] = 1;
}

The resulting 3D array is full of 0's and all documentation suggests that I should have a buffer full of 1's


EDIT:


Very curious behaviour ... so I am using compute to generate sets of voxel data and then generate meshes for the data, I created a simple voxel gen to fill only the center voxel in a 3,3,3 array like this ...


#pragma kernel GenerateChunk

struct voxel
{

float weight;
uint type;
};

voxel newVoxel(float weight, uint type)
{
voxel voxel;
voxel.weight = weight;
voxel.type = type;
return voxel;

};

// params for voxel generation
int3 from;
int3 to;

// the voxel generation result buffer
RWTexture3D voxels;

[numthreads(3,3,3)]

void GenerateChunk (uint3 threadId : SV_DispatchThreadID)
{
int3 pos = threadId + from;

bool xOk = (pos.x > 0 && pos.x < to.x);
bool yOk = (pos.y > 0 && pos.y < to.y);
bool zOk = (pos.z > 0 && pos.z < to.z);
bool ok = (xOk && yOk && zOk);

if (ok)

{
voxels[threadId] = newVoxel(1, 1);
}

if(!ok)
{
voxels[threadId] = newVoxel(-1, 0);
}
}


Calling this up in the same way as my original question results in me getting what appears to be a not populated buffer of voxels however, before I started this I created all this code as cpu based versions.


If I take my "not populated voxel buffer" and run that through my meshing code on the cpu I get as expected a single cube.


I'm now not sure how it's possible to debug the results of a compute shader since it seems that you cannot view the data using the debugger in visual studio.


I'm going to take a look in unity's built in MonoDevelop IDE and see if that shows anything but it may be that my original question was actually not even broken code in the first place!


EDIT2:


Ok MonoDevelop doesn't work either, nor does logging out the data using UnityEngine.Debug.Log();


As per the code, all values are -1 for the weights of my voxels except for the center voxel in my 3,3,3 grid and yet debugging / logging out any of the values always reports 0.


The cpu code appears to get what Iwould expect though and outputs the right result.


Now I have a problem when my gpu based meshing code doesn't work and I have no way to determine why ... does anyone have any ideas how I might be able to debug this code without apparently logging or using an IDE?


... jeez unity!!!



EDIT3:


I have spoken to unity about this by way of a bug, they initially stated that the problem was in my code but that was before I extracted this simple demo of the problem, I raised the problem in the unity forums too in the hope that someone with internal unity knowledge might be able to see something I can't, that discussion is here: http://forum.unity3d.com/threads/compute-shaders-populating-buffers-reading-computed-results-and-general-debugging-advice.385297/


It looks like my next step is to build the same scenario in raw DX perhaps using SharpDX to talk to DX's API directly that would at least tell me if a "RWTexture3D" buffer can be mapped to an array in this manner.


Personal note:


I can't believe that noone has faced this problem before, surely someone out there has seen this? I mean ... even the 2D scenario isn't doing what I think makes sense and if your problem is 1D then why use the GPU at all right?


Someone therefore must know the answer to this, my gut feeling is that there is some underlying architectural reason why a 3D buffer can't just be created like this, maybe it's worth asking the guys over at nVidia this question!



Answer



So it turns out if you put the data in to a standard structured buffer on the gpu in the right order you can basically just pull that data in to a 3d array on the cpu.


It requires you to flatten your indexes in to the buffer on the gpu in to 1d indexes but it's pretty clean on the cpu at least.


Not quite what I wanted as I wanted to have a 3d container for the data on both the cpu and the gpu but since unity technologies had nothing to offer I assume it must not be possible right now.



unity - Turn and point Animation not ending in correct position


I have Right Turn, Point & talk Mixamo animation. I am playing animation in this order



  1. Play Idle animation

  2. Turn animation

  3. Point Animation

  4. Then, run Turn animation again with - speed to bring it back(reverse)

  5. and then finally played Idle animation and loop continue.



enter image description here


But the problem is, each time when I return from step 4 my character rotation is different. And over different iterations the character rotation become completely changed. The rotation of the character increment in each iteration. How can I solve this problem? I am learning this but unable to understand.




Wednesday, July 24, 2019

grammar - Question about "surely" and "certainly"


Today I saw a sentence:




She surely can do it.



What does that mean? How does it differ from:



She certainly can do it.


Surely she can do it.



This slight difference in meaning of those sentences I am not able to notice. Could you please help me? Thanks in advance!




past tense - '... has been injured for about a week now' vs. '... was injured for about a week now'




Kitty: 'Jair, my middle finger has been injured for about a week now'. (1)


Kitty: 'Jair, my middle finger was injured for about a week now'. (2)



Could now be ungrammatical in (2)? Or, otherwise, (1) means that Kitty's finger hasn't yet healed, whereas (2) implies that that finger is no longer damaged -- e.g., it works?




politeness - The difference between "I am" and "My name is" in a face-to-face meeting


Not all my English language teachers are native speaker, but they told me that "never use I'm FirstName LastName when you introduce yourself".


Instead they told me that when trying to introduce yourself to new people, I may say "Hi, my name is FirstName LastName, you can call me Kitty..."


I wonder under What circumstance I can say "I am ..." ?


Is it informal and incorrect for one to say "I am FirstName LastName" in a face-to-face meeting ?


If, when I meet with my favourite pop singer in the street, I will probably say to her / him "I am FirstName LastName. I am a big fan of yours"


Edited:
I remembered that they had also told me not to say "I am nickName" when telling someone else who you are on the phone.




Answer




Never use "I'm John Smith" when you introduce yourself; instead, use "My name is John Smith."



I would agree with this much: in general, using "my name is" is probably preferable to "I am", because there is more to who we are than our name.


That said, I think never use is a bit overly strong, although I wouldn't be surprised to learn a non-native-speaking English teacher was offering that advice. Language teachers can sometimes be a bit stuffy, and woefully unaware of oft-used, informal conventions.


Most native speakers aren't going to bat an eye if you say, "Hello, I'm David." It's normal, idiomatic conversational speech.


Moreover, there are times where "Hello, I'm David," might be the most natural way to say your name.


Suppose you are one of four people are seated in a circle in a classroom. Your name is John Smith. The teacher asks you all to introduce yourselves to one another, and the person to your left begins:




"Hi, I'm David Carson."



and then it continues clockwise around the circle:



"Mike Jones" [uttered with a quick wave]
"Hello." [smiles and nods] "Linda Everett."



Now it's your turn. Follow the advice of your English teacher, and you'll mechanically say,



"My name is John Smith."




Truth is, "I'm John Smith" would have been just fine. Most likely, no one is going to think David Carson is an idiot who does not know the right way to introduce himself.




As I write this answer, I'm imagining myself in different settings, giving my name for the first time.


I think tone can be as important as word choice. Give your name as if you're God's gift to the world, and it can sound either mechanical or pretentious.


Context is also important. "I am..." sounds natural if you are giving your name plus some additional information:



I am David Carson, the marketing director for Acme Corporation.



which is a nicely condensed form of:




My name is David Carson, and I am the marketing director for Acme Corporation.





Lastly, conspicuously absent from your question is the difference between "I am David Carson," and "I'm David Carson." The contracted version can sound more approachable and friendly, while the longer version can sound more stiff and pretentious. That said, mannerisms such as warm smiles, friendly nods, affable handshakes, and welcoming intonations also play a big role in how your introduction will be perceived.


If you're too worried about the words you use, that might have an adverse affect. Just relax and tell us who you are.


Tuesday, July 23, 2019

c# - Are there any good engines for isometric collision detection and platforming?


I've decided to resurrect an old game idea I had years ago. I currently have zero experience with programming, but I'm going to begin studying either C#, Python or both in the near future.


The issue I'm currently facing is that what I plan on making is an isometric Metroidvania-type game, similar to that old GBA title Scurge: Hive on a very basic level. Naturally, this means that there will be some emphasis on platforming. The problem is, I hear that programming those kinds of physics into a 2D game is highly impractical. General consensus, from what I've seen, seems to be that it's easier to just make isometric games in 3D so that programming collision detection and the like is simpler.


I really want this to be a 2D game, as I have absolutely no experience with 3D modeling. Yet I also don't want to have to build the entire underlying physics engine from scratch. I've looked around a bit and there don't seem to be any engines for this type of game that are compatible with C# or Python. There are isometric engines, but most seemed to be geared toward 3D games and RPGs.


So I guess what I'm trying to ask is, are there any engines available that would make it easier to program an isometric 2D platformer? Or would I have to do the collision detection coding myself?


(As an aside, while I'm considering both #C and Python, I'm leaning toward Python due to the fact that it's multiplatform and apparently better for beginners. So please take that into consideration if possible.)



Edit: After some more research, I've chosen to go with Lua, but I may still study Python and C# as well if possible. Hopefully I'm not biting off more than I can chew.



Answer



Whoever's general consensus you have, is wrong. There is nothing special needed to implement collision detection in an isometric game. It is no different from implementing collision detection in Robotron or even Pitfall. This is a common misconception, and one that often leads to a lot of struggling. On contract recently I met a senior developer who couldn't for the life of him fix a broken isometric engine's collision detection, and furthermore refused to rewrite the thing, because he didn't grok what I am about to tell you.


Consider an isometrically-rendered space. Is that space, the actual space, what you see on the screen? No, that is just a representation. In reality it is a set of underlying data in memory, and that data is a 2D array (or a set of them, layered by height). From a visual perspective, that space could just as easily be imagined as an orthogonal top down view (a la Robotron), with left=-x, right=+x, up=-y, down=+y, -z=out, +z=in, and it is pragmatic to visualize your data structure as such. In other words, imagine the game as orthogonal top-down, do all physics and other logic in that mode, but then perform transformations into an isometric format for the purposes of rendering only. I advise you to first render as vectors i.e. using points/lines/squares: An article like this one will help you get the basics right for point placement using isometric transformations, and subsequent line drawing between those points. Then after some tweaking you will see from your drawn lines, what your isometric tile sizes and character sizes should be. You could then take screenshots (or save bitmap data to disk) and use these ("diamonds") as the bases for your sprites.


The key distinction to be made here is that what you see is not the data model of your game. It is only a representation thereof. No special engine is required to do any of what you want to do, easily.


sentence meaning - Did remember/ remembered


There is a sentence from GoT: And perhaps the dragon did remember, but Dany could not


What the differences between sentences:



And perhaps he did remember, but she could not


And perhaps he remembered, but she could not




Is it correct to use did + Verb?



Answer



It is an idiomatic usage of do/does/did to add emphasis to the verb they precede:



We do not normally use do or does in affirmative sentences, but we can use them for emotive or contrastive emphasis when we feel strongly about something:




  • *She thinks he doesn't love her, but he does love her. He really does!





  • You do look pretty in that new outfit! Quite stunning!




  • Are you all right? You do look a bit pale. Do please sit down.




  • I don't see very much of my old friends now, but I do still email them. Was that a joke? I do believe you're teasing me!*





When we are using the auxiliaries do and does for contrastive or emotive emphasis like this, we give them extra stress in pronunciation to make them sound louder, longer or higher in tone.



(www.bbc.co.uk)


2d - How do I calculate rotation caused by bounce friction?



Following on from my previous question: I have the ball quite realistically bouncing from surfaces it hits. Now I'd like to make it spin from the friction of the hit.


Showing this is simple enough: I rotate the ball by its angular velocity every tick and apply the same rotation when it's rendered.


When a ball hits a wall, I know that the speed of rotation is affected by...



  • the ball's initial speed when hitting the surface

  • the friction coefficients of the ball and surface (physical constants)

  • the angle of incidence (the angle between the ball's incoming velocity vector and the surface normal).


The angle of incidence is approximated by the dot product of the ball's impact and exit velocity vectors. (1 meaning high spin, -1 meaning no spin, and everything else relatively in between)


Multiplying all of the above together and making sure they were then transformed to the range 0 - 1, and multiplied by max rotation speed, the ball seemed to respond in rotation speed as expected. Except for one thing: It would always rotate clock-wise (because of positive values).





Is this a good method? Can you think of a simpler way?


If this method seems fine, what am I missing? How do I know when the ball should be rotating counter-clockwise?



Answer



Your method is nice, because it's very simple. One thing you might need is dependency on previous spin on the ball, which you do not take into account. The spinning ball represents rotational energy, so a realistic simulation would probably have to conserve it along with the other energies.


However, if the ball is not rotating upon impact, I can't imagine a situation in which it begins rotation against the direction of the incident angle. That is, "clockwise" or "counterclockwise" should be relative to whichever side of the normal the incident angle is.


I think simply multiplying the result by the original x-direction vector (+1 if traveling left to right, -1 if traveling right to left) should do it.


Edit: You can use the cross-product for this. Incident cross normal provides a vector in the Z direction only (if we are on the 2D x-y plane). Look at the z-element: if it is positive, the ball's approach should cause it to spin clockwise. If it is negative, the ball should spin counterclockwise.


prepositions - How to understand "with" in the following sentence?



Not every job will end up with a success.



What is the meaning of "with" here? Why not use other preposition?


Could native speakers please describe the scene of this sentence for me? Thx.




libgdx - Box2d bodies that are really close together, are getting “stuck”


I'm using a tiled tmx map, and I created a class that adds bodies to each tile within a certain layer. This has been working great so far except for when a character or an enemy moves around on the screen, its body gets stuck on an edge between two tiles.


This seems to happen "sometimes" and in certain spots. Jumping makes you unstuck but it's annoying when it happens, and I tried increasing the position iterations, but the problem keeps reoccurring.


Here's what my game looks like:


enter image description here



Answer



I ended up redoing to algorithm for building the map. This seems to be working really really well



enter image description here


I wrote this to build it, this basically makes a body for each tile, if there are tiles next to each other, horizontally, it will group them together and create a single body for those tiles


 private static void buildCollision(Map map, World world){
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("collisionlayer");
BodyDef bDef = new BodyDef();
PolygonShape shape = new PolygonShape();
FixtureDef fDef = new FixtureDef();
fDef.density = 2.5f;
fDef.isSensor = false;
fDef.friction = 0;

fDef.restitution = 0;

bDef.type = BodyType.StaticBody;
Body tileBody = world.createBody(bDef);
tileBody.setUserData("ground");
int cellcounter = 0;
TiledMapTileLayer.Cell cell, nextCell, prevCell;
int firstCellIndexX = 0, firstCellIndexY = 0;

for(int j = 0; j < layer.getHeight(); j++){

for(int i = 0; i < layer.getWidth(); i++){
cell = layer.getCell(i, j);
prevCell = layer.getCell(i-1, j);
nextCell = layer.getCell(i+1, j);

if(cell != null){
cellcounter++;




if(prevCell == null){
firstCellIndexX = i;
firstCellIndexY = j;
}

if(nextCell == null){
float width = layer.getTileWidth() * cellcounter * scaledRatio;
float height = layer.getTileHeight() * scaledRatio;

shape.setAsBox(width/2, height/2, new Vector2((firstCellIndexX * layer.getTileWidth() * scaledRatio) + (width/2), (firstCellIndexY * layer.getTileHeight() * scaledRatio) + (height/2)), 0);

fDef.shape = shape;
tileBody.createFixture(fDef);
cellcounter = 0;
}
}
}
}
shape.dispose();

}

Monday, July 22, 2019

java - Calculating trajectory


I'm just starting with game development and some physics related to that. Basically I want to calculate a trajectory given an initial velocity and as well as an elevation / angle. So I wrote this code in Java (I left out some class related code and such):


int v0 = 30; // m/s
int angle = 60;
double dt = 0.5; // s


double vx = v0 * Math.cos(Math.PI / 180 * angle);
double vy = v0 * Math.sin(Math.PI / 180 * angle);

double posx = 1; // m
double posy = 1; // m
double time = 0; // s

while(posy > 0)
{
posx += vx * dt;

posy += vy * dt;
time += dt;

// change speed in y
vy -= 9.82 * dt; // gravity
}

This seems to work fine. However, is there a better way to do this? Also, is it possible to scale so that 5 meter (in calculation) corresponds to 1 m for the posx and posy variables?


Thanks in advance!



Answer




The equations of motion for a projectile are:


x(t) = x0 + v0 * t + 0.5g * t^2

where x0 and v0 are your initial position and velocity respectively ([posx, posy] and [vx, vy] in your code), g is the gravitational acceleration (9.82m/s^2 in your code) and t is the time, in seconds.


So, instead of looping, you can find your projectile's position at any time t.


When you map from physical space to pixel space, you need a single value that scales meters to pixels. You want 5 meters to be 1 pixel, so simply divide your physical quantities related to position by 5.


architecture - Synchronizing clients with a server and with each other


What is the best way for keeping all clients synchronized with a server and with each other?


Currently, we have two approaches in mind:



  1. When a client sends something to the server, the server immediately sends out messages to all clients, which react immediately.

  2. Introducing some time delay, whereby the server sends out messages to all clients, with the directive, "act upon this at time t.



The second approach seems like it would more likely keep the clients all in better synchronization (since it caters for some degree of lag); but I wonder whether responsiveness would be lost to too high a degree (i.e. the user clicks 'jump' and there is a noticeable gap between pressing the button and actually jumping).


There is also the possibility of having clients calculate their own position (and not wait for servers to say "you have jumped"); but because of the inevitable lag, clients would get very out-of-sync.


Then there's the whole TCP vs. UDP question; because we want it fast, but I'd also hate for the server to say you're in a completely different location than you thought you were.


With all of these competing demands, it all gets very uncertain how we should approach this issue. Which of these approaches (or any other) would be best for keeping clients and server all in sync? Which ones are actually used in the industry?




Sunday, July 21, 2019

algorithm - Simple noise generation


I'm looking to generate noise that looks like this:


enter image description hereenter image description here


(images courtesy of Understanding Perlin Noise)


I'm basically looking for noise with lots of small "ripples". The following is undesirable:


enter image description here


Are there any simple ways to do this? I've been looking at perlin and simplex for a week now and I can't seem to ever get it to work in JavaScript, or when I do, I don't have the correct parameters to generate such images, or it is excruciatingly slow.


I understand that the 3 images I posted could probably be achieved by the same algorithm but at a different scale, but I don't need that algorithm. I just need a very simple algorithm to achieve something like in the first image ideally. Maybe some kind of blurring would do the job, but I can't manage to have results.


I'm developing this in JavaScript but any kind of code or even a simple and detailed explanation will work.



Answer




While the existing answers provide a good way to achieve what the images in the question show, the comments revealed that the goal is to generate an image as shown below:


perlin noise turbulence


This type of noise is quite different from the noise shown in the images of the question, as it forms close isolated blobs.


Turns out that this kind of noise is called turbulence which (according to this CPU Gems article) is implemented as follows (where noise is your Perlin-noise function returning values from -1..1):


double turbulence(double x, double y, double z, double f) {
double t = -.5;
for ( ; f <= W/12 ; f *= 2) // W = Image width in pixels
t += abs(noise(x,y,z,f) / f);
return t;
}


Mashing up this JavaScript Perlin-noise implementation with the turbulence function described above generates noise which is pretty similar to the image above:


turbulence noise


The JavaScript code that was used to generate the image above can be found in this jsFiddle.


quotations - “The happiest people are those who are too busy to notice whether they are or not.” - What? Happy or Busy?


http://www.forbes.com/forbes/welcome/



“The happiest people are those who are too busy to notice whether they are or not.”

William Feather



I didn't get what are they too busy to notice out of the following?



  • That they are happy?

  • That they are busy?



Answer




“The happiest people are those who are too busy to notice whether they are or not.”




So, your first suggestion seems apt - They are too busy to notice their own happiness.


This means that the happiest people are those individuals who really don't worry too much about their happiness. When you start noticing your happiness, you tend to measure it and we humans are never satisfied with what we have.
"I could be happier" - That is what creeps in when you think about how happy you are. When a person who is too busy to think about it doesn't waste time measuring his happiness. After all, Ignorance is bliss.


word usage - "really not" vs "not really"


If someone says "David is not really a leader", it means something like: the speaker believes that David isn't the kind of person you would think of as a without-doubt a real leader; but the speaker isn't necessarily saying that David is definitely a very poor leader.


If someone says "David is really not a leader", it means that the speaker thinks that David is definitely a very poor leader.


What analysis (grammatical, dictionary, etc?) can help me understand how this difference in meaning is created?




copyright - Questions on the legal protection of games and their parts (assets, sounds, title)



we started new pirate game, and I just want to ask some questions about rights. So I am new in game dev, I guess there are a lot of answers, but I guess professionals can advise something for first steps.


So we started some things like:



  1. concept arts

  2. sounds

  3. we are working on the name of the game (just use temp one for now)

  4. we develop some models of ships and characters


I have question what's my step to protect everything I listed above. Do I need to protect everything separately? Do I need to register a game somewhere? Can I use my already made domain and subdomain for the game? Or do I need to register unique one domaine.




Saturday, July 20, 2019

c# - Communicate Unity application via a series of Json


I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.


Here is my JSON structure


{

"id": “id",
"payload": {
“image”: "Image Url”
"text":"text message"
"option" : {
"option1":"1" ,
"option2": "2"
}
}


}


Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.


I have used this code.Iam getting the output


using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()

{
Data data = new Data();
data.id = 1;
data.payload = new Payload() { text = "wwwwwww", image = "hello" };
//json = JsonMapper.ToJson(data) ;
string json = JsonUtility.ToJson(data);
P (json);
// P(json + "\t\n");

}


// Use this for initialization
void P(string aText)
{
print (aText +"\n");
}

}


  [System.Serializable]
public class Payload

{
public string text;
public string image;
}

[System.Serializable]
public class Data
{
public int id;
public Payload payload;

}

The output is getting displayed in a single line


{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}


But I need the output to be printed as the Json format.I tried giving space.


Can anybody please help me out?



Answer



https://docs.unity3d.com/Manual/JSONSerialization.html
The documentation has very detailed explaination. In your case the classes/structures (that store data ) should look like:


[Serializable]

public class Payload
{
public string imageUrl;
public string text;
}

[Serializable]
public class Data
{
public int id;

public Payload payload;
}

Mark them with Serializable attribute so that they can be serialized.
To serialize it , you do:


Data data = new Data();
data.id = ;
data.payload = new Payload() { imageUrl = , text = };

string json = JsonUtility.ToJson(data);


And to convert the json string back into data you do:


var data = JsonUtility.FromJson(json);

That's it, hope this helps.




Edit 01: Pretty format JSON
(in the same documentation as above )



Controlling the output of ToJson()



ToJson supports pretty-printing the JSON output. It is off by default but you can turn it on by passing true as the second parameter.



So i guess all you need to do is just :


string json = JsonUtility.ToJson(data,true);

Honestly, I havent tried it yet but I do believe in what the documentation says :D




Edit02 :


[Serializable]
public class Option

{
public int option01;
public int option02;
}
[Serializable]
public class Payload
{
public string imageUrl;
public string text;
}


[Serializable]
public class Data
{
public int id;
public Payload payload;
public Option option;
}

Data data = new Data();

data.id = ;
data.payload = new Payload() { imageUrl = , text = };
data.option= new Option() { option01 = 1, option02 = 2 };

string json = JsonUtility.ToJson(data,true);

modal verbs - Meaning of "you'd of thought"


I am reading The great Gatsby and there is one part that says:



I had a woman up here last week to look at my feet, and when she gave me the bill you'd of thought she had my appendicitis out.



I would like to know what does you'd of thought mean and also if the of is omitted the sentence would have the same meaning?



Answer



The pronunciation of the preposition of and the auxiliary verb have are identical in casual speech. We say them as: /əv/.



Basically, "you'd of thought" is a way to try and represent the sound of "you would have thought" in normal speech.


Hope this is helpful!


participle phrases - During the tour, you will hear interesting stories about the city, learning (?) about its establishment


I wrote a sentence that was considered awkward by fellow translators, on a couple of counts. I'm singling out one particular word they found awkward:



During the tour, you will hear interesting stories about the city, learning about its establishment and history.



Does this "learning" look awkward here?


Would a native speaker use the finite-form "learn" instead? I understand that that would involve adding "and", I just wonder whether the -ing form or the finite form is more felicitous here.





(Another question concerning the same sentence)



Answer



We can use the participle clause as you do there to express an incidental or tangential fact.



We will visit the ruins on our tour, fording the stream to reach the dig site.



The problem with your sentence is not grammatical, but semantic, since learning is not an incidental but a direct outcome of hearing stories.


P.S. The participle smooths a somewhat jarring non-sequitur by marking the added fact as tangential/incidental to the finite clause. Consider the statement with a second (non-sequitur) finite clause:




We will visit the ruins on our tour and ford the stream to reach the dig site.



In the OP, a second finite clause would have been better than the participle learning:


During the tour, you will hear interesting stories about the city and learn about its establishment and history.


because the second finite clause follows directly from the first; it is not tangential to it.


lwjgl - Packaging a Java game for Linux


I'm just about finished developing a small Java/Lwjgl-based game. For Windows users, I intend to use Launch4J to package the game into a nice .exe. For Mac users, I'll be using JarBundler to produce a nice .app.


What do I do for Linux users? So far I've been distributing beta versions as a .jar file, a lib folder and a shell script for invoking the jar with the right virtual machine parameters. But this is less than pretty. Is there a cross-distro way of providing a single clear way to start the game?




Friday, July 19, 2019

java - fast java2d translucency


I'm trying to draw a bunch of translucent circles on a Swing JComponent. This isn't exactly fast, and I was wondering if there is a way to speed it up. My custom JComponent has the following paintComponent method:


public void paintComponent(Graphics g) {
Rectangle view = g.getClipBounds();


VolatileImage image = createVolatileImage(view.width, view.height);
Graphics2D buffer = image.createGraphics();
// translate to camera location
buffer.translate(-cx, -cy);
// renderables contains all currently visible objects
for(Renderable r : renderables) {
r.paint(buffer);
}
g.drawImage(image.getSnapshot(), view.x, view.y, this);

}

The paint method of my circles is as follows:


public void paint(Graphics2D graphics) {
graphics.setPaint(paint);
graphics.fillOval(x, y, radius, radius);
}

The paint is just an rgba color with a < 255:


Color(int r, int g, int b, int a)


It works fast enough for opaque objects, but is there a simple way to speed this up for translucent ones?



Answer



The immediate potential performance problems I see in your code are:



  1. You are recreating the volatile image in every paintComponent

  2. Calling image.getSnapshot() to convert the VolatileImage to BufferedImage.


There is a good example in the beginning of VolatileImage documentation on how to deal with both of the problems.


In the comments you say that 2. is required so that you can later use BufferedImageOp to filter the rendered image. I think this is a mistake, because as far as I know, BufferedImageOp processes each individual pixel of the image on CPU. This operation alone is likely much slower than any problems regarding image creation or conversion.



I recommend you to take a look at AlphaComposite and the related tutorial. Alternatively depending on what exactly you want to achieve, you could just fill another semi-transparent rectangle on top of everything. With a TexturePaint you can probably create the noise filter you are looking for.


In addition instead of using VolatileImages, you could try GraphicsConfiguration.createCompatibleImage to create accelerated BufferedImages. Benchmark if this has the same performance as VolatileImage. If it does, it will be easier to manage than VolatileImage.


grammar - Is “far from perfect” grammatical?


Is “far from perfect” grammatical?


Here’s my analysis:




  1. It’s ungrammatical because the object of preposition from must be a noun, not an adjective(perfect).

  2. It’s grammatical because perfect can be a noun.

  3. It’s grammatical because perfect is the shortened version of the noun phrase “perfect state” or “being perfect”.

  4. It’s grammatical because “far from” is an adverbial phrase.


I think no. 4 is most likely correct. If it’s the case, what does it modify: the verb “is” or the adjective “perfect”?




relative pronouns - "Those who" vs "Them who"




I pity those who lost their money in gambling.


I pity them who lost their money on gambling.



I know the first one is correct, but I think there is nothing wrong grammatically with the second sentence. Am I wrong somewhere?




phrase usage - What do they mean with "Hi, how are you doing"?


When I was in New York the workers at the counter (in a shop) always said




Hi, how are you doing?



I was, and still am very confused if they just mean "hello", or actually want to know how I feel.


Could someone please tell me if this is just an empty phrase or if the speaker is genuinely interested.



Answer



It's just a hello, they don't actually care how you are doing. Some appropriate response would be to say



  • Hello

  • How are you (without actually answering)

  • Fine, and yourself? (doesn't matter if you are doing fine or not)



auxiliary verbs - Should I add s in questions that start with Could?



I'd like to ask a question like this, but I am not sure whether I should add s at the end of the verb


Could you tell me how long it usually takes to ... ?


or


Could you tell me how long does it usually take to ... ?




geometry - Algorithm for creating adjacent triangles


I have a system where you can click once to place a node in a scene. When you place 3 nodes, it forms a triangle. When you place any future nodes, it creates a new triangle by joining that node to the 2 nearest existing nodes.


This works fine most of the time but is flawed when used near triangles with very acute angles, because one of the 2 nearest nodes is often not one that should be used.



For example, see the image below. The magenta triangle is the first one placed. If I then click at the position marked X, what I get is a new triangle where the blue overlay is. What I want is a new triangle where the green overlay is. (ie. symmetrical to the magenta one, in this example. Clarification: The green and magenta triangles don't overlap - the green one extends under the blue one to the left-most node)


Example of actual and desired behaviour


How can I determine which 2 existing vertices to use when creating new triangles so that triangles are not superimposed like this?


EDIT: Searching for the nearest edge gives better results, but not perfect ones. Consider this situation:


enter image description here


The 'nearest edge' test is ambiguous, and can return AB or AC (as the nearest point to X for both is at A). The desired result would be AC, to form the ACX triangle with no edges overlapping. How could I ensure this result? (I'd rather not have to perform individual edge overlap tests as a tie-breaker if possible as I'm concerned that the nearest edge test won't necessarily spot the 2 are exactly equidistant, given floating point precision issues.)




opengl - Voxel engine artifacts


There are white little dots between blocks at random places, mainly at very near blocks. They disappear when I move the mouse and change the view direction.


I use Vertex Arrays with glVertexAttributePointer to send the data directly to the shader. The shader only adds some fake light based on the face direction and draws the pixels.


What could be the reason for the small white artifacts?


Chunk render code:


public void renderChunk() {
glPushMatrix();


glTranslatef(pos.x*world.chunkSize.x, 0.0f, pos.z*world.chunkSize.z);

glBindBuffer(GL_ARRAY_BUFFER, vao_id);

glVertexAttribPointer(world.game.positionAtt, 3, GL_FLOAT, false, 32, 0);
glVertexAttribPointer(world.game.normalAtt, 3, GL_FLOAT, false, 32, 12);
glVertexAttribPointer(world.game.texCoordAtt, 2, GL_FLOAT, false, 32, 24);

glDrawArrays(GL_TRIANGLES, 0, arraySize / 8);


glBindBuffer(GL_ARRAY_BUFFER, 0);

glPopMatrix();
}

Vertex Shader:


attribute vec3 in_position;
attribute vec3 in_normal;
attribute vec3 in_texcoord;

varying vec2 texture_coordinate;
varying vec3 normal;

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(in_position, 1.0);
normal = in_normal;
texture_coordinate = in_texcoord;
}


Fragment Shader:


varying vec2 texture_coordinate;
varying vec3 normal;
uniform sampler2D texture;

void main()
{
float add;

if (normal.x == 1.0 || normal.z == 1.0) {

add = 0.65;
} else if (normal.y != 1.0) {
add = 0.8;
} else {
add = 1.0;
}
gl_FragColor = texture2D(texture, texture_coordinate) * add;
}

Voxel Engine Artifacts (Dots)



Enlarge the image by click it to notice the artifacts.



Answer



I had the same problem with a recent game I'm working on. I guess you are using one big texture with all the block textures in it (like Minecraft does it)?


If so these white pixels appear because of rounding errors in the shader that lead to "empty" texture spots. This occurs even if you do not use texture interpolation (which is the case with your game obviously).


You can circumvent the problem by modifying the texture coordinates to add a little margin. This way the rounding error won't lead to a lookup outside the texture. This may not be the best solution but when it comes to float values you always have to take care of possible rounding problems.


Another way to fix that would be to use one of the more recent GLSL versions that offer a integer based texture lookup method.


Non-usage of Sequence of tenses



He gave me his room number just in case I change my mind.



Why doesn't the rule of sequence tenses use in this sentence?


PS At the same time, why is it written as "room number" instead of "room's number"/"number of his room"?



Answer



There is a mix of tenses because, evidently, the first person is speaking in the present but the room number was received by them in the past. In other words, the person is already in possession of the room number, and they may yet change their mind.


If the first person was telling a story that occurred entirely in the past, then they would put the entire sentence in the past tense:




He gave me his room number just in case I changed my mind.



This would be appropriate if there was no longer any opportunity for the first person to change their mind.


"Room number" is idiomatic, just like "telephone number", as opposed to "my telephone's number". It is the number of the room.


Are DirectX coordinates spaced out in meters?


Are the DirectX coordinates spaced out in meters? I am just wondering, so I can add some realism to my game.




Thursday, July 18, 2019

Is between the correct word when there are more than two items, for example 'a balance between a, b, and c'?


I know we can say, for example, "a balance between a and b".

Is it valid to say "a balance between a, b and c"?


Because I'm not sure whether "between" can be used for more than two items.
If not, what should be a proper word to use?



Answer



In your example, it's sooner a matter of collocations (set phrases/word combinations) with the word "balance" as in "the balance of animals and plants in the environment, the balance of advantage/forces/power".


There's no usage of the preposition "among" after the noun "balance", if that is what you mean. So, "the balance between a, b and c" is correct.


To see the difference between "between" and "among", you've already gotten the link, which is in the comment to your question.


comparative degree - one of the more fascinating


Václav Havel was one of the more fascinating politicians of the last century.



I would like to ask whether this sentence is correct. I would await the usage of superlative: Václav Havel was one of the most fascinating




gui - Interfaces 101: Making it Pretty



I've made a few games which I've actually released into the wild. There's one particular issue I run into over and over, and that's the issue of the interface/theme of the game.


How can you make non-arbitrary, consistent decisions about the look-and-feel and interface of your game?


For example, in version one of my Silverlight chemistry-based game, I made a (bad?) decision to go witha natural, landscape-style look-and-feel, which resulted in this UI:


Valence 0.1, replete with grass, rocks, and sky.


Then in a later iteration, I got smarter and went with a more "machiney," grungy look-and-feel, which resulted in this (final UI):


Valence final version looks more machine-like and grungy


I will definitely say that my taste in UI improved through iteration. But it was a result of a lot of initially arbitrary decisions followed by a lot of tweaking.


Is there a better way to figure out how to theme your game?




To give a parallel in writing, when you're writing a fantasy/sci-fi novel, there are a lot of elements you need to describe. While you can arbitrarily invent objects/creatures/places/etc., you get a much more consistent world when you sit down for a few minutes and design the area, region, planet, or universe. Everything then fits together nicely, and you can ask yourself "how would this work in this universe?



Edit: It seems like I didn't explain this well. Let me simplify the question in the extreme: when I need to lay out a title screen (with background, fonts, skinned buttons) how do I decide how they should look? Green or blue? Grunge or not? Rounded or flat? Serif or sans-serif?


Take that question and explode it into your game as a whole. How do you figure out how things should look? What process do you use to make them consistent and non-arbitrary?


Look at the screenshots again. I could have stuck to grass/sky/rocks, but metal seemed more fitting to the idea of chemical reactions and atoms.



Answer



You seem to have conflicting styles.


Have a look at these UI's from Peggle, Ultima Underworld, Diablo 3, Starcraft 2, and Gran Turismo 5.


Notice how each UI is consistent within its theme.


Peggle


Peggle is pin-ball like in all its UI elements. Everything's a meter, a lever, a nozzle, a springboard.


Ultima underworld



Ultima Underworld has UI elements are iron/steel, potions, backpacks, maps. Adventure Time.


Diablo III


Similar to Ultima underworld (in fact appears to be based on UW)


Starcraft 2


Futuristic, sleek, simple, minimal (protoss)


Gran Turismo 5


Car interior


So you see, your first design is completely inconsistent and unthemed. What an open field have to do with your game? Same goes for the metal background. Try a lab bench for the game board, and a chem lab background, with flasks and vials and rubber gloves and petri dishes.


Dr Mario


Dr. Mario is very basically medical, bacteria, virus, medicine themed



Further the UI should have similarly-styled graphics to the game play elements. The chemical symbol balls are round and gently graded solid colors. The backgrounds/game board you chose have art styles that are completely dissimilar to the gameplay elements. The field is a vivid photograph. The metal is very detailed, while the chemical balls are smooth and relatively undetailed.


graphics programming - Why are normal maps predominantly blue?


Why normal maps are predominantly blue instead of a random color?


I guess normal vectors of a 3D object can point in every direction, like:


(1.0, 0.1, 0.5), (0.1, -0.5, 0.3), (-0.51, 0.46, -1.0) ... 

enter image description here



Answer



There are two types of normal maps commonly used in game development. The way you are thinking they should work is the way one type works (model-space normal maps), but most games use another type (tangent-space normal maps) which is why you associate mostly-blue textures with normal maps.


Model-space normal map example



With model-space normal maps, each channel encodes the precise value of the normal using the same coordinate system as the vertices of the model it's used with. This means different parts of the normal map will have different hues, but pixels near each other will usually have similar colors. An example of a model-space normal map appears above (source).


Tangent-space normal maps are usually light blue. This type of map defines normals in a coordinate space unique to each pixel's position on the surface of the mesh. It uses the (interpolated) vertex normal as the Z axis, and two other orthogonal vectors, called the tangent and bitangent, as the X and Y axes. Essentially, you can think of the normals in the map as an "offset" from the normal for that pixel calculated by interpolating the vertex normals. The tangent and bitangent vectors are also interpolated from vertex data, and determine which direction on the mesh corresponds to "up" and "left" in the normal map. The image provided in the question provides an excellent example of what a typical tangent-space normal map looks like, so I won't provide another example here.


The components of a normal normally (no pun intended) range from [-1, 1]. But components of a color in an image range from [0, 1] (or [0, 255] but usually they're normalized to [0, 1]). So normals are scaled and offset such that the normal (0, 0, 1) becomes the color (0.5, 0.5, 1). This is the light blue color you see in normal maps, and it indicates no deviation from the interpolated vertex normal when using tangent-space normals.


The reason tangent-space normals are preferred over model-space normals is due to the fact that they are easier to create, and can be used for multiple meshes. Additionally, if used with an animated mesh, tangent-space normals are always used, because the normals are constantly changing.


word usage - Is "further" really used as synonym of "farther"?


The OALD, for the meaning of further says:



(comparative of far) (especially BrE) at or to a greater distance SYN farther




Is further really used as synonym of farther?
As far as I recall, there is a slightly different meaning between those words. I don't recall that exactly, but I think I was taught that further is used figuratively, such as in "I cannot go any further into this discussion."



Answer



Here are a few relevant pronouncements culled from dailywritingtips.com...



The OED says
In standard English the form farther is usually preferred where the word is intended to be the comparative of far, while further is used where the notion of far is altogether absent.
It concedes, however, that “there is a large intermediate class of instances in which the choice between the two forms is arbitrary.”


According to the Online Etymology Dictionary
There is no historical basis for the notion that farther is of physical distance and further of degree or quality.



In 1926 H.W. Fowler wrote in A Dictionary of Modern English Usage
The fact is surely that hardly anyone uses the two words for different occasions; most people prefer one or the other for all purposes, and the preference of the majority is for further.





As these NGrams for advanced further/farther and further/farther advanced show, there's no significant preference based on word position, or UK/US usage. What stands out is further is always more common.


Thus, even if some people (i.e. Grammar Girl) do distinguish either the precise meanings, or the contexts in which they use each form, this is effectively irrelevant, since most of us don't. It's just pedantry.




But there are contexts where farther is never used. In "fixed expressions" such as further education (BrE for AmE continuing education), and as the verb to further (to develop or make progress in something).


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