Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht Das deutsche QBasic- und FreeBASIC-Forum
Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
 
FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   BenutzergruppenBenutzergruppen  RegistrierenRegistrieren
ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin
Zur Begleitseite des Forums / Chat / Impressum
Aktueller Forenpartner:

4D-Perlin Noise komisch?

 
Neues Thema eröffnen   Neue Antwort erstellen    Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht -> Allgemeine Fragen zu FreeBASIC.
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
Haubitze



Anmeldungsdatum: 14.10.2009
Beiträge: 132

BeitragVerfasst am: 24.12.2012, 13:31    Titel: 4D-Perlin Noise komisch? Antworten mit Zitat

Hallo Leute,

ich hab hier ne perlin noise funktion von 1D-4D geschrieben(is noch unfertig)
nun wolltich wissen ob die 4D variante so richtig ist?
wenn sich da wer auskennt und mir helfen kann waer das sehr nett.

hier ma der code.

Code:

Randomize Timer
#Include Once "fbgfx.bi"
#Include Once "windows.bi"
#Include Once "crt.bi"
#Include Once "crt/math.bi"
#Include Once "crt/limits.bi"
#Include Once "gl\gl.bi"
#Include Once "gl\glu.bi"
#Include Once "gl\glext.bi"
ScreenRes 800,600,32,2,0 Or &h02 Or &h10000 Or &h20000 Or &h40000,60

Dim Shared As Integer ScreenResX,ScreenResY,MidX,MidY,seed
ScreenInfo(ScreenResX,ScreenResY)
MidX=ScreenResX/2
MidY=ScreenResY/2

Using FB
Enum Interpolate_Modes
linear=0
cosine
cubic
hermite
End Enum
'uint32_t KISS() {
'static uint32_t x = 123456789 // <- beliebige seed != 0
'static uint32_t y = 362436000
'static uint32_t z = 521288629
'static uint32_t c = 7654321
'   uint64_t t
'
'   // Linearer Kongruenzgenerator
'   x = 69069 * x + 12345
'
'   // Xorshift
'   y ^= y << 13
'   y ^= y >> 17
'   y ^= y << 5
'
'   // Multiply-with-carry
'   t = 698769069ULL * z + c
'   c = t >> 32
'   z = (uint32_t) t
'
'   return x + y + z
'}

'Function XOR_RAND_UInt(x As UInteger) As UInteger
'  Dim a As UInteger= x
'  a = a Xor (a Shl 13)
'  a = a Xor (a Shr 17)
'  a = a Xor (a Shl 5)
'  return a
'End Function
'Function XOR_RAND_Int(x As Integer) As Integer
'  Dim a As Integer = 314159265*x
'  a = a Xor (a Shl 13)
'  a = a Xor (a Shr 17)
'  a = a Xor (a Shl 5)
'  return a
'End Function
'
'uint32_t xorshift128() {
'  static uint32_t x = 123456789 '<- userseed
'  static uint32_t y = 362436069
'  static uint32_t z = 521288629
'  static uint32_t w = 88675123
'
'  uint32_t t = x ^ (x << 11)
'  x = y y = z z = w
'  w ^= (w >> 19) ^ t ^ (t >> 8)
'
'  return w
'}

sub InitializeGL(screenw As Integer,screenh As Integer)
   '' Start Of User Initialization
   'angle = 0.0f                                            '' Set Starting Angle To Zero

   'BlurTexture = EmptyTexture (screenh,screenw,GL_RGBA)                           '' Create Our Empty Texture
   'DepthTexture = EmptyTexture (screenh,screenw,GL_DEPTH_COMPONENT)
   glViewport (0, 0, screenw, screenh)                                 '' Set Up A Viewport
   glMatrixMode (GL_PROJECTION)                            '' Select The Projection Matrix
   glLoadIdentity ()                                       '' Reset The Projection Matrix
   'gluPerspective (45, screenw/screenh, 1, 200000)                       '' Set Our Perspective
   'gluLookAt(0,1,-1,0,0,0,0,1,0)

   glMatrixMode (GL_MODELVIEW)                             '' Select The Modelview Matrix
   glLoadIdentity ()                                       '' Reset The Modelview Matrix

   glEnable (GL_DEPTH_TEST)                                '' Enable Depth Testing

   dim global_ambient(0 to 3) as single => { _             '' Set Ambient Lighting To Fairly Dark Light (No Color)
   0.0f, 0.0f, 0.0f, 1.0f _
   }
   dim light0pos(0 to 3) as single => { _                  '' Set The Light Position
   0.000000f, 0.000000f, 0.000001f, 1.0f _
   }
   dim light0ambient(0 to 3) as single => { _              '' More Ambient Light
   0.0f, 0.0f, 0.0f, 1.0f _
   }
   dim light0diffuse(0 to 3) as single => { _              '' Set The Diffuse Light A Bit Brighter
   1.3f, 1.3f, 1.3f, 1.0f _
   }
   dim light0specular(0 to 3) as single => { _             '' Fairly Bright Specular Lighting
   0.8f, 0.8f, 0.8f, 1.0f _
   }

   dim lmodel_ambient(0 to 3) as single => { _             '' And More Ambient Light
   0.1f, 0.1f, 0.1f, 1.0f _
   }

   glLightModelfv (GL_LIGHT_MODEL_AMBIENT, @lmodel_ambient(0)) '' Set The Ambient Light Model

   glLightModelfv (GL_LIGHT_MODEL_AMBIENT, @global_ambient(0)) '' Set The Global Ambient Light Model
   glLightfv (GL_LIGHT0, GL_POSITION, @light0pos(0))           '' Set The Lights Position
   glLightfv (GL_LIGHT0, GL_AMBIENT, @light0ambient(0))        '' Set The Ambient Light
   glLightfv (GL_LIGHT0, GL_DIFFUSE, @light0diffuse(0))        '' Set The Diffuse Light
   glLightfv (GL_LIGHT0, GL_SPECULAR, @light0specular(0))      '' Set Up Specular Lighting
   glEnable (GL_LIGHTING)                                      '' Enable Lighting
   glEnable (GL_LIGHT0)                                        '' Enable Light0

   glShadeModel (GL_SMOOTH)                                    '' Select Smooth Shading

   'glCullFace(GL_BACK)                          '' Set Culling Face To Back Face
   'glEnable(GL_CULL_FACE)                       '' Enable Culling
   glPolygonMode(GL_FRONT,GL_FILL)
   glPolygonMode(GL_BACK,GL_LINE)

   glMateriali (GL_FRONT, GL_SHININESS, 128)
   glClearColor (0.0f, 0.0f, 0.0f, 0.5)                        '' Set The Clear Color To Black
   glEnable(GL_DEPTH_TEST)
   glEnable(GL_COLOR_MATERIAL)
   glEnable(GL_NORMALIZE)
end Sub
'' ------------------------------------------------------------------------
sub ViewOrtho ()                              '' Set Up An Ortho View
   glMatrixMode (GL_PROJECTION)              '' Select Projection
   glPushMatrix ()                           '' Push The Matrix
   glLoadIdentity ()                         '' Reset The Matrix
   glOrtho (0, 800, 600, 0, - 1, 1)          '' Select Ortho Mode (640x480)
   glMatrixMode (GL_MODELVIEW)               '' Select Modelview Matrix
   glPushMatrix ()                           '' Push The Matrix
   glLoadIdentity ()                         '' Reset The Matrix
end sub

'' ------------------------------------------------------------------------
sub ViewPerspective ()                        '' Set Up A Perspective View
   glMatrixMode (GL_PROJECTION)              '' Select Projection
   glPopMatrix ()                            '' Pop The Matrix
   glMatrixMode (GL_MODELVIEW)               '' Select Modelview
   glPopMatrix ()
   'gluPerspective (45+(instrument(11).param*45), screenw/screenh, 1, 200000)                       '' Set Our Perspective
   'gluLookAt(0,50,100,0,0,0,0,1,0)
   '' Pop The Matrix
End Sub
Sub SetCamera()
   Dim As Single lookposx,lookposy,lookposz
   glMatrixMode (GL_PROJECTION)              '' Select Projection
   glLoadIdentity()
   gluPerspective (45, ScreenResX/ScreenResY, 0.001, 100)'3.402823e+38)'(45-(instrument(11).param*44), screenw/screenh, 0.1, 3.402823e+38)                       '' Set Our Perspective
   gluLookAt(0,0,-50,0,0,0,0,1,0)
   glMatrixMode (GL_MODELVIEW)               '' Select Modelview
   glLoadIdentity()
End Sub

'' ------------------------------------------------------------------------
'' ------------------------------------------------------------------------
'' ------------------------------------------------------------------------
'' ------------------------------------------------------------------------
'' N->Noise | S->Smoothed | I->Interpolated | P->Perlin
Type Noise
   Private:

   'Public:
   Declare Function Linear_Interpolate(a As Single, b As Single, f As Single) As Single
   Declare Function Cosine_Interpolate(a As Single, b As Single, f As Single) As Single
   Declare Function Cubic_Interpolate(v0 As Single, v1 As Single, v2 As Single, v3 As Single,f As Single) As Single
   Declare Function Hermite_Interpolate(y0 As Single,y1 As Single,y2 As Single,y3 As Single,f As Single,tension As Single=0,bias As Single=0) As Single
   Declare Function N_1D(x As Integer) As Single
   Declare Function N_2D(x As Integer,y As Integer) As Single
   Declare Function N_3D(x As Integer,y As Integer,z As Integer) As Single
   Declare Function N_4D(x As Integer,y As Integer,z As Integer,w As Integer) As Single
   Declare Function S_1D(x As Integer) As Single
   Declare Function S_2D(x As Integer,y As Integer) As Single
   Declare Function S_3D(x As Integer,y As Integer,z As Integer) As Single
   Declare Function S_4D(x As Integer,y As Integer,z As Integer,w As Integer) As Single
   Declare Function I_1D(x As Single) As Single
   Declare Function I_2D(x As Single,y As Single) As Single
   Declare Function I_3D(x As Single,y As Single,z As Single) As Single
   Declare Function I_4D(x As Single,y As Single,z As Single,w As Single) As Single
   Public:
   Declare Function P_1D(x As Single) As Single
   Declare Function P_2D(x As Single,y As Single) As Single
   Declare Function P_3D(x As Single,y As Single,z As Single) As Single
   Declare Function P_4D(x As Single,y As Single,z As Single,w As Single) As Single

   seed As Integer
   min As Single
   max As Single
   octaven As Integer
   persistenz As Single
   frequenz_x As Single
   frequenz_y As Single
   frequenz_z As Single
   frequenz_w As Single
End Type


Function Noise.Linear_Interpolate(a As Single, b As Single, f As Single) As Single
   Return  a*(1-f) + b*f
   'Return a + (1-x) * (b - a)
End Function
Function Noise.Cosine_Interpolate(a As Single, b As Single, f As Single) As Single
   Dim ft As Single = f * 3.1415927
   Dim ff As Single = (1.0 - Cos(ft)) * .5
   Return  a*(1.0-ff) + b*ff
   'Return a + (1.0-f) * (b*f)
End Function
Function Noise.Cubic_Interpolate(v0 As Single, v1 As Single, v2 As Single, v3 As Single,f As Single) As Single
   Dim x2 As Single=f*f
   Dim x3 As Single=f*f*f
   Dim P As Single = (v3 - v2) - (v0 - v1)
   Dim Q As Single = (v0 - v1) - P
   Dim R As Single = v2 - v0
   Dim S As Single = v1
   Return(P*x3+Q*x2+R*f+S)
End Function
Function Noise.Hermite_Interpolate(y0 As Single,y1 As Single,y2 As Single,y3 As Single,f As Single,tension As Single=0,bias As Single=0) As Single
   /'
   Tension: 1 is high, 0 normal, -1 is low
   Bias: 0 is even,
         positive is towards first segment,
         negative towards the other
'/
   Dim As Single m0,m1,mu2,mu3
   Dim As Single a0,a1,a2,a3
   mu2 = f * f
   mu3 = f * f * f
   m0  = (y1-y0)*(1+bias)*(1-tension)/2
   m0 += (y2-y1)*(1-bias)*(1-tension)/2
   m1  = (y2-y1)*(1+bias)*(1-tension)/2
   m1 += (y3-y2)*(1-bias)*(1-tension)/2
   a0 =  2*mu3 - 3*mu2 + 1
   a1 =    mu3 - 2*mu2 + f
   a2 =    mu3 -   mu2
   a3 = -2*mu3 + 3*mu2
   Return(a0*y1+a1*m0+a2*m1+a3*y2)
End Function

Function Noise.N_1D(x As Integer) As Single
   x += seed
   x = (x Shl 13) Xor x
   Return ( 1.0 - (((x * (x * x * 15731 + 789221) + 1376312579) And &h7fffffff)) / 1073741827.0)
End Function
Function Noise.N_2D(x As Integer,y As Integer) As Single
   Dim n As Integer= x+y*53+seed
   n = (n Shl 13) Xor n
   Return ( 1.0 - (((n * (n * n * 15731 + 789221) + 1376312579) And &h7fffffff) / 1073741827.0))
End Function
Function Noise.N_3D(x As Integer,y As Integer,z As Integer) As Single
   Dim n As Integer= x+y*53+z*107+seed
   n = (n Shl 13) Xor n
   Return ( 1.0 - (((n * (n * n * 15731 + 789221) + 1376312579) And &h7fffffff) / 1073741827.0))
End Function
Function Noise.N_4D(x As Integer,y As Integer,z As Integer,w As Integer) As Single
   Dim n As Integer= x+y*53+z*107+w*211+seed
   n = (n Shl 13) Xor n
   Return ( 1.0 - (((n * (n * n * 15731 + 789221) + 1376312579) And &h7fffffff) / 1073741827.0))
End Function
Function Noise.S_1D(x As integer) As Single
   Return    N_1D(x  )/2.0f  +  _
   N_1D(x-1)/4.0f  +  _
   N_1D(x+1)/4.0f
End Function
Function Noise.S_2D(x As Integer,y As Integer) As Single
   Dim As Single corners = (   N_2D(x-1, y-1)+_
   N_2D(x+1, y-1)+_
   N_2D(x-1, y+1)+_
   N_2D(x+1, y+1) ) / 4.0f

   Dim As Single sides   = (   N_2D(x-1, y  )  +_
   N_2D(x+1, y  )  +_
   N_2D(x  , y-1)  +_
   N_2D(x  , y+1) ) /  4.0f

   Dim As Single center  =     N_2D(x  , y  ) / 2.0f
   Return corners + sides + center
End Function
Function Noise.S_3D(x As Integer,y As Integer,z As Integer) As Single
   Dim As Single corners
   Dim As Single sides
   Dim As Single center
   Dim As Single fZm1,fZ,fZp1
   'average of neighbours in z-1
   Corners = ( N_3D( x - 1, y - 1, z - 1 ) + _
   N_3D( x + 1, y - 1, z - 1 ) + _
   N_3D( x - 1, y + 1, z - 1 ) + _
   N_3D( x + 1, y + 1, z - 1 ) ) / 4.0f
   Sides   = ( N_3D( x - 1, y    , z - 1 ) + _
   N_3D( x + 1, y    , z - 1 ) + _
   N_3D( x    , y - 1, z - 1 ) + _
   N_3D( x    , y + 1, z - 1 ) ) / 4.0f
   Center  =   N_3D( x, y, z - 1 ) / 2.0f
   fZm1     = Corners + Sides + Center
   'average of neighbours in z
   Corners = ( N_3D( x - 1, y - 1, z ) + _
   N_3D( x + 1, y - 1, z ) + _
   N_3D( x - 1, y + 1, z ) + _
   N_3D( x + 1, y + 1, z ) ) / 4.0f
   Sides   = ( N_3D( x - 1, y    , z ) + _
   N_3D( x + 1, y    , z ) + _
   N_3D( x    , y - 1, z ) + _
   N_3D( x    , y + 1, z ) ) / 4.0f
   Center  =   N_3D( x, y, z ) / 2.0f
   fZ       = Corners + Sides + Center
   'average of neighbours in z+1
   Corners = ( N_3D( x - 1, y - 1, z + 1 ) + _
   N_3D( x + 1, y - 1, z + 1 ) + _
   N_3D( x - 1, y + 1, z + 1 ) + _
   N_3D( x + 1, y + 1, z + 1 ) ) / 4.0f
   Sides   = ( N_3D( x - 1, y    , z + 1 ) + _
   N_3D( x + 1, y    , z + 1 ) + _
   N_3D( x    , y - 1, z + 1 ) + _
   N_3D( x    , y + 1, z + 1 ) ) / 4.0f
   Center  =   N_3D( x, y, z + 1 ) / 2.0f
   fZp1     = Corners + Sides + Center
   'Return(( fZm1  ) + ( fZ  ) + ( fZp1 ))/3.0
   Return(( fZm1 / 4.0f ) + ( fZ / 2.0f ) + ( fZp1 / 4.0f ))
End Function
Function Noise.S_4D(x As Integer,y As Integer,z As Integer,w As Integer) As Single
   Dim As Single corners
   Dim As Single sides
   Dim As Single center
   Dim As Single fWm1,fW,fWp1
   'average of neighbours in z-1
   Corners = ( N_4D( x - 1, y - 1, z - 1 ,w - 1 ) + _
   N_4D( x + 1, y - 1, z - 1 ,w - 1) + _
   N_4D( x - 1, y + 1, z - 1 ,w - 1) + _
   N_4D( x + 1, y + 1, z - 1 ,w - 1) + _
   N_4D( x - 1, y - 1, z + 1 ,w - 1) + _
   N_4D( x + 1, y - 1, z + 1 ,w - 1) + _
   N_4D( x - 1, y + 1, z + 1 ,w - 1) + _
   N_4D( x + 1, y + 1, z + 1 ,w - 1) ) / 8.0f

   Sides   = ( N_4D( x - 1, y    , z     , w - 1 ) + _
   N_4D( x + 1, y    , z     , w - 1 ) + _
   N_4D( x    , y - 1, z     , w - 1 ) + _
   N_4D( x    , y + 1, z     , w - 1 ) + _
   N_4D( x    , y    , z - 1 , w - 1 ) + _
   N_4D( x    , y    , z + 1 , w - 1 ) ) / 6.0f

   Center  =   N_4D( x    , y    , z     , w - 1 ) / 2.0f
   fWm1     = Corners + Sides + Center
   'average of neighbours in z
   Corners = ( N_4D( x - 1, y - 1, z - 1 , w ) + _
   N_4D( x + 1, y - 1, z - 1 , w ) + _
   N_4D( x - 1, y + 1, z - 1 , w ) + _
   N_4D( x + 1, y + 1, z - 1 , w ) + _
   N_4D( x - 1, y - 1, z + 1 , w ) + _
   N_4D( x + 1, y - 1, z + 1 , w ) + _
   N_4D( x - 1, y + 1, z + 1 , w ) + _
   N_4D( x + 1, y + 1, z + 1 , w ) ) / 8.0f

   Sides   = ( N_4D( x - 1, y    , z     , w ) + _
   N_4D( x + 1, y    , z     , w ) + _
   N_4D( x    , y - 1, z     , w ) + _
   N_4D( x    , y + 1, z     , w ) + _
   N_4D( x    , y    , z - 1 , w ) + _
   N_4D( x    , y    , z + 1 , w) ) / 6.0f

   Center  =   N_4D( x    , y    , z     , w ) / 2.0f
   fW       = Corners + Sides + Center
   'average of neighbours in z+1
   Corners = ( N_4D( x - 1, y - 1, z - 1, w + 1 ) +_
   N_4D( x + 1, y - 1, z - 1, w + 1 ) +_
   N_4D( x - 1, y + 1, z - 1, w + 1 ) +_
   N_4D( x + 1, y + 1, z - 1, w + 1 ) +_
   N_4D( x - 1, y - 1, z + 1, w + 1 ) +_
   N_4D( x + 1, y - 1, z + 1, w + 1 ) +_
   N_4D( x - 1, y + 1, z + 1, w + 1 ) +_
   N_4D( x + 1, y + 1, z + 1, w + 1 ) ) / 8.0f

   Sides   = ( N_4D( x - 1, y    , z    , w + 1 ) +_
   N_4D( x + 1, y    , z    , w + 1 ) +_
   N_4D( x    , y - 1, z    , w + 1 ) +_
   N_4D( x    , y + 1, z    , w + 1 ) +_
   N_4D( x    , y    , z - 1, w + 1 ) +_
   N_4D( x    , y    , z + 1, w + 1 ) ) / 6.0f

   Center  =   N_4D( x    , y    , z    , w + 1 ) / 2.0f
   fWp1     = Corners + Sides + Center
   Return(( fWm1 / 4.0f ) + ( fW / 2.0f ) + ( fWp1 / 4.0f ))
End Function
Function Noise.I_1D(x As Single) As Single
   Dim xf As Single=Frac(x)
   Dim xi As Integer=x-xf
   Dim As Single v0,v1
   v0=S_1D(xi)
   v1=S_1D(xi+1)

   'Return Cosine_Interpolate(v0,v1,xf)
   Return Linear_Interpolate(v0,v1,xf)
End Function
Function Noise.I_2D(x As Single,y As Single) As Single
   Dim xf As Single=Frac(x)
   Dim xi As Integer=x-xf
   Dim yf As Single=Frac(y)
   Dim yi As Integer=y-yf
   Dim As Single v0,v1,v2,v3,i0,i1
   v0=S_2D(xi,yi)
   v1=S_2D(xi+1,yi)
   v2=S_2D(xi,yi+1)
   v3=S_2D(xi+1,yi+1)
   i0=Linear_Interpolate(v0,v1,xf)
   i1=Linear_Interpolate(v2,v3,xf)

   'Return Cosine_Interpolate(i0,i1,yf)
   Return Linear_Interpolate(i0,i1,yf)
End Function
Function Noise.I_3D(x As Single,y As Single,z As Single) As Single
   Dim xf As Single=Frac(x)
   Dim xi As Integer=x-xf
   Dim yf As Single=Frac(y)
   Dim yi As Integer=y-yf
   Dim zf As Single=Frac(z)
   Dim zi As Integer=z-zf
   Dim As Single v0,v1,v2,v3,v4,v5,v6,v7,w0,w1,w2,w3,i0,i1
   v0=S_3D(xi,yi,zi)
   v1=S_3D(xi+1,yi,zi)
   v2=S_3D(xi,yi+1,zi)
   v3=S_3D(xi+1,yi+1,zi)
   v4=S_3D(xi,yi,zi+1)
   v5=S_3D(xi+1,yi,zi+1)
   v6=S_3D(xi,yi+1,zi+1)
   v7=S_3D(xi+1,yi+1,zi+1)
   w0=Linear_Interpolate(v0,v1,xf)
   w1=Linear_Interpolate(v2,v3,xf)
   w2=Linear_Interpolate(v4,v5,xf)
   w3=Linear_Interpolate(v6,v7,xf)
   i0=Linear_Interpolate(w0,w1,yf)
   i1=Linear_Interpolate(w2,w3,yf)

   'Return Cosine_Interpolate(i0,i1,zf)
   Return Linear_Interpolate(i0,i1,zf)
End Function
Function Noise.I_4D(x As Single,y As Single,z As Single,w As Single) As Single
   Dim xf As Single=Frac(x)
   Dim xi As Integer=x-xf
   Dim yf As Single=Frac(y)
   Dim yi As Integer=y-yf
   Dim zf As Single=Frac(z)
   Dim zi As Integer=z-zf
   Dim wf As Single=Frac(w)
   Dim wi As Integer=w-wf
   Dim As Single v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15
   Dim As Single w0,w1,w2,w3,w4,w5,w6,w7
   Dim As Single i0,i1,i2,i3
   Dim As Single j0,j1
   v0= S_4D(xi  ,yi  ,zi  ,wi  )
   v1= S_4D(xi+1,yi  ,zi  ,wi  )
   v2= S_4D(xi  ,yi+1,zi  ,wi  )
   v3= S_4D(xi+1,yi+1,zi  ,wi  )
   v4= S_4D(xi  ,yi  ,zi+1,wi  )
   v5= S_4D(xi+1,yi  ,zi+1,wi  )
   v6= S_4D(xi  ,yi+1,zi+1,wi  )
   v7= S_4D(xi+1,yi+1,zi+1,wi  )
   v8= S_4D(xi  ,yi  ,zi  ,wi+1)
   v9= S_4D(xi+1,yi  ,zi  ,wi+1)
   v10=S_4D(xi  ,yi+1,zi  ,wi+1)
   v11=S_4D(xi+1,yi+1,zi  ,wi+1)
   v12=S_4D(xi  ,yi  ,zi+1,wi+1)
   v13=S_4D(xi+1,yi  ,zi+1,wi+1)
   v14=S_4D(xi  ,yi+1,zi+1,wi+1)
   v15=S_4D(xi+1,yi+1,zi+1,wi+1)

   w0=Linear_Interpolate(v0,v1,xf)
   w1=Linear_Interpolate(v2,v3,xf)
   w2=Linear_Interpolate(v4,v5,xf)
   w3=Linear_Interpolate(v6,v7,xf)
   w4=Linear_Interpolate(v8,v9,xf)
   w5=Linear_Interpolate(v10,v11,xf)
   w6=Linear_Interpolate(v12,v13,xf)
   w7=Linear_Interpolate(v14,v15,xf)

   i0=Linear_Interpolate(w0,w1,yf)
   i1=Linear_Interpolate(w2,w3,yf)
   i2=Linear_Interpolate(w4,w5,yf)
   i3=Linear_Interpolate(w6,w7,yf)

   j0=Linear_Interpolate(i0,i1,zf)
   j1=Linear_Interpolate(i1,i2,zf)

   'Return Cosine_Interpolate(j0,j1,wf)
   Return Linear_Interpolate(j0,j1,wf)

End Function
Function Noise.P_1D(x As Single) As Single
   Dim sum As Single=0
   Dim fx As Single=frequenz_x
   Dim p As Single=persistenz
   Dim bereich As Single=(max-min)*0.5f
   For i As Integer =0 To octaven-1
      sum+=I_1D(x*fx)*bereich*p'(max-min)*0.5
      fx*=2.0f
      bereich/=2.0f
      p/=2.0f
   Next
   Return sum'I_1D(x*frequenz_x)*(max-min)*0.5
End Function
Function Noise.P_2D(x As Single,y As Single) As Single
   Dim sum As Single=0
   Dim p As Single=persistenz
   Dim bereich As Single=(max-min)*0.5f
   Dim fx As Single=frequenz_x
   Dim fy As Single=frequenz_y
   For i As Integer =0 To octaven-1
      sum+=I_2D(x*fx,y*fy)*bereich*p
      fx*=2.0f
      fy*=2.0f
      bereich/=2.0f
      p/=2.0f
   Next
   Return sum
End Function
Function Noise.P_3D(x As Single,y As Single,z As Single) As Single
   Dim sum As Single=0
   Dim p As Single=persistenz
   Dim bereich As Single=(max-min)*0.5f
   Dim fx As Single=frequenz_x
   Dim fy As Single=frequenz_y
   Dim fz As Single=frequenz_z
   For i As Integer =0 To octaven-1
      sum+=I_3D(x*fx,y*fy,z*fz)*bereich*p
      fx*=2.0f
      fy*=2.0f
      fz*=2.0f
      bereich/=2.0f
      p/=2.0f
   Next
   Return sum
End Function
Function Noise.P_4D(x As Single,y As Single,z As Single,w As Single) As Single
   Dim sum As Single=0
   Dim p As Single=persistenz
   Dim bereich As Single=(max-min)*0.5f
   Dim fx As Single=frequenz_x
   Dim fy As Single=frequenz_y
   Dim fz As Single=frequenz_z
   Dim fw As Single=frequenz_w
   For i As Integer =0 To octaven-1
      sum+=I_4D(x*fx,y*fy,z*fz,w*fw)*bereich*p
      fx*=2.0f
      fy*=2.0f
      fz*=2.0f
      fw*=2.0f
      bereich/=2.0f
      p/=2.0f
   Next
   Return sum
End Function







Dim N As Noise
N.seed=Timer*1000
N.octaven=1
N.frequenz_x=1.0
N.frequenz_y=0.5
N.frequenz_z=0.25
N.frequenz_w=0.125
N.persistenz=0.95
N.min=-1.0
N.max=1.0
Dim t As Single
Dim As Integer a
a=gluNewQuadric()
'While InKey=""
InitializeGL(ScreenResX, ScreenResY)
Do
   if inkey = chr(255)+"k" then exit do        '' exit if close box is clicked
   glClearColor (0.0f, 0.0f, 0.1f, 0.5)                    '' Set The Clear Color To Black
   glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)    '' Clear Screen And Depth Buffer
   glLoadIdentity ()                                       '' Reset The View
   ViewPerspective ()
   glDisable(GL_LIGHTING)
   SetCamera()
   'gluLookAt(0,-50,0,0,0,0,0,1,0)
   'ScreenLock
   'Line (0,0)-(800,600),0,BF
   glRotatef(t/2,0,1,0)
   For x As Single=-2 To 2 Step 1
      For y As Single=-2 To 2 Step 1
         For z As Single=-2 To 2 Step 1
'            glColor3f(1.0,N.P_1D(x+1+t),1.0)
            '1D
            glBegin(GL_LINES)
            glColor3f(1.0,N.P_1D(x+1+t),1.0)
            glVertex3f (x+1-20,N.P_1D(x+1+t)*5-10,0)
            glColor3f(1.0,N.P_1D(x+t),1.0)
            glVertex3f (x-20,N.P_1D(x+t)*5-10,0)
            glEnd()
            '2D
            glBegin(GL_QUADS)
            glColor3f(1.0,N.P_2D(x,y+1+t),1.0)
            glVertex3f (x,N.P_2D(x,y+1+t)*5-10,y+1)
            glColor3f(1.0,N.P_2D(x,y+1+t),1.0)
            glVertex3f (x+1,N.P_2D(x+1,y+1+t)*5-10,y+1)
            glColor3f(1.0,N.P_2D(x+1,y+t),1.0)
            glVertex3f (x+1,N.P_2D(x+1,y+t)*5-10,y)
            glColor3f(1.0,N.P_2D(x,y+t),1.0)
            glVertex3f (x,N.P_2D(x,y+t)*5-10,y)
            glEnd()
            '3D
            glColor3f(1.0,N.P_3D(x,y+1,t),1.0)
            glBegin(GL_QUADS)
            glVertex3f (x+20,N.P_3D(x,y+1,t)*5-10,y+1)
            glVertex3f (x+1+20,N.P_3D(x+1,y+1,t)*5-10,y+1)
            glVertex3f (x+1+20,N.P_3D(x+1,y,t)*5-10,y)
            glVertex3f (x+20,N.P_3D(x,y,t)*5-10,y)
            glEnd()
            '4D
            glColor3f(1.0,N.P_4D(x,y+1,z,t),1.0)
            glBegin(GL_QUADS)
            glVertex3f (x,N.P_4D(x,y+1,z,t)*5+10,y+1)
            glVertex3f (x+1,N.P_4D(x+1,y+1,z,t)*5+10,y+1)
            glVertex3f (x+1,N.P_4D(x+1,y,z,t)*5+10,y)
            glVertex3f (x,N.P_4D(x,y,z,t)*5+10,y)
            glEnd()
         Next
      Next
   Next
   'Print N.N_1D(Timer*10),N.N_2D(Timer,Timer*10),N.N_3D(Timer,Timer*10,Timer*100),N.N_4D(Timer,Timer*10,Timer*100,Timer*1000)
   'ScreenUnLock
   t+=0.1
   glFlush()
   ScreenSync
   Flip
   Sleep 1
Loop Until MultiKey(1)


die 4D variante scheint mir etwas komisch zu sein,
bzw nicht richtig zu funktionieren.
ja ich weis es giebt bessere algorithmen.
mir geht es aber erstmal ums verstaendniss.

Salute Haubitze
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht -> Allgemeine Fragen zu FreeBASIC. Alle Zeiten sind GMT + 1 Stunde
Seite 1 von 1

 
Gehe zu:  
Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.

 Impressum :: Datenschutz