raytracing - obfuscated C++ Translation: float&, two for loops -


i reading hacker news , this article came up. contains raytracer code written on of business card. decided academic challenge translate c++ python, there's few concepts i'm stuck on.

first, function comes up: i t(v o,v d,f& t,v& n){...} translated int tracer(vector o, vector d, float& t, vector& n){...} float& mean? know in other places & used == case here? can in c++?

second, noticed these 3 lines:

for(i k=19;k--;)  //for each columns of objects for(i j=9;j--;)   //for each line on columns if(g[j]&1<<k){ 

i know << bit shift, , assume & ==. loops 1 loop in other?

finally, line: v p(13,13,13); not quite sure does. create class labeled p extends v (vector) defaults of 13,13,13?

these dumb questions, want see if can understand , searching didn't come anything. thank in advance!

what float& mean?

here, & means "reference", argument passed reference.

i know in other places & used == case here?

& means various things in various contexts, never means ==. in case, it's not operator either; it's part of type specification, meaning it's reference type.

i know << bit shift, , assume & ==

no, it's bitwise and operator. result has bits set bit set in both operands. here, 1<<k 1 operand, result kth bit of g[j]; tests whether bit set.

are loops 1 loop in other?

yes. if don't use braces around for-loop's body, body single statement. in case, body of first loop second loop. make clear, recommend indenting body of loop, , using braces whether or not strictly necessary. of course, don't write (deliberately) obfuscated code.

finally, line: v p(13,13,13);

v class constructor taking 3 arguments. declares variable called p, of type v, initialised using constructor; i.e. 3 co-ordinates initialised 13.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -