Note that there are some explanatory texts on larger screens.

plurals
  1. POGLU NURBS rendered wrongly
    primarykey
    data
    text
    <p>EDIT: This is a library bug. I <a href="http://www.haskell.org/pipermail/hopengl/2011-October/001055.html" rel="nofollow noreferrer">reported</a> it to the HOpenGL mail list.</p> <p>I use 9-point rectangular method to represent a circle/ellipse as a NURBS.</p> <p>The points are <code>p1, p2, ..., p9</code>, <code>p9 = p1</code>. They lay as shown:</p> <pre><code>y2 | p2 p3 p4 y1 | p1 p5 y0 | p8 p7 p6 ------------- | x0 x1 x2 x1 = (x0 + x2) / 2 y1 = (y0 + y2) / 2 </code></pre> <p>I.e. <code>p1 = (x0, y1), p2 = (x0, y2)</code> and so on.</p> <p>And weights are:</p> <ul> <li><code>1</code> for middle points (<code>p1,p3,p5,p7</code>)</li> <li><code>sqrt(0.5)</code> for corner points (<code>p2,p4,p6,p8</code>)</li> </ul> <p>I applied weights as homogeneous coordinates, using two ways:</p> <ul> <li>right - <code>(x,y)</code> with weight <code>w</code> becomes <code>Vertex4 (w*x) (w*y) 0 w</code></li> <li>wrong - it becomes <code>Vertex4 x y 0 w</code></li> </ul> <p>The results (right first, wrong second, sorry if they are too big): <img src="https://i.stack.imgur.com/waoRm.png" alt="first"> <img src="https://i.stack.imgur.com/p2mOb.png" alt="second"></p> <p>You see, both are not proper circles (though the second looks nice) and I can't understand why.</p> <p>Here follows the code, based on <code>Lines.hs</code> from GLUT examples:</p> <pre><code>import System.Exit ( exitWith, ExitCode(ExitSuccess) ) import Graphics.UI.GLUT import Foreign.Marshal.Array import Graphics.Rendering.OpenGL.GLU.NURBS myInit :: IO () myInit = do clearColor $= Color4 0 0 0 0 display :: DisplayCallback display = do clear [ ColorBuffer, DepthBuffer ] color (Color3 1.0 1.0 1.0 :: Color3 GLfloat) withNURBSObj () $ \nurbsObj -&gt; do nurbsBeginEndCurve nurbsObj $ withArrayLen knots $ \nKnots knots -&gt; withArray controls $ \controls -&gt; do nurbsCurve nurbsObj (fromIntegral nKnots) knots stride controls order flush where order = 3 stride = 4 -- number of floats in Vertex controls = zipWith mkControl points weights mkControl (x, y) w = Vertex4 (x*w) (y*w) 0 w -- mkControl (x, y) w = Vertex4 x y 0 w knots = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] weights = let a = sqrt 0.5 in [1, a, 1, a, 1, a, 1, a, 1] points = [ (x0, y1), (x0, y2), (x1, y2), (x2, y2), (x2, y1), (x2, y0), (x1, y0), (x0, y0), (x0, y1) ] y1 = (y0 + y2) / 2 x1 = (x0 + x2) / 2 (x0, x2) = (50, 450) (y0, y2) = (x0, x2) reshape :: ReshapeCallback reshape size@(Size w h) = do viewport $= (Position 0 0, size) matrixMode $= Projection loadIdentity ortho2D 0 (fromIntegral w) 0 (fromIntegral h) -- the following line is not in the original example, but it's good style... matrixMode $= Modelview 0 keyboard :: KeyboardMouseCallback keyboard (Char '\27') Down _ _ = exitWith ExitSuccess keyboard _ _ _ _ = return () -- Request double buffer display mode. -- Register mouse input callback functions main :: IO () main = do (progName, _args) &lt;- getArgsAndInitialize initialDisplayMode $= [ SingleBuffered, RGBMode ] initialWindowSize $= Size 500 500 initialWindowPosition $= Position 100 100 createWindow "Test" myInit displayCallback $= display reshapeCallback $= Just reshape keyboardMouseCallback $= Just keyboard mainLoop </code></pre> <p>EDIT: I rechecked coefficients several times, and before rectangular representation I used 7-point triangle method, and there were very similar distortions. So it shall not be a problem with concrete representation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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