Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You haven't given the types for the other variables - in particular, what are the types of <code>camera.fov_x</code> and <code>camera.fov_y</code>? If they're both integers, then the lines initializing <code>angx</code> and <code>angy</code> will be evaluated using integer arithmetic.</p> <p>This can be fixed by casting one of the operands:</p> <pre><code>double angy = ((double) camera.fov_y / h) * iy; </code></pre> <p>The <code>fovy</code> and <code>fovx</code> variables are already doubles though, this isn't the problem.</p> <p>Could you give a complete example of this, which we can compile and test ourselves?</p> <p>EDIT: Koistya Navin's edit is overkill. You only need one operand of an expression to be a double for the whole thing to be computed using double arithmetic. (It needs to be the right expression though - if you do <code>(a/b) * c</code> and cast <code>c</code> a double, the multiplication will be done with double arithmetic but a/b might still be done as integers.)</p> <p>Here's the listing changed appropriately to make sure double arithmetic is used everywhere it should be:</p> <pre><code>// Changed loops to declare the variable, for stylistic purposes for (int iy = 0; iy &lt; h; iy++) { // Changed here - cast camera.fov_y double angy = ((double) camera.fov_y / h) * iy; for (int ix = 0; ix &lt; w; ix++) { // Changed here - cast camera.fov_x double angx = ((double) camera.fov_x / w) * ix; //output[ix,iy].r = (int)Math.Round(255 * (angy / camera.fov_y); //output[ix,iy].b = (int)Math.Round(255 * (angy / camera.fov_y); double tr = (angx / camera.fov_x) * 255D; double tb = (angy / camera.fov_y) * 255D; Console.Write("({0},{1})", Math.Round(tr), Math.Round(tb)); output.SetPixel(ix, iy, Color.FromArgb(Convert.ToInt32(tr), 0, Convert.ToInt32(tb)) ); Console.Write("."); } Console.WriteLine(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload