Code archives/3D Graphics - Effects/2d alpha rotation and scaling realtime for b3d only sry blitz+ :(
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This is a free 2d alpha engine only in 3d mode. It uses multi layered rendering and 3d rectangles (not blitz sprites) I am working on incorperating textures in at the moment. Here is a list of the functions. (NTG stands for Nate the Great) :) DrawNTG UpdateNTG NTGsetblend NTGsetrotation NTGsetscale NTGsetalpha NTGCreateRect NTGinit2dAlpha | |||||
Graphics3D 640,480,0,2 lit = CreateLight(2) MoveEntity lit,0,-101,0 SetBuffer BackBuffer() Global NTGox# Global NTGoz# Global NTGpixelwidth# Global NTGpixelheight# Global NTGinit = False Global NTGplane Global NTGcam Global NTGheight# Global NTGrotation# Global NTGscalex# = 1 Global NTGscaley# = 1 Global NTGalpha# = 1 Global NTGblend = 3 Type NTGsprite Field entity,active End Type NTGinit2dAlpha() ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Type rects Field x#,y#,rot#,rotspeed#,vx#,vy#,lif,ent.NTGsprite End Type rect1.NTGsprite = NTGcreateRect.NTGsprite(40,40) cnt# = 1 timer = MilliSecs() While Not KeyDown(1) Cls NTGsetrotation cnt# NTGsetscale Sin(cnt#),Sin(cnt#) NTGsetalpha Sin(cnt#/2)/2 + .5 DrawNTG rect1.NTGsprite,MouseX(),MouseY() NTGsetscale 1,1 For r.rects = Each rects NTGsetrotation r\rot# NTGsetalpha r\lif/255.0 DrawNTG r\ent.NTGsprite,r\x#,r\y# r\lif = r\lif - 1 r\rot# = r\rot# + r\rotspeed# r\x# = r\x# + r\vx# r\y# = r\y# + r\vy# r\vy# = r\vy# + .07 If r\y# > 480 Then r\vy# = - r\vy#*Rnd#(.5,.9) r\y# = 480 EndIf If r\lif = 0 Then FreeEntity r\ent\entity Delete r\ent.NTGsprite Delete r.rects EndIf Next If MouseDown(1) Then r.rects = New rects r\x# = MouseX() r\y# = MouseY() r\rot# = Rnd(360) r\rotspeed# = Rnd#(-10,10) r\vx# = Rnd#(-3,3) r\vy# = Rnd#(-3,4) r\lif = 255 r\ent.NTGsprite = NTGCreateRect.NTGsprite(40,40,255,0,255) EndIf cnt = cnt + 1 If cnt = 720 Then cnt = 0 UpdateWorld() RenderWorld() UpdateNTG() .stt1 If MilliSecs()-timer > 0 Then .stt x = 1000/(MilliSecs()-timer) If x > 58 Then Goto stt Text 1,1,x Else Goto stt1 EndIf timer = MilliSecs() Flip Wend Flip WaitKey() ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Function DrawNTG(hand.NTGsprite,x#,y#) ShowEntity hand\entity hand\active = True PositionEntity hand\entity,NTGox# + x#*NTGpixelwidth#,0,NTGoz# + y#*NTGpixelheight RotateEntity hand\entity,0,NTGrotation#,0 ScaleEntity hand\entity, NTGscalex#,1,NTGscaley# EntityAlpha hand\entity, NTGalpha# EntityBlend hand\entity, NTGblend End Function Function UpdateNTG() For s.NTGsprite = Each NTGsprite s\active = False HideEntity s\entity Next End Function Function NTGSetBlend(bld) NTGblend = bld End Function Function NTGSetRotation(Rot# = 0) NTGrotation = rot# End Function Function NTGsetscale(sclx# = 1,scly# = 1) NTGscalex# = sclx# NTGscaley# = scly# End Function Function NTGsetalpha(alph# = 1) NTGalpha# = alph# End Function Function NTGCreateRect.NTGsprite(width#,height#,r = 255,g = 255,b = 255) tmp.NTGsprite = New NTGsprite tmp\entity = CreateMesh() tmpsurf = CreateSurface(tmp\entity) width# = width# / 2 height# = height# / 2 v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#)) v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#)) v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#)) v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#)) AddTriangle(tmpsurf,v3,v4,v2) AddTriangle(tmpsurf,v2,v4,v1) EntityColor tmp\entity,r,g,b UpdateNormals tmp\entity HideEntity tmp\entity Return tmp.NTGsprite End Function Function NTGinit2dAlpha(maxrng# = 1000) NTGcam = CreateCamera() NTGinit = True If NTGcam = 0 Then RuntimeError("Camera does not exist.") NTGplane = CreatePlane() TurnEntity NTGplane,-90,0,0 MoveEntity NTGplane,0,-2,0 EntityParent NTGplane,NTGcam EntityAlpha NTGplane,0 EntityPickMode NTGplane,2 CameraRange NTGcam,.01,maxrng# TurnEntity NTGcam,90,0,0 MoveEntity NTGcam,0,0,100 CameraZoom NTGcam,3 CameraClsMode NTGcam,0,1 CameraPick NTGcam,1,1 x1# = PickedX() z1# = PickedZ() NTGheight# = PickedY() CameraPick NTGcam,GraphicsWidth(),GraphicsHeight() x2# = PickedX() z2# = PickedZ() NTGox# = x1# NTGoz# = z1# NTGpixelwidth# = (x2#-x1#)/GraphicsWidth() NTGpixelheight# = (z2#-z1#)/GraphicsHeight() End Function |
Comments
| ||
I guess what I am trying to do here is write something that makes blitz 3d more like blitz max. One thing I didn't mention before is that you can just make a normal camera before you call the init function and it will act like normal on your game. and I think it eliminates the alpha problem between the camera for the 2d fx and the normal camera so your sprites will never look like they are behind the water wich they are obviously not behind. I also have locked it at 58 fps because it keeps it from leaping between 58 and 1000 fps on my machine... it is very unstable. |
| ||
Like FastImage and SpriteCandy :) You anew invent bicycle... |
| ||
yeah... it was just for the learning experience. I got the idea from fastimage because I like to know how every part of my game works... I even made a small 3d engine for blitzbasic when it first came out. I wish I had known about this blog earlier :) P.S. I know it isn't as fast as fastimage but it can handle 200 sprites easily which serves my purpose especially since I have added a load2dsprite function for images. |
| ||
ok I added NTGloadimage now this will be more useful... here is the code. P.S. you have to replace the name of my image with the name of your own image for this to work. after you move the mouse around a little hold the space bar down and move the mouse around some more. Oh... and By the way... I would recomend loading all sprites before the game not ingame because they use resize image which causes major slowdown. If anyone has anything they want me to add please tell me. I love a challenge. |
| ||
Here is the final file... the file that you should include if you use it. for a sample download the following 3 files sorry I couldn't zip them. run the one called test.bb http://files.filefront.com/NTG+imagebb/;12232060;/fileinfo.html http://files.filefront.com/shippng/;12232059;/fileinfo.html http://files.filefront.com/testbb/;12232057;/fileinfo.html |
Code Archives Forum