Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 28 Feb 2011
Offline Last Active Today, 02:49 AM

Posts I've Made

In Topic: Implementation of Analytical Lighting

Yesterday, 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?




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.

In Topic: C# static interface or lack thereof

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

In Topic: Verify answers to these big o notation questions

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.

In Topic: Byte and double byte numerals

15 December 2014 - 08:56 AM

Such suffixes are not needed for byte-sized integers, hence they do not exist. Probably the best way to document that your literal is supposed to be a byte is to write it in hexadecimal with exactly two digits, e.g. 0xFA, 0x0D, etc.. (edit) read up on the "usual arithmetic conversions" in C if you don't understand why you get 0xFF00 in your snippet above.

In Topic: Minimalist Programming Environment

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.