Ooops
January 15, 2021, 05:46:18 PM

Author Topic: [bb] Get 2D entity Size by Rob [ 1+ years ago ]  (Read 1257 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Get 2D entity Size by Rob [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Get 2D entity Size
Author : Rob
Posted : 1+ years ago

Description : Speed up by using a polygon box proxy (only 8 checks verses num verts in mesh).

Code :
Code: BlitzBasic
  1. ; Get 2D entity size! Rob Cummings
  2. ;
  3. ; perfect bounding box detection for entities - ideal for
  4. ; huds, cameras, and more! targetting squares... endless uses!
  5.  
  6.  
  7.  
  8. Global mxspd#,myspd#,campitch#,vx#,vz#,temp#
  9. Global camera
  10.  
  11. Graphics3D 800,600,16,2
  12. SetBuffer BackBuffer()
  13.  
  14. camera=CreateCamera()
  15. PositionEntity camera,0,500,0
  16. light=CreateLight()
  17. RotateEntity light,45,45,0
  18.  
  19. ; setup a small world to play within
  20. plane=CreatePlane()
  21. EntityColor plane,100,100,200
  22. For i=0 To 10
  23.         temp=CreateSphere(8)
  24.         ScaleEntity temp,Rnd(-100,100),Rnd(-100,100),Rnd(-100,100)
  25.         PositionEntity temp,Rnd(-500,500),Rnd(500),Rnd(-500,500)
  26.         EntityPickMode temp,2
  27. Next   
  28.  
  29. Color 0,255,0
  30.  
  31. ;small test app
  32. While Not KeyHit(1)
  33.         picked=CameraPick(camera,GraphicsWidth()/2,GraphicsHeight()/2)
  34.         freelook
  35.         UpdateWorld
  36.         RenderWorld
  37.         targetbox(picked)
  38.         Flip
  39. Wend
  40. End
  41.  
  42.  
  43. ;-------------------------------------------------------
  44.  
  45. Function targetbox(ent)
  46.         If ent=0 Return 0
  47.         If EntityInView(ent,camera)=0 Return 0
  48.         CameraProject camera,EntityX(ent),EntityY(ent),EntityZ(ent)
  49.         leftmost#=ProjectedX()
  50.         rightmost#=ProjectedX()
  51.         topmost#=ProjectedY()
  52.         bottommost#=ProjectedY()
  53.         For i=1 To CountSurfaces(ent)
  54.                 s=GetSurface(ent,1)
  55.                 For v=0 To CountVertices(s)-1
  56.                         TFormPoint VertexX(s,v),VertexY(s,v),VertexZ(s,v),ent,0
  57.                         CameraProject camera,TFormedX(),TFormedY(),TFormedZ()
  58.                         If ProjectedX()<leftmost leftmost=ProjectedX()
  59.                         If ProjectedX()>rightmost rightmost=ProjectedX()
  60.                         If ProjectedY()<topmost topmost=ProjectedY()
  61.                         If ProjectedY()>bottommost bottommost=ProjectedY()
  62.                 Next
  63.         Next
  64.         Rect leftmost,topmost,rightmost-leftmost,bottommost-topmost,0
  65. End Function
  66.  
  67. ;-------------------------------------------------------
  68.  
  69. Function freelook()
  70.         mxspd#=MouseXSpeed()*0.4
  71.         myspd#=MouseYSpeed()*0.4
  72.         MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  73.  
  74.         campitch=campitch+myspd
  75.         If campitch<-85 Then campitch=-85
  76.         If campitch>85 Then campitch=85
  77.         RotateEntity camera,campitch,EntityYaw(camera)-mxspd,0
  78.        
  79.         If KeyDown(203) Then vx=vx-.1
  80.         If KeyDown(205) Then vx=vx+.1  
  81.         If KeyDown(200) Then vz=vz+.1
  82.         If KeyDown(208) Then vz=vz-.1
  83.         vx=vx/1.05
  84.         vz=vz/1.05
  85.         MoveEntity camera,vx,vy,vz
  86. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal