Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Emboss_03.bas

Uploader:MitgliedMuttonhead
Datum/Zeit:15.02.2014 20:59:09

'******************************************************************************
const as single pi =atn (1) * 4
const as single doublepi=pi*2
const as single halfpi=pi/2


'******************************************************************************
#include "fbgfx.bi"
using FB

#include "ColorDefinition.bi"
dim as ColorDefinition s,d



'******************************************************************************
'******************************************************************************
'******************************************************************************
Screen 19,32

dim as any ptr SourceImage = ImageCreate(640,480)
dim as any ptr DestImage = ImageCreate(640,480)

BLoad "BumpMap3.bmp",SourceImage

dim as integer ibpp
dim as uinteger ipitch
dim as uinteger ptr pixelptr

ibpp=cast(Image ptr,SourceImage)->bpp
ipitch=cast(Image ptr,SourceImage)->pitch

'Verortung Licht im Koordinatensystem
'Licht kommt für jedes Pixel aus einer Richtung und einer Höhe, parallele Lichtstrahlen ähnlich Sonne
dim as single LightAzimutRad,LightHeightRad

'Höhe der Nebenpixel
dim as integer Pixel1PosZ,Pixel2PosZ,Pixel3PosZ,Pixel4PosZ'in Draufsicht--> l,r,o,u

'das zu untersuchende Pixel
dim as integer PixelPosX,PixelPosY,PixelPosZ'Position desPixels
dim as single PixelXRad 'Höhenwinkel bei 0 grd durch Pixel1PosZ und Pixel2PosZ definiert (ist bei 180 grd negativ)
dim as single PixelYRad'Höhenwinkel bei 90 grd durch Pixel2PosZ und Pixel3PosZ definiert (ist bei 270 grd negativ)
dim as single PixelLRad'Azimut des Lichtes
dim as single PixelXYRad'Höhenwinkel in Abhängigkeit vom Azimut
dim as single PixelDiffHeights'Lichthöhe

'Berechnungshilfen
dim as integer diffx,diffy,diffz

'Darstellung
dim as integer Xo,Yo

Xo=0
Yo=479

'Sonne
for i as single=0 to doublepi step 0.1

LightAzimutRad=i
LightHeightRad=.8

For y As integer= 0 to 479
  For x As integer=0 to 639
    PixelPosX=X
    PixelPosY=y

    '0.alle Höhen der vier anliegenden Pixel aus SourceImage holen,Farbwert Pixel merken (in d)
    pixelptr=(SourceImage + 32 + ((Yo-PixelPosY) * ipitch) + (PixelPosX * ibpp))
    d.SetRGB(*pixelptr)
    PixelPosZ=255 * d.GetValue/100

    if PixelPosX=0 then
      Pixel1PosZ=PixelPosZ
    else
      pixelptr=(SourceImage + 32 + ((Yo-PixelPosY) * ipitch) + ((PixelPosX-1) * ibpp))
      s.SetRGB(*pixelptr)
      Pixel1PosZ=255 * s.GetValue/100
    end if

    if PixelPosX=639 then
      Pixel2PosZ=PixelPosZ
    else
      pixelptr=(SourceImage + 32 + ((Yo-PixelPosY) * ipitch) + ((PixelPosX+1) * ibpp))
      s.SetRGB(*pixelptr)
      Pixel2PosZ=255 * s.GetValue/100
    end if

    if PixelPosY=0 then
      Pixel3PosZ=PixelPosZ
    else
      pixelptr=(SourceImage + 32 + ((Yo-PixelPosY-1) * ipitch) + (PixelPosX * ibpp))
      s.SetRGB(*pixelptr)
      Pixel3PosZ=255 * s.GetValue/100
    end if

    if PixelPosY=479 then
      Pixel4PosZ=PixelPosZ
    else
      pixelptr=(SourceImage + 32 + ((Yo-PixelPosY+1) * ipitch) + (PixelPosX * ibpp))
      s.SetRGB(*pixelptr)
      Pixel4PosZ=255 * s.GetValue/100
    end if

        'Schritte 1 und 2 sind reichlich unprofessionell, erfüllen aber ihren Zweck :)

    '1.Winkel für 0 grd berechnen in Bogenmaß
    'hier eine einfache gleichmäßige Zuordnung des entsprechenden Bogenmaßes zur Höhendifferenz
    PixelXRad=halfpi * (Pixel2PosZ-Pixel1PosZ)/255

    '2.Winkel für 90 grd berechnen in Bogenmaß
    'hier eine einfache gleichmäßige Zuordnung des entsprechenden Bogenmaßes zur Höhendifferenz
    PixelYRad=halfpi * (Pixel3PosZ-Pixel4PosZ)/255

    '3.Höhenwinkel des Pixels in Richtung Licht(Azimut) berechnen in Bogenmaß
    PixelXYRad=Cos(LightAzimutRad)*PixelXRad  +  sin(LightAzimutRad)*PixelYRad

      '4.Differenz relative Höhe Licht - Höhenwinkel Pixel in Richtung Licht
      'dieser Wert "pendelt" zwischen +pi/2  bis -Pi/2
      PixelDiffHeights= LightHeightRad - PixelXYRad
      if PixelDiffHeights>halfpi then PixelDiffHeights=doublepi-PixelDiffHeights

      '5. Farbe berechnen
    d.SetValue(d.GetValue+ 100 * (PixelDiffHeights/halfpi))
    '6. Pixel setzen
    pixelptr=DestImage + 32 + ((Yo-PixelPosY) * ipitch) + (PixelPosX * ibpp)
    *pixelptr=d.GetRGB

  Next x
Next y
Put(0,0),DestImage,pset

next i


bsave"screenshot.bmp",0
imagedestroy SourceImage
imagedestroy DestImage
sleep