Jump to content

  • Log In with Google      Sign In   
  • Create Account

Bacterius

Member Since 28 Feb 2011
Online Last Active Today, 04:20 AM

#5200814 Disk Partition Security for Game Dev

Posted by Bacterius on 30 December 2014 - 09:50 AM

Yep. And for maximum safety that VM shouldn't use the HW virtualization extensions/acceleration, and have its virtual Ethernet connection unplugged (the VM shouldn't be capable of communicating with the real machine)

 

And keep in mind that even *that* isn't 100% watertight, as malware may very well exploit vulnerabilities in the VM's drivers or memory management to pull themselves out of the VM and infect the host, for instance this vulnerability report describing how the VirtualBox 3D graphics driver can be compromised to run arbitrary code on the host system. Admittedly this comes from a driver that taps into the host's 3D acceleration capabilities, but it could potentially happen for any driver, even a simple virtual mouse or keyboard driver. Of course, all that is unlikely to be a threat in practice, as almost all malware isn't VM-aware, and most of those who are just want to shut down so they can't be analyzed (the primary reason malware finds itself in a VM to begin with) so run-of-the-mill malware will be well-contained in a VM with no network connection.




#5200028 Logic question

Posted by Bacterius on 25 December 2014 - 10:40 PM

It seems like bitfields are what you want, but it only seems so, because you need to distinguish order as well, so just recording that a button was clicked is not enough. One easy way to do this is to set A = 0, B = 1, C = 2, keep a "total" variable initialized to zero, and each time you click a button, you multiply the total by 3 before adding the corresponding value to the total. After all buttons are clicked, you add to the total (3^N - 3) / 2 where N is the number of buttons clicked. You can verify collisions are now impossible, and you get the following mapping:

 

A = 0

B = 1

C = 2

AA = 3

AB = 4

AC = 5

BA = 6

BB = 7

BC = 8

CA = 9

CB = 10

CC = 11

AAA = 12

AAB = 13

AAC = 14

ABA = 15

and so on...

 

in particular, BBB = 25 and ABC = 17, AAC = 14 and BBA = 24.

 

This mapping also works for any number of button clicks, i.e. two-button or four-button click combinations will also all have their own unique keys. If you know you will only ever need three-button click combinations, you can just drop the final addition involving N if you want to. This construction also happens to be optimal, producing the smallest possible keys, and also letting you convert the key back to the respective button clicks efficiently, should that be of use to you. Note the keys start from zero, just increment them if you need them to start at one.

 

(perhaps a "purer" mapping would be to add (3^N - 1) / 2 instead, and let 0 be the key corresponding to "no clicks at all" i.e. N = 0, but that's up to you)




#5199928 Implementation of Analytical Lighting

Posted by Bacterius on 24 December 2014 - 10:29 PM

Isn't there a much easier way, now that I think about it? How about a LUT that has that ramp, and I just sample the ramp based on temperature?

 

The issue is what function would I use in order to sample the color based on the temperture chosen?

 

http://en.wikipedia.org/wiki/Planck%27s_law

 

In short, Planck's law describes how much energy per wavelength in the visible spectrum (or outside it for that matter) is emitted by a black body (a nonreflective body in thermodynamic equilibrium with its surroundings, don't fret too much about that, it's a sufficient approximation of reality for computer graphics purposes) at a given temperature, you integrate that power spectrum via a wavelength to RGB (or XYZ) reference table to obtain the corresponding RGB (or XYZ) color, and the color can perhaps be precomputed for each temperature of interest. That spectral conversion part is what the article Spiro linked discusses, so I think the physical basis for the temperature curve was what you were missing.




#5199417 C# static interface or lack thereof

Posted by Bacterius on 21 December 2014 - 10:02 AM

There are at least two solutions immediately available to you, the first one is the use abstract base classes as mentioned above, the other one is to use reflection to work around your problem. But perhaps we can better understand your problem if you give us an example of how the methods you describe would be used. Can you show how you would implement the hypothetical FromBytes() static method of your HeirTree, assuming classes implementing IEdible<T> did have a FromBytes() static method as well?

In any case, interface constructors and interface static methods make very little sense, for reasons that are already explained all over the internet. That is not to say that the underlying concept is meaningless, just that interfaces are not the right way to implement it. In fact, I think attributes would be an excellent place to document and enforce contracts such as (for instance) "should have a constructor that takes a byte array and instantiates the object from it" but unfortunately I don't think C# attributes can perform custom compile-time checks, which defeats the point (if you don't want compile-time checking then you can already do basically anything you want via reflection, but giving up compile-time safety is often far too high a price to pay).


#5199219 Verify answers to these big o notation questions

Posted by Bacterius on 20 December 2014 - 01:39 AM

Your answers are all wrong because you didn't answer the question. The question was "for each of these functions, decide if they are in O(x)", which, unlike your interpretation of it, is actually meaningful, as Alvaro explained above. So your answers should be of the form "yes, because (...)" or "no, because (...)".

Recall that a function f is in O(g) if and only if, for all sufficiently large x, there exists a constant C > 0 such that f(x) <= C g(x). For the first problem you have g(x) = x, and f(x) = 10. Does there exist a positive constant C such that 10 <= C x for all sufficiently large x? What about C = 10? Then the inequality holds for all x >= 1, and so 10 is in O(x). Done. For the next problem, you might try C = 4 (and keep in mind the inequality only has to hold for all sufficiently large x). For the third one, prove that no such C exists which shows that x^2 + x + 1 is NOT in O(x). And so on for all the problems.

EDIT: or you can use shortcuts such as omitting all terms except the fastest growing one or using limits to show that a suitable constant C exists (or doesn't) as long as you are able to justify each step of your work, of course. You don't have to work from the formal definition every time, but your work needs to be rigorous enough.


#5198259 Minimalist Programming Environment

Posted by Bacterius on 15 December 2014 - 01:00 AM

I don't understand the quasi-spiritual arguments going around these days about who has the "purest" development workflow. Some people like Vim, others find it inadequate or inconvenient, other people prefer VS, but some find it slow and bothersome, more others use neither and prefer different tools like CodeBlocks, Sublime Text, QtCreator or Notepad++. It's called life, not everyone works the same way. Sure, it's possible to try and have an objective discussion about the pros and cons of different development environments under various conditions, but we all know how these tend to end.

Also, coding exclusively in vim is hardly "off the beaten path". You're not the first person to do it (as a matter of fact, I have a friend who does just that) and you probably won't be the last either. But I think I know what you meant.


#5198066 How can a non-complete graph be connected in graph theory?

Posted by Bacterius on 13 December 2014 - 09:36 PM

A path can consist of multiple edges. What it means for a graph to be connected is that you can go from any vertex to any other by travelling along some set of edges, not just that they are directly connected with a single edge. So, no, a connected graph and a complete graph are very much not the same.




#5197939 Want to become a Computer Scientist

Posted by Bacterius on 13 December 2014 - 03:18 AM

When do you guys recommend that I learn a new programming language ?
 
Also, thanks for all the answers.


I learnt a single language when I started programming. After a few years of working with it, it began to dawn on me it was the only language I knew. So I expanded to C# and Python, and today I use at least three major programming languages regularly with experience in many others, some general, some scripting, some domain-specific, and even more software technologies (and I still have much to learn). Yet all this only took me about 3 additional years on top of the time spent learning my first language. It's important to realise that once you've gotten well past the beginner stage in your first language of choice, learning more languages is generally much easier. Knowing a programming language can be roughly broken down into four major knowledge bases:

(1) Abstract programming: understanding infinite loops, conditionals and branches, indirection, abstraction, referential transparency, closures, composability, algorithmic complexity, this kind of stuff, as well as a clear mental representation of how these notions generalize and relate to one another;
(2) Syntax and semantics: understanding how the language's collective keywords and constructs map to those abstract concepts, and knowing them well;
(3) Base utilities: being fluent with the development environment provided by the language to perform concrete tasks like renaming a file or communicating over the network, for Python those are the built-in modules, for C# it's undoubtedly the .NET technology stack, for Java it's its expansive standard library, and so on;
(4) External utilities: being familiar with a number of third-party libraries which are not provided by default with the language, the more you have in (4) the more valuable you are as a developer with that particular language;

Note that (1) does not depend on any specific programming language, and while you will need to add information to it over time, in general, say, 60% to 80% of what needs to go in (1) [in terms of how often you will need it] is learnt within the first two years of messing with your first programming language, and the more you have in (1), the easier learning (2) becomes for any language. Then for your second language you bootstrap (2) and (3) by writing the usual introductory programs suitable to that language (such as hello world, guess my number, hangman game, etc..) and after that it's only a matter of using the language regularly and challenging yourself to keep putting more stuff into (2), (3) and (4). Also, interacting with other programmers is a very good way to build up (4).

Also don't forget that it's not all about learning programming languages. Knowing how to develop an effective workflow is important. Experience in many different build systems and toolchains is also a very important aspect of being a programmer. Knowing how and when to use different languages together to benefit from the strengths of each is also important. Having strong debugging and testing methodologies is critical. There's so much more to being a programmer than just typing code.

All this to say that learning another programming language is not, and should not be, a big deal. Most software developers do it fairly often. If you feel you know enough C++ (is that right?) that you can successfully extend that knowledge to another language without needing to go over the basics again, then go ahead. You are pretty young, so I would personally recommend from experience to spend a few more months honing your C++ skills (have you covered lambdas, for example?) but it's ultimately up to you to make your own decisions. Oh, and this should go without saying but just to be clear: you are not expected to know every language - only learn those relevant to your career and your personal interests. Actively learning for the sake of accumulating knowledge is of no use whatsoever unless you intend to use it, and it often turns you into a jack of all trades but master of none, which is not a good thing for a software developer given the high competition and fast pacing of the industry.


#5197512 Creating .so files in linux

Posted by Bacterius on 10 December 2014 - 10:54 PM

Hi Bacterius,
 
Thanks for the reply.
 
Where would you put __attribute__((visibility("default"))) etc? Before the double keyword?


Yes, just before the function's return value in its declaration. See https://gcc.gnu.org/wiki/Visibility


#5197503 Creating .so files in linux

Posted by Bacterius on 10 December 2014 - 10:16 PM

You can actually use the same syntax in GCC I believe, it added extensions to support this. Otherwise, you need to use __attribute__((visibility("default"))) and __attribute__((visibility("hidden"))) to hide symbols.


#5197116 Writing my own pathtracer on mobile device

Posted by Bacterius on 09 December 2014 - 03:09 AM


Salt'n Pepper ? Probably hitting the same object you bounced the ray off again. This can happen due to precision issues. Grant your Trace function a ignoreObject parameter, skip collision check for this and feed hitObject when you recurse.

 

Another quick'n'dirty way to fix it is to "nudge" your hitpoint slightly outside the object (or inside, in the case of refraction) to make sure it doesn't intersect it again. A bit ugly, though, and unreliable with floating-point arithmetic although it tends to work most of the time (I actually read a paper where the authors used fixed point arithmetic to make it reliable).




#5196721 Writing my own pathtracer on mobile device

Posted by Bacterius on 06 December 2014 - 06:53 PM

Fyi. in mathematics sqrt(0) depends on convention - there are multiple definitions - one of the conventions also specifies that 0^2 is undefined, thus also sqrt(0) is undefined


o.O

I have never heard of such a convention. The square root of zero has always been, and always will be zero, and zero squared is most definitely zero. Are you confusing with 0^0?

That said, yes, dividing by zero is always a mistake, and indeed you need some positive z component to drive the camera rays in a particular direction - there are different camera types but the one given by Villem is probably the simplest and easiest (and most common).


#5196607 Writing my own pathtracer on mobile device

Posted by Bacterius on 06 December 2014 - 06:27 AM

So like this?


No, see here if x1 is negative and x2 is positive then your code will return x1, but the correct return value should be x2 as that is the first intersection along the ray. Something like:
if(discriminant > 0){
    float x1 = (-b - (float)Math.sqrt(discriminant) / (2.0f * a));
    float x2 = (-b + (float)Math.sqrt(discriminant) / (2.0f*a));

    if (x1 < 0) return x2;
    if (x2 < 0) return x1;
    return Math.min(x1,x2);
}
You can check this will always return the smallest positive solution, and a negative value (not necessarily -1!) if there is no positive solution. It could probably be optimized, though.
 

So like this?


Yes, but I really meant to remember to make sure they actually are normalized before giving them to your intersect function, since it depends on the direction vector having unit length.


#5196589 Writing my own pathtracer on mobile device

Posted by Bacterius on 06 December 2014 - 04:26 AM

Probably you want to completely exclude results less than zero (i.e. if t1 is less than 0, return t2, and vice versa, and if they are both positive then return the smallest one). That will also handle cases where your ray starts inside the sphere, as well. Otherwise I haven't checked but the equation looks correct, it's just a standard quadratic. Also make sure your direction vectors are normalized.

Also since you seem to be using C# (correct me if I'm wrong) you would do yourself a favour to code proper arithmetic operators for your vector class rather than using .subtract, .add, etc... that'll make your code much easier to read and write.


#5195836 Writing my own pathtracer on mobile device

Posted by Bacterius on 02 December 2014 - 01:46 AM


do i really need a KD-Tree if i only use primitives such as spheres and planes?

 

If you only have a few, no. You can start out with a test scene of 5-6 spheres and won't need any special data structure to store the spheres. Once you get over a few hundred spheres (or triangles) though you quickly begin to realize how important it is for larger scenes!






PARTNERS