Schatten-Engine
Übersicht

![]() |
StepTigerBetreff: Schatten-Engine |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo!
Also ich habe mich mal an einer Schattenengine versucht. Hab auch alles durchgerechnet! stimmt so, etwas langsam aber schatten wird projeziert! Aber: Immer wenn ich mich etwas bewege(nur in die x+ und z+ richtung), zeigt es eine "Memory Acces Violation" Meldung an. Die Resourcen sind alle da, aber seit ich die Schatten intigriert habe klappt es nicht mehr. Und warum zeigt es den Fehler nur, wenn ich mich in diese Richtungen(z+ und x+) bewege? anders herum aber nicht? Fehler im code? Villeicht dividieren durch 0 oder so? hier mal der code: Code: [AUSKLAPPEN] ; Shadows by StepTiger
AppTitle "Real Shadow System","Wirklich beenden?" SeedRnd MilliSecs() ;Global conditions Graphics3D 1024,768,32,2 Global objects=0,playerpivot,player,px,py,pzworld Global cam,camx#,camy#,camz#,yangle#,xangle# Global forward,world Global fallspeed#,oldpx#,oldpz#,dif#,gdif#,odif#,difx#,difz#,oldmoved,nx#,ny#,nz# Global shadowmaxdist#=500,maxlife#=100.,plife#=maxlife# debug=1 HidePointer ;the zombie Global zombie=LoadAnimMesh("zombie\zombie.b3d") RotateEntity zombie,0,135,0 ScaleEntity zombie,.6,.6,.6 TurnEntity zombie,0,135+90,0 PositionEntity zombie,0,0,0 Global zom_walk1=ExtractAnimSeq(zombie,2,20) Global zom_walk2=ExtractAnimSeq(zombie,22,36) Global zom_getatt1=ExtractAnimSeq(zombie,38,47) Global zom_getatt2=ExtractAnimSeq(zombie,48,57) Global zom_killback=ExtractAnimSeq(zombie,59,75) Global zom_lying=ExtractAnimSeq(zombie,78,88) Global zom_killfront=ExtractAnimSeq(zombie,91,103) Global zom_kickatt=ExtractAnimSeq(zombie,106,115) Global zom_punchgrabatt=ExtractAnimSeq(zombie,117,128) Global zom_headnutatt=ExtractAnimSeq(zombie,129,136) Global zom_idle1=ExtractAnimSeq(zombie,137,169) Global zom_idle2=ExtractAnimSeq(zombie,170,200) Global zom_beatatt=ExtractAnimSeq(zombie,201,206) ; Animate zombie,1,.3,punchgrabatt EntityAutoFade zombie,120,130 HideEntity zombie ;the zombie type Type zombie Field x#,y#,z#,lif# Field obj,action,attacktime,idletime,piv,shad End Type ;the shadow type Type shadow Field obj End Type ;The Backgroundmusic bgm=LoadSound("bgm\bgm.mp3") LoopSound bgm SoundPitch bgm,25000 PlaySound bgm ;The collision types and configuration Global type_player=1 Global type_world=2 Global type_scenery=3 Global type_zombie=4 Collisions type_player,type_world,2,2 Collisions type_player,type_zombie,2,2 ;The player model playerpivot=CreatePivot() player=LoadMD2("model\tris.md2",playerpivot) EntityColor player,255,255,255 ScaleEntity player,.2,.2,.2 playertex=LoadTexture("model\ctf_b.pcx") EntityTexture player,playertex AnimateMD2 player,1,.09,0,5 EntityType playerpivot,type_player EntityRadius playerpivot,2.2,5 CreateListener(playerpivot) px=640 pz=640 py=25 ;sound options Global hit1=Load3DSound("sounds\hit1.wav") Global hit2=Load3DSound("sounds\hit2.wav") Global hit3=Load3DSound("sounds\hit3.wav") Global hit4=Load3DSound("sounds\hit4.wav") ;Camera settings cam=CreateCamera() PositionEntity cam,0,10,-50 CameraFogMode cam,1 inner=0 outer=130 CameraFogRange cam,inner,outer fogsphere=CreateSphere(20,playerpivot) ScaleEntity fogsphere,outer,outer,outer EntityColor fogsphere,0,0,0 FlipMesh fogsphere EntityAlpha fogsphere,.7 fogsphere=CreateSphere(20,playerpivot) ScaleEntity fogsphere,inner,inner,inner EntityColor fogsphere,0,0,0 FlipMesh fogsphere EntityAlpha fogsphere,.5 ;Light setting Global light=CreateLight(3,playerpivot) PositionEntity light,0,20,0 PointEntity light,player ; TurnEntity light,180,0,0 lhell=50 LightRange light,120 LightColor light,lhell,lhell,lhell LightConeAngles light,0,360 hel=50 AmbientLight hel,hel,hel ;world setting world=LoadTerrain("world\world.bmp") worldtex=LoadTexture("world\moss.bmp") ScaleTexture worldtex,10,10 EntityTexture world,worldtex ScaleEntity world,5,50,5 TerrainShading world,10 TerrainDetail world,3000,1 EntityType world,type_world EntityPickMode world,2 ;last setting PositionEntity playerpivot,px,py,pz Global cu=CreateCube() ScaleEntity cu,2,2,2 PositionEntity cu,50,10,50 EntityColor cu,255,255,255 Global cu_shadow=CreateCube() ScaleEntity cu_shadow,2,2,2 PositionEntity cu_shadow,50,10,50 EntityColor cu_shadow,20,20,20 EntityAlpha cu_shadow,1 ;set some zombies For x=1 To 10 zombie(Rnd(1200)+40,Rnd(1280)+40,Rnd(15.)+5.) Next zombie(640,640,Rnd(15.)+5.) ;main Loop While Not KeyDown(1) SetBuffer BackBuffer() updategame() UpdateWorld RenderWorld For dddx.shadow=Each shadow FreeEntity dddx\obj Delete dddx Next If debug=1 Text 1,1,difx# Text 1,20,difz# Text 1,40,dif# Text 1,60,gdif# Text 1,80,oldpx# Text 1,100,oldpz# Text 1,120,fallspeed# Text 1,140,TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot)) Text 1,160,EntityY(playerpivot) Text 1,180,EntityX(cu)+" "+EntityY(cu)+" "+EntityZ(cu) Text 1,200,CountSurfaces(cu)+" "+CountVertices(GetSurface(cu,1)) dax.zombie=First zombie Text 1,220,AnimTime(dax\obj)+" "+AnimSeq(dax\obj)+" "+zom_lying Text 1,240,EntityX(dax\obj,1)+"x "+EntityY(dax\obj,1)+"y "+EntityZ(dax\obj,1)+"z" Text 1,260,EntityX(dax\piv,1)+"x "+EntityY(dax\piv,1)+"y "+EntityZ(dax\piv,1)+"z" dax.zombie=After dax.zombie Text 1,280,EntityX(dax\obj,1)+"x "+EntityY(dax\obj,1)+"y "+EntityZ(dax\obj,1)+"z" Text 1,300,EntityX(dax\piv,1)+"x "+EntityY(dax\piv,1)+"y "+EntityZ(dax\piv,1)+"z" Text 1,320,nx#+" "+ny#+" "+nz# EndIf updatehud() Flip Wend ;End of all End ;Functions ;main update functions Function updategame() updateplayer() updatezombies() updatecam() End Function Function updateplayer() moved=0 If KeyDown(17) And EntityY(playerpivot)<TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot))+10 MoveEntity playerpivot,0,0,.32 moved=1 If MD2AnimTime(player)<40 Or MD2AnimTime(player)>46 Or forward=0 If dif#=0 AnimateMD2 player,1,0.1,40,46 Else AnimateMD2 player,1,dif#,40,46 EndIf EndIf forward=1 EndIf If KeyDown(31) And EntityY(playerpivot)<TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot))+10 MoveEntity playerpivot,0,0,-.25 moved=1 If MD2AnimTime(player)<40 Or MD2AnimTime(player)>46 Or forward=1 AnimateMD2 player,1,-0.08,40,46 EndIf forward=0 EndIf If KeyDown(30) MoveEntity playerpivot,-.2,0,0 moved=1 EndIf If KeyDown(32) MoveEntity playerpivot,.2,0,0 moved=1 EndIf If KeyHit(57) And EntityY(playerpivot)<TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot))+10 fallspeed#=fallspeed#-2 EndIf If EntityY(playerpivot)>TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot))+10 TranslateEntity playerpivot,difx#*.95,0,difz#*.95 EndIf xspeed#=-MouseXSpeed()/5. yspeed#=MouseYSpeed()/5. xangle#=xangle#-yspeed# yangle#=yangle#-xspeed# If xangle#>75 Then xangle#=75 If xangle#<60 Then xangle#=60 RotateEntity playerpivot,0,-yangle#,0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 If moved=0 If MD2AnimTime(player) < 0 Or MD2AnimTime(player) > 10 AnimateMD2 player,1,0.1,0,5 EndIf EndIf If oldmoved=1 And moved=1 difx#=Abs(EntityX(playerpivot)-oldpx#) difz#=Abs(EntityZ(playerpivot)-oldpz#) dif#=(difx#^2)+(difz#^2) dif#=Sqr(dif#) odif#=dif# gdif#=1-dif#*3 gdif#=gdif# If gdif#<0 Then gdif#=0 fallspeed#=fallspeed#+(gdif#) Else fallspeed#=fallspeed#+.1 dif#=0 EndIf oldmoved=moved gravity(fallspeed#) If fallspeed#>3 Then fallspeed#=3 oldpx#=EntityX#(playerpivot) oldpz#=EntityZ#(playerpivot) End Function Function updatezombies() For x.zombie=Each zombie shadow(light,x\obj) If x\lif#>0 If EntityDistance(playerpivot,x\piv)<100 wink#=ATan2(EntityX#(x\piv)-EntityX(playerpivot),EntityZ#(x\piv)-EntityZ(playerpivot)) RotateEntity x\piv,0,360-wink#,0 If EntityDistance(x\piv,playerpivot)<7 move=1 If (((Not(AnimSeq(x\obj)=zom_kickatt)) And (Not(AnimSeq(x\obj)=zom_punchgrabatt)) And (Not(AnimSeq(x\obj)=zom_headnutatt)) And (Not(AnimSeq(x\obj)=zom_beatatt)) Or MilliSecs()>attacktime) And MilliSecs()>x\idletime) att=Rnd(3) If att=0 Then Animate x\obj,3,.2,zom_kickatt If att=1 Then Animate x\obj,3,.6,zom_punchgrabatt If att=2 Then Animate x\obj,3,.3,zom_headnutatt If att=3 Then Animate x\obj,3,.2,zom_beatatt x\attacktime=MilliSecs()+2000 x\idletime=MilliSecs()+3000 EndIf If (AnimSeq(x\obj)=zom_kickatt) And AnimTime(x\obj)>5 And AnimTime(x\obj)<5.5 And EntityDistance(x\piv,playerpivot)<5 plife#=plife#-2.5 rndsound=Rand(3) If rndsound=0 Then EmitSound(hit1,x\piv) If rndsound=1 Then EmitSound(hit2,x\piv) If rndsound=2 Then EmitSound(hit3,x\piv) If rndsound=3 Then EmitSound(hit4,x\piv) EndIf If (AnimSeq(x\obj)=zom_punchgrabatt) And AnimTime(x\obj)>5 And AnimTime(x\obj)<5.5 And EntityDistance(x\piv,playerpivot)<4 rndsound=Rand(3) If rndsound=0 Then EmitSound(hit1,x\piv) If rndsound=1 Then EmitSound(hit2,x\piv) If rndsound=2 Then EmitSound(hit3,x\piv) If rndsound=3 Then EmitSound(hit4,x\piv) plife#=plife#-.5 EndIf If (AnimSeq(x\obj)=zom_headnutatt) And AnimTime(x\obj)>5 And AnimTime(x\obj)<5.5 And EntityDistance(x\piv,playerpivot)<3 rndsound=Rand(3) If rndsound=0 Then EmitSound(hit1,x\piv) If rndsound=1 Then EmitSound(hit2,x\piv) If rndsound=2 Then EmitSound(hit3,x\piv) If rndsound=3 Then EmitSound(hit4,x\piv) plife#=plife#-.6 EndIf If (AnimSeq(x\obj)=zom_beatatt) And AnimTime(x\obj)>4 And AnimTime(x\obj)<4.5 And EntityDistance(x\piv,playerpivot)<3 rndsound=Rand(3) If rndsound=0 Then EmitSound(hit1,x\piv) If rndsound=1 Then EmitSound(hit2,x\piv) If rndsound=2 Then EmitSound(hit3,x\piv) If rndsound=3 Then EmitSound(hit4,x\piv) plife#=plife#-5. EndIf Else If MilliSecs()>x\attacktime If difwink#<3 move=1 MoveEntity x\piv,0,0,-.3 If ((Not(AnimSeq(x\obj)=zom_walk2)) And ((Not(AnimSeq(x\obj)=zom_kickatt)) And (Not(AnimSeq(x\obj)=zom_punchgrabatt)) And (Not(AnimSeq(x\obj)=zom_headnutatt)) And (Not(AnimSeq(x\obj)=zom_beatatt)) Or (MilliSecs()>x\attacktime))) Then Animate x\obj,1,.3,zom_walk2:x\idletime=MilliSecs()+3000 EndIf EndIf EndIf Else If Not(AnimSeq(x\obj)=zom_idle1) Then Animate x\obj,1,.1,zom_idle1 EndIf Else If ((Not(AnimSeq(x\obj)=zom_killback)) And (Not(AnimSeq(x\obj)=zom_lying)) And (Not(AnimSeq(x\obj)=zom_beatatt)) And (Not(AnimSeq(x\obj)=zom_killfront))) Then Animate x\obj,1,.8,zom_lying EndIf PositionEntity x\piv,EntityX(x\piv),TerrainY(world,EntityX(x\piv)+1.5,0,EntityZ(x\piv)),EntityZ(x\piv) Next End Function Function shadow(tlight,tobj) p.shadow=New shadow ; p\obj=CreateSphere() ; ScaleEntity p\obj,5,.1,5 p\obj=LoadAnimMesh("zombie\zombie.b3d") SetAnimTime p\obj,AnimTime(tobj),AnimSeq(tobj) PositionEntity p\obj,EntityX(tobj,1),EntityY(tobj,1),EntityZ(tobj,1) ScaleEntity p\obj,.6,.6,.6 RotateEntity p\obj,0,EntityYaw(tobj),0 EntityColor p\obj,0,0,0 EntityAlpha p\obj,.9 lx#=EntityX(tlight,1) ly#=EntityY(tlight,1) lz#=EntityZ(tlight,1) ox#=EntityX(tobj,1) oy#=EntityY(tobj,1) oz#=EntityZ(tobj,1) For x=1 To CountSurfaces(p\obj) tx=x face=GetSurface(tobj,x) sace=GetSurface(p\obj,tx) For y=1 To CountVertices(sace) dif#=Abs((((lx#-VertexX(face,y)))^2+((lz#-VertexZ(face,y))^2)))^.5 dify#=(ly#-VertexY(face,y)) wink#=ATan2((lx#-VertexX(face,y)),(lz#-VertexZ(face,y)))+180. If ly#>VertexY(sace,y) faktor#=dif#/(ly#-VertexY(face,y)) nx#=Sin(wink#)*faktor#*ly#+ox# nz#=Cos(wink#)*faktor#*ly#+oz# ny#=TerrainY(world,nx#,0,nz#)+1 VertexCoords sace,y,nx#,ny#,nz# EndIf Next Next End Function Function gravity(grav#=.1) If (EntityCollided(playerpivot,type_world))=1 And EntityY(playerpivot)<TerrainY(world,EntityX(playerpivot),0,EntityZ(playerpivot))+10 If fallspeed#>=.1 Then fallspeed#=fallspeed#-.09 EndIf TranslateEntity playerpivot,0,-fallspeed#,0 End Function Function updatecam() camx#=EntityX(playerpivot) camy#=EntityY(playerpivot) camz#=EntityZ(playerpivot) camx#=camx#+(Sin(yangle#+180)*30)*(1-Cos(xangle#)) camz#=camz#+(Cos(yangle#+180)*30)*(1-Cos(xangle#)) camy#=camy#+Sin(xangle#+90)*30 If camy#<TerrainY(world,camx#,0,camz#) Then camy#=TerrainY(world,camx#,0,camz#)+5 PositionEntity cam,camx#,camy#,camz# PointEntity cam,playerpivot End Function Function updatehud() maxx#=200 maxy#=50 thx#=maxx#/maxlife# thpx#=GraphicsWidth()-30-maxx# thpy#=30 thmx#=thx#*plife# Color 255,0,0 Rect thpx#,thpy#,thmx#,maxy# End Function ;other needed functions Function zombie(ddx#,ddz#,lif#) dx.zombie=New zombie dx\piv=CreatePivot() EntityType dx\piv,type_zombie EntityRadius dx\piv,2.2,5 dx\obj=CopyEntity(zombie,dx\piv) ShowEntity dx\obj dx\x#=ddx# dx\z#=ddz# dx\y#=50 PositionEntity dx\piv,dx\x#,dx\y#,dx\z# dx\lif#=lif# dx\action=zom_idle2 End Function Function RegisterObject(obj,obj_typ=0,facedetect=0) objects=objects+1 If Not (obj_typ=0) Then EntityType obj,obj_typ End Function |
||
Noch gestern standen wir am Abgrund, doch heute sind wir schon einen Schritt weiter.
Computer: AMD Sempron 3000+; ATI Radeon 9800 Pro; 512 MB DDR RAM 400Mhz; Asus E7N8X-E Deluxe; Samsung 200GB HD 5.4ns acces t Gewinner: BP Code Compo #2 Π=3.141592653589793238...<--- und das aus dem kopf ![]() Seit der Earthlings-Diskussion überzeugter Fleisch(fr)esser. |
![]() |
Mr.Keks |
![]() Antworten mit Zitat ![]() |
---|---|---|
woha, danke, ein ganzer programmcode inklusive sound, animation, wasweißich, natürlich durch externe dateien nicht so ohne weiteres ausführbar und kein hinweis, wo der debugger den fehler markiert. das macht es nicht gerade leicht, dir zu helfen ^^. | ||
MrKeks.net |
![]() |
StepTiger |
![]() Antworten mit Zitat ![]() |
---|---|---|
huch! Stimmt ja! Also es geht vor allem um diesen Part des Codes:
Code: [AUSKLAPPEN] Function shadow(tlight,tobj)
p.shadow=New shadow ; p\obj=CreateSphere() ; ScaleEntity p\obj,5,.1,5 p\obj=LoadAnimMesh("zombie\zombie.b3d") SetAnimTime p\obj,AnimTime(tobj),AnimSeq(tobj) PositionEntity p\obj,EntityX(tobj,1),EntityY(tobj,1),EntityZ(tobj,1) ScaleEntity p\obj,.6,.6,.6 RotateEntity p\obj,0,EntityYaw(tobj),0 EntityColor p\obj,0,0,0 EntityAlpha p\obj,.9 lx#=EntityX(tlight,1) ly#=EntityY(tlight,1) lz#=EntityZ(tlight,1) ox#=EntityX(tobj,1) oy#=EntityY(tobj,1) oz#=EntityZ(tobj,1) For x=1 To CountSurfaces(p\obj) tx=x face=GetSurface(tobj,x) sace=GetSurface(p\obj,tx) For y=1 To CountVertices(sace) dif#=Abs((((lx#-VertexX(face,y)))^2+((lz#-VertexZ(face,y))^2)))^.5 dify#=(ly#-VertexY(face,y)) wink#=ATan2((lx#-VertexX(face,y)),(lz#-VertexZ(face,y)))+180. If ly#>VertexY(sace,y) faktor#=dif#/(ly#-VertexY(face,y)) nx#=Sin(wink#)*faktor#*ly#+ox# nz#=Cos(wink#)*faktor#*ly#+oz# ny#=TerrainY(world,nx#,0,nz#)+1 VertexCoords sace,y,nx#,ny#,nz# EndIf Next Next End Function Wenn ich das ganze mit einer kugel mache und die vertexes nicht beachte, sondern nur das ganze objekt, geht es so weit, dass es ab einer bestimmten distanz eine memory acces violation gibt Wenn ich die vertexes nehme, geht es auch, aber wenn ich mich in richtung z oder x nach oben bewege, gibt es eine memory acces violation die restlichen dateien lad ich gleich mal auf meinen server und setzt dann den link hier rein! |
||
Noch gestern standen wir am Abgrund, doch heute sind wir schon einen Schritt weiter.
Computer: AMD Sempron 3000+; ATI Radeon 9800 Pro; 512 MB DDR RAM 400Mhz; Asus E7N8X-E Deluxe; Samsung 200GB HD 5.4ns acces t Gewinner: BP Code Compo #2 Π=3.141592653589793238...<--- und das aus dem kopf ![]() Seit der Earthlings-Diskussion überzeugter Fleisch(fr)esser. |
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
ganz spontan würde ich darauf tippen, dass "(ly#-VertexY(face,y)) " gegen 0 geht.
Für einen Fehler muss es dabei nicht wirklich 0 sein, sondern schon < 0.0001 wird zu sehr grossen Werten führen. Ich würde also empfehlen, diesen Wert vorher zu berechnen und falls <0.0001 (oder 0.00001) einfach auf den entsprechenden Grenzwert setzen. (bzw den wert berechnest du ja vorher schon) |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
![]() |
StepTiger |
![]() Antworten mit Zitat ![]() |
---|---|---|
ICH HAB DEN FEHLER DES SYSTEMS GEFUNDEN!
Ich gehe sonst immer davon aus, dass sich alle vertexes verziehen! Aber die, die direkt beleuchtet werden, werden nicht verzogen! Ich setz mich dann mal daran! Wenn einer noch nen Vorschlag hat, dann poste er ihn bitte! |
||
Noch gestern standen wir am Abgrund, doch heute sind wir schon einen Schritt weiter.
Computer: AMD Sempron 3000+; ATI Radeon 9800 Pro; 512 MB DDR RAM 400Mhz; Asus E7N8X-E Deluxe; Samsung 200GB HD 5.4ns acces t Gewinner: BP Code Compo #2 Π=3.141592653589793238...<--- und das aus dem kopf ![]() Seit der Earthlings-Diskussion überzeugter Fleisch(fr)esser. |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group