Author Topic: Constrain  (Read 2975 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Constrain
« on: October 04, 2011, 12:23:11 PM »
Deleted
« Last Edit: April 11, 2015, 09:52:33 AM by Peter »

Charles Pegge

  • Guest
Re: Constrain
« Reply #1 on: October 05, 2011, 01:36:22 AM »

Hi Peter,

We need your latest window.h for bmpw() and bmph()

Charles

Charles Pegge

  • Guest
Re: Constrain
« Reply #2 on: October 05, 2011, 04:09:11 AM »
Hi Peter,

I've been working on the idea of a constraining box and point transforms

Code: OxygenBasic
  1.  
  2.  
  3. indexbase 0
  4. include "window.h"
  5.  
  6. SetWindow "Spinning squares",800,600,w_2
  7. SetFont 12,24,100,"courier"
  8.  
  9.    Long seed=0x12345678
  10.  
  11.   '------------------------
  12.  Function RndF() as Single
  13.   '========================
  14.  '
  15.  Static As Single f, d=1/0x7fffffff
  16.   mov eax,seed
  17.   rol eax,7
  18.   imul eax,eax,13
  19.   mov seed,eax
  20.   push eax
  21.   fild dWord [esp]
  22.   add esp,4
  23.   fmul dWord d
  24.   fstp dWord f
  25.   Function=f
  26.   End Function
  27.  
  28.  
  29.   'TYPES
  30.  '=====
  31.  
  32.   type boxF        single xb,yb,zb, xt,yt,zt
  33.   type pointF      single x,y,z, sys c
  34.   type projectionF single xa,ya,za, xs,ys,zs, xo,yo,zo
  35.  
  36.  
  37.   function LimitWithinBox(pointF*p, boxF*b)
  38.   '========================================
  39.  if p.x<b.xb then p.x=b.xb
  40.   if p.y<b.xb then p.y=b.yb
  41.   if p.z<b.xt then p.z=b.zb
  42.   if p.x>b.xt then p.x=b.xt
  43.   if p.y>b.xt then p.y=b.yt
  44.   if p.z>b.xt then p.z=b.zt
  45.   end function
  46.  
  47.  
  48.   sub projectPoint(pointF*p,projectionF*pr)
  49.   '========================================
  50.  single r,a
  51.   r=hypot(p.x,p.y)
  52.   a=atan(p.y,p.x)+pr.za
  53.   pixel r*cos(a)*pr.xs+pr.xo, r*sin(a)*pr.ys+pr.yo,p.c
  54.   end sub
  55.  
  56.  
  57.   single      pi2 = pi()*2
  58.  
  59.  
  60.   sub RotaClamp(single*a)
  61.   '======================
  62.  if a < pi2 then
  63.     a+=pi2
  64.   elseif a > pi2 then
  65.     a-=pi2
  66.   end if
  67.   end sub
  68.  
  69.  
  70.   'MAIN
  71.  '====
  72.  
  73.   boxF        b1
  74.   pointF      p1
  75.   projectionF pr1,pr2,pr3
  76.  
  77.   'BOX DATA
  78.  b1<= -.5, -.5, -.5, .5, .5, .5
  79.  
  80.   'PROJECTION DATA
  81.  pr1<= 0,0,.2,  200,200,200,  400,250,0
  82.   pr2<= 0,0,.3,  150,150,150,  400,300,0
  83.   pr3<= 0,0,.4,  100,100,100,  600,200,0
  84.   '
  85.  
  86. While WinExit=0
  87.  
  88.   cls 0x551111
  89.   pr1.za+=.0025
  90.   pr2.za+=.005
  91.   pr3.za-=.007
  92.   RotaClamp pr1.za 'clamp angle range
  93.  RotaClamp pr2.za 'clamp angle range
  94.  '
  95.  seed=0x12345678 'reset random seed
  96.  for i=1 to 4000
  97.     p1<=rndf(),rndf(),rndf(),0xaaaaaa
  98.     ProjectPoint p1,pr1
  99.     ProjectPoint p1,pr2
  100.     LimitWithinBox p1,b1
  101.     ProjectPoint p1,pr3
  102.   next
  103.  
  104.   DoEvents
  105.   SwapBuffers
  106.   FrameRate 60
  107.   'pause
  108. Wend
  109. WinEnd
  110.  

Charles

Charles Pegge

  • Guest
Re: Constrain
« Reply #3 on: October 05, 2011, 07:31:46 AM »

Thanks Peter.

Simple types like that are needed everywhere in geometry so why not make them as easy as creating variables. It has taken me thirty years to get this far, but I'm a slow learner :)

How do you make a bitmap spin?

This article looks promising:

http://www.codeguru.com/cpp/g-m/gdi/article.php/c3693

Charles