|
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
Muecke Gast
|
Verfasst am: 07.01.2014, 20:13 Titel: OpenGL Kammera Perspektive |
|
|
Hallo miteinander,
ich bin ja immer noch dran mir meine Zeilenkamera irgend wie mal Grafisch darstellen zu lassen .
ich habe als erstes mal die "Zeilenkamera - Datei" gekürzt
jetzt habe ich mir gedacht wenn ich den Befehl
habe dann Trage ich dort meine Werte ein
und kann dann die Kammera Drehen dann müsste ich doch das Teil ungefähr so wie auf dem Bild sehen?
irgend wie finde ich nichts im Netz dazu ;-(
Tuts habe ich schon gefunden und durchgearbeitet doch das ist immer alles 2D ich glaube ich raffe das nicht
kann mir jemand einen Tipp geben?
Das ist der Code dazu:
Code: | Declare Sub Zeichnung (filename As String)
' --------------------------------------------------------------------------------------------------------------------------------------------------
' Einbinden der Grafiklib für Windows und Linux
' --------------------------------------------------------------------------------------------------------------------------------------------------
#Include once "GL/gl.bi"
#include once "GL/glu.bi"
' --------------------------------------------------------------------------------------------------------------------------------------------------
' Festlegung der Konstanten, die für den Bildschirm wichtig sind
' --------------------------------------------------------------------------------------------------------------------------------------------------
Const scrnX = 1024
const scrnY = 768
Const depth = 32
const fullscreen = &h0 ' Vollbildmodus ( &h0 = aus, &h1 = an )
ScreenRes scrnX,scrnY,depth,,&h2 OR fullscreen
' --------------------------------------------------------------------------------------------------------------------------------------------------
' Konfiguration von OpenGL
' --------------------------------------------------------------------------------------------------------------------------------------------------
glMatrixMode(GL_PROJECTION) ' Matrix definieren
glLoadIdentity
glViewport(0,0,scrnX,scrnY) ' Achse festlegen
glOrtho(0,scrnX,scrnY,0,-128,128)
glMatrixMode(GL_MODELVIEW) ' Deaktivierung des Rendern der Rückseiten
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
glEnable GL_TEXTURE_2D ' Texturen aktivieren
glLoadIdentity
glEnable(GL_DEPTH_TEST) ' Tiefentest
glDepthFunc(GL_LESS)
glEnable(GL_ALPHA_TEST) ' Alphatest
glAlphaFunc(GL_GREATER, 0.1)
glClearColor 1.0, 1.0, 1.0, 0.0 ' weisser Hintergrund
' ---------------------------
' Hauptschleife
' ESC Ende
' ---------------------------
Do ' ESC Ende
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT ' "CLS" für OpenGL
glColor3ub 255,0,0 '' rot
glBegin GL_POINTS
Zeichnung "C:\Users\00\Desktop\Data\OpenGL\Kurz.csv"
glEnd
glLoadIdentity ' Wiederherstellung Cursor auf (0, 0)
glFlush
flip
screensync
Loop until multikey(&h01) ' ESC Ende
Sub Zeichnung (filename As String)
Dim As String Text, Wert
Dim As Integer Spalte, Zeile, anfptr, endptr
Dim DNr As Integer = FreeFile
Zeile = 0
Open filename FOR INPUT ENCODING "ASCII" AS #DNr
Do
LINE INPUT #DNr, Text
Zeile + = 1: Spalte = 0: anfptr = 1
If Zeile <> 1 Then
Do ' string zerlegen
Spalte + = 1
endptr = InStr(anfptr, Text, ",") ' endpointer auf nächsten separator setzen
Wert = Mid(Text, anfptr, endptr - anfptr) ' teilstring
glVertex3f Spalte, Val(Wert), Zeile ' glVertex3f (x,y,z)
anfptr = endptr + 1 ' anfangspointer hinter den separator setzen
Loop Until endptr = 0 ' weitermachen, bis der string zuende ist (wenn Seperator nicht gefunden wierd wir 0 ausgegeben)
EndIf
Loop until eof(1)
End Sub
|
das ist meine Kleine Muster 3D Datei: https://dl.dropboxusercontent.com/u/130479015/Forum/FreeBasic/Kurz.csv
erste Zeile sind die X Werte
zu beginn jeder Zeile kommt meine ich der Wert Z
ich habe die erste ziele erst mal ignoriert und Sätze X je Spalte immer um eins nach Oben.
Den Z Wert habe ich auch pro Zeile eins nach Oben gesetzt.
[EDIT] URL Korrektur zu Datei Kurz
Zuletzt bearbeitet von Muecke am 21.01.2014, 17:21, insgesamt einmal bearbeitet |
|
Nach oben |
|
|
micha
Anmeldungsdatum: 09.12.2005 Beiträge: 72
|
Verfasst am: 08.01.2014, 19:09 Titel: |
|
|
Code: | #include once "fbgfx.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"
const FILE = "Kurz.csv"
const scr_w = 800
const scr_h = 600
function IsNumber(char as integer) as integer
return instr("-.0123456789",chr(char))
end function
' open the file
ChDir ExePath()
dim as integer hFile = FreeFile()
if open(FILE for input as #hFile) then
print "error can' read [" & FILE & "] !"
beep:sleep:end 1
end if
dim as integer nChars,n
dim as string number,aLine
' ignore first line (X/Y header)
line input #hFile,aLine
' get all rows (y coords)
dim as single ptr ptr Rows
dim as single ptr row
dim as integer nRows,cRow,nItems
' read rest of the file
while not EOF(hFile)
cRow = 0 : Row = 0
Rows = reallocate(Rows,(nRows+1)*sizeof(single ptr))
line input #hFile,aLine
nChars=len(aLine):n=0
' ignore first item (z coord)
while IsNumber(aLine[n]) : n+=1 : wend : n+=1
while n<nChars
row = reallocate(row,(cRow+1)*sizeof(single))
number="" : while IsNumber(aLine[n]) : number &= chr(aLine[n]) : n+=1 : wend : n+=1
if len(number) then ' the rest of the row are y coords
row[cRow]=val(number) : cRow+=1
else ' ",," is 0.0
row[cRow]=row[cRow-1] : cRow+=1
end if
wend
Rows[nRows]=Row
if cRow>nItems then nItems=cRow
nRows+=1 ' next row
wend
' close the file
close #hFile
screenres 640,480,32,,2
flip
glDisable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60,scr_w/scr_h,1,nItems*2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
dim as single camx,camy,camz
dim as single w
while inkey=""
camx=cos(w)*150
camz=sin(w)*150
camy=-80
w+=0.01
glClear(GL_COLOR_BUFFER_BIT)
glPushMatrix()
gluLookAt(-camx,-camy,-camz, 0,0,0, 0,1,0)
glBegin(GL_POINTS)
for zc as integer = 0 to nRows-1
Row=Rows[zc]
for xc as integer = 0 to nItems-1
dim as single y=row[xc]
glVertex3f(xc-(nItems\2),y,zc-(nRows\2))
next
next
glEnd()
glPopMatrix()
flip
wend |
Zuletzt bearbeitet von micha am 09.01.2014, 05:14, insgesamt 2-mal bearbeitet |
|
Nach oben |
|
|
micha
Anmeldungsdatum: 09.12.2005 Beiträge: 72
|
Verfasst am: 09.01.2014, 04:26 Titel: |
|
|
Hallo Muecke,
hier mal als GL_TRIANGLES und Beleuchtung 14 Reihen sind aber zu wenig (bei 1010 Spalten).
Poste doch mal einen Link zu einem kompletten CSV Datensatz.
Was ist der Wert für fehldende Y Werte also zwei aufeinander folgende Kommas ,, ich bin von 0.0 ausgegangen ?
Micha
Code: | #include once "fbgfx.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"
const FILE = "Kurz.csv"
const scr_w = 800
const scr_h = 600
function IsNumber(char as integer) as integer
return instr("-.0123456789",chr(char))
end function
' open the file
ChDir ExePath()
dim as integer hFile = FreeFile()
if open(FILE for input as #hFile) then
print "error can't read [" & FILE & "] !"
beep:sleep:end 1
end if
dim as integer nChars,n
dim as string number,aLine
' ignore first line (X/Y header)
line input #hFile,aLine
' get all rows (y coords)
dim as single ptr ptr Rows
dim as single ptr row
dim as integer nRows,cRow,nItems
' read rest of the file
while not EOF(hFile)
cRow = 0 : Row = 0
Rows = reallocate(Rows,(nRows+1)*sizeof(single ptr))
line input #hFile,aLine
nChars=len(aLine):n=0
' ignore first item (z coord)
while IsNumber(aLine[n]) : n+=1 : wend : n+=1
while n<nChars
row = reallocate(row,(cRow+1)*sizeof(single))
number="" : while IsNumber(aLine[n]) : number &= chr(aLine[n]) : n+=1 : wend : n+=1
if len(number) then ' the rest of the row are y coords
row[cRow]=val(number) : cRow+=1
else ' ",," is it 0.0 ???
row[cRow]=0.0 : cRow+=1
end if
wend
Rows[nRows]=Row
if cRow>nItems then nItems=cRow
nRows+=1 ' next row
wend
' close the file
close #hFile
' setup OpenGL
ScreenRes 640,480,32,,FB.GFX_OPENGL
'`quality
glShadeModel(GL_SMOOTH)
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
' pixel buffer
glClearColor(0.3, 0.3, 0.8, 0.0)
' z buffer
glEnable (GL_DEPTH_TEST)
glClearDepth(1.0)
' face visibilty
glDisable(GL_CULL_FACE)
' light
glEnable (GL_LIGHTING)
dim as single LightPos(3)=>{1,5,1,1}
dim as single LightDif(3)=>{1,1,1,1}
dim as single LightSpe(3)=>{1,0.8,0.4,1}
glLightfv (GL_LIGHT0, GL_POSITION,@LightPos(0))
glLightfv (GL_LIGHT0, GL_DIFFUSE ,@LightDif(0))
glLightfv (GL_LIGHT0, GL_SPECULAR,@LightSpe(0))
glEnable (GL_LIGHT0)
' material
glEnable (GL_COLOR_MATERIAL)
dim as single MatDif(3)=>{.8,.8,.8,1}
dim as single MatSpe(3)=>{1,1,1,1}
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE ,@MatDif(0))
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,@MatSpe(0))
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS,50)
glMateriali (GL_FRONT_AND_BACK, GL_COLOR_MATERIAL_PARAMETER, GL_SPECULAR)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60,scr_w/scr_h,1,nItems*2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
dim as single camx,camy,camz
dim as single w
while inkey=""
camx=cos(w)*200
camz=sin(w)*200
camy=-50
w+=0.01
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glPushMatrix()
' move the camera
gluLookAt(-camx,-camy,-camz, 0,0,0, 0,1,0)
' render geom
glBegin(GL_TRIANGLES)
for zc as integer = 0 to nRows-2
dim as single z0 = zc -(nRows\2)
dim as single z1 = (zc+1)-(nRows\2)
dim as single z2 = z1
dim as single z3 = z0
dim as single ptr Row1=Rows[zc ]
dim as single ptr Row2=Rows[zc+1]
for xc as integer = 0 to nItems-2
dim as single y0=row1[xc+0],y1=row2[xc+0],y2=row2[xc+1],y3=row1[xc+1]
dim as single x0=(xc+0)-(nItems\2),x1=x0,x2=(xc+1)-(nItems\2),x3=x2
' calculate face A normale
dim as single ax = x1 - x0,ay = y1 - y0,az = z1 - z0
dim as single bx = x2 - x0,by = y2 - y0,bz = z2 - z0
' cross product
dim as single nx = ay*bz - az*by, ny = az*bx - ax*bz, nz = ax*by - ay*bx
' normalize
dim as single l = nx*nx + ny*ny + nz*nz
if abs(l)>0.01 then
l=1.0/sqr(l) : nx*=l : ny*=l : nz*=l
else
nx=0:ny=1:nz=0
end if
' render face A
glNormal3f(nx,ny,nz):glColor3f(.2,.8,.2)
glVertex3f(x0,y0,z0):glVertex3f(x1,y1,z1):glVertex3f(x2,y2,z2)
' calculate face B normale
ax = x2 - x0: ay = y2 - y0: az = z2 - z0
bx = x3 - x0: by = y3 - y0: bz = z3 - z0
' cross product
nx = ay*bz - az*by: ny = az*bx - ax*bz: nz = ax*by - ay*bx
' normalize
l = nx*nx + ny*ny + nz*nz
if abs(l)>0.01 then
l=1.0/sqr(l) : nx*=l : ny*=l : nz*=l
else
nx=0:ny=1:nz=0
end if
' render face B
glNormal3f(nx,ny,nz)
glColor3f(.2,.8,.2)
glVertex3f(x0,y0,z0)
glVertex3f(x2,y2,z2)
glVertex3f(x3,y3,z3)
next
next
glEnd()
glPopMatrix()
flip
wend |
|
|
Nach oben |
|
|
micha
Anmeldungsdatum: 09.12.2005 Beiträge: 72
|
Verfasst am: 14.01.2014, 09:10 Titel: |
|
|
micha hat Folgendes geschrieben: | Poste doch mal einen Link zu einem kompletten CSV Datensatz. |
|
|
Nach oben |
|
|
Muecke Gast
|
Verfasst am: 14.01.2014, 14:01 Titel: |
|
|
die Original Datei ist auch nicht größer da ich gerade nur mit mustern arbeite
in der Original Datei sind 14 Weitere Zeilen oben dran mit Informationen zur Kammer und zu dem Leser etc.
Die Richtig großen Datensätze habe ich noch nicht hier hier bei mir .
das mit der OPENGL Lib habe ich mir versucht irgend wie zu erklären doch das ist für mich irgend wie etwas zu hoch glaube ich, daher habe ich mir den Schnitt selber gezeichnet aus den Daten und arbeite gerade nur mit der Schnittansicht erst einmal.
http://forum.qbasic.at/viewtopic.php?p=104543 |
|
Nach oben |
|
|
Muecke Gast
|
|
Nach oben |
|
|
|
|
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.
|
|