Irgend etwas stimmt auch mit Int , Float , Sin oder Cos nicht.
Ich kann ein Auto(Grafik) drehen und in die gedrehte Richtung weiterfahren mit dem normalen XProfan und der XPSE-Rotate-Routine. Bei FreePascal-Profan stimmt die Drehrichtung nicht mit der Fahrtrichtung über ein.
Danke.
Gruss
peter
Beiträge von funkheld
-
-
Hier dreht sich ein Auto und fährt dann in die gedrehte Richtung weiter.
Mit FreePascal-Profan stimmt die Bewegungsrichtung nicht mit der gedrehten Richtung überein. Irgend etwas stimmt nicht mit der Mathematik in FreePascal-Profan.
Gruss
peter
Code
Alles anzeigen{$cleq} declare bpic&, bpic1&,ende&,winkel!,hintergrpic&,vordergrpic& declare x1!,y1!,dx!,dy! ende&=1 bpic& = create("hPic",-1,"data\\auto.bmp") Window 20,20-800,600 Cls RGB(220,220,220) bpic1& = create("hNewPic", 128,128,rgb(0,0,0)) hintergrpic& = create("hNewPic", 500,500,rgb(255,255,0)) vordergrpic& = create("hNewPic", 500,500,rgb(255,255,0)) startpaint hintergrpic& usebrush 1,rgb(0,128,255) ellipse 200,200-250,250 endpaint WHILE ende& if isKey(87) y1!=Sin((winkel!/1000)/180.0*pi())*0.2 x1!=Cos((winkel!/1000)/180.0*pi())*0.2 dx!=dx!-x1! dy!=dy!-y1! endif if isKey(83) y1!=Sin((winkel!/1000)/180.0*pi())*0.2 x1!=Cos((winkel!/1000)/180.0*pi())*0.2 dx!=dx!+x1! dy!=dy!+y1! endif if isKey(81) winkel!=winkel!-500 startpaint bpic1& drawhPicRotated(bpic&,hDC,50,50,128,128,winkel!,50) endpaint endif if isKey(69) winkel!=winkel!+500 startpaint bpic1& drawhPicRotated(bpic&,hDC,50,50,128,128,winkel!,50) endpaint endif startpaint vordergrpic& drawpic hintergrpic&,0,0;0 drawpic bpic1&,100+dx!,100+dy!;-1 endpaint drawpic vordergrpic&,10,10;0 ENDWHILE end nProc getCircP(long r,w) return long(sin(0.0174532925199433*float(w)/1000.0)*float(r)) endproc nProc angleByLine(long x,y,xx,yy) sub y,yy sub x,xx if x xx=int(57295.77951 * arctan(float(y)/float(x))) case x>0 : return 270000 + xx return 90000 + xx endif case y<0 : return 180000 return 0 endproc nProc drawhPicRotated(long hPic,dc,x,y,xx,yy,w,r) long hDCBits=createCompatibleDC(hDC) selectObject(hDCBits, hPic) long pts=dim(24) long w1=angleByLine(xx,yy,0,0),w2=abs(w1-360000),w3=abs(w1-540000) casenot r : r=long(sqrt(float(xx*xx+yy*yy)))\2 long pts&,0=x+getcircp(r,w1+w),y+getcircp(r,w1-90000+w),x+getcircp(r,w2+w),y+getcircp(r,w2-90000+w),x+getcircp(r,w3+w),y+getcircp(r,w3-90000+w) plgBlt(dc,pts,hDCBits,0,0,xx,yy,0,0,0) deleteDC(hDCBits) dispose(pts) endproc -
Jup, läuft ja schon wunderbar.
Sogar das XPSE lässt sich damit Complilieren und OGL.
Die Maus dreht das Object im IF's Beispiel :
Mit dem normalen XProfan/XPSE dreht sich das Object wenn ich die Maus im Window(graues Fenster) von XProfan bewege und auf dem OGL-Fenster. Bei dem FreePascal-Profan/XPSE dreht sich das Object nur wenn die Maus sich im grauen Fensterbereich befindet, bei Bewegung der Maus auf dem OGL-Fenster dreht sich das Object nicht.
Code
Alles anzeigen{$cleq} declare hWin& Window 20,20-800,800 Cls @RGB(220,220,220) hWin& = @Create("text", %hWnd, "Test1", 10, 10, 600,600) OGL("init",hwin&,0,0,0,5) OGL("posmode",1) int tex.spaceShip=ogl.loadtex("a.tex") int tex.background=ogl("loadtexturebmp","tile4.bmp",3) float x,y,xpos,ypos,f=1.6,fps=50,speed=0.5,wxpos,wypos long fpsc,fpstme=gettickcount+200,ompos while 1 fpsc+ if fpstme<gettickcount fpstme=fpstme+200 fps=fpsc fpsc=0 endif case mousepressed : break oGL("Clear") ogl("glEnable",GL_BLEND); ogl("glBlendFunc",GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ogl("move",0,0,-3) ogl("push") ogl("texture",tex.background,10) ogl("quad",8,8) ogl("texture",tex.spaceShip,1) ogl("quad",1,1) ogl("pop") ogl("push") ogl("move",x,y,1) ogl("rotate",0,0,mousex) ogl("texture",tex.spaceShip,1) ogl("quad",0.3,0.3) ogl("pop") ogl("show") wypos=sin((mousex+90)*0.01745329) wxpos=cos((mousex+90)*0.01745329) xpos=xpos+(wxpos-xpos)/(fps*10) ypos=ypos+(wypos-ypos)/(fps*10) y=y-ypos/(fps/speed)/2 x=x-xpos/(fps/speed)/2 wend end proc ogl.LoadTEX(string fileName) casenot fileexists(fileName) : return false casenot fileexists(fileName) : return false long fSiz=filesize(fileName) case (fSiz<4) : return false mem mem=fSiz long bytesRead=blockread(fileName,mem,0,fSiz) casenot (bytesRead==fSiz) : return false long iWidth=sqrt(fSiz\4) long txID=0 ogl("glGenTextures",1,addr(txID)) ogl("glBindTexture",GL_TEXTURE_2D,txID); ogl("glEnable",GL_ALPHA_TEST) ogl("glAlphaFunc",GL_GREATER, 0.1) ogl("glTexEnvi",GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ogl("glTexParameteri",GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ogl("glTexParameteri",GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) ogl("glMatrixMode",GL_PROJECTION) ogl("gluBuild2DMipmaps",GL_TEXTURE_2D, GL_RGBA, iWidth, iWidth, GL_RGBA, GL_UNSIGNED_BYTE, mem) dispose mem return txID endproc
Gruss
peter -
Hallo, guten Tag.
Gibt es schon Ansätze um mit XProfan DirectX zu bewerkstelligen ?
Wer kann dann dieses DirectX mal als Kursus anbieten mit XProfan ? Erste Dreiecke die sich drehen usw.
Danke.
Gruss
peter