interlocking meshes

Blitz3D Forums/Blitz3D Beginners Area/interlocking meshes

Chad(Posted 2005) [#1]
I don't exactly know the right words for this, but I'll let the pictures do the talking. Basically I have my gun model in, and the beginning of my city, however, somethings messed up, the building might look 6 feet away from me, but when I point the gun in that direction, it goes through the object. I know there's not a lot I can do to help that, except I want it to happen at a closer range, what should I do?





Thanks,
Chad


morduun(Posted 2005) [#2]
Tinker with the EntityOrder command:
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=entityorder&ref=goto


Ross C(Posted 2005) [#3]
Or, do multiple renders with the hand and gun.


Beaker(Posted 2005) [#4]
Don't use EntityOrder (it can screw up your model if made from more than one part), use multiple renders.


morduun(Posted 2005) [#5]
Ahhhh true @ Beaks. I reckon you could probably get away with using a pair of entityorder commands, setting the arm to draw after the gun, but the multiple render passes are probably more solid.


Chad(Posted 2005) [#6]
Ok, your going have to explain to me how I do multiple renders.. I'm lost


Zethrax(Posted 2005) [#7]
Create two cameras, one for the main render and a second one to render the hand and gun (plus possibly your heads-up-display if you're using a 3d HUD).

Position the second camera setup somewhere where it won't interfere with your main world area (I put mine 500 units below the main world area), and give it a max entity distance value that clips as close to the second camera as you can get to prevent your main world from being rendered by the second camera.

Give the second camera an entityorder of -1 to force it to render last (this won't stuff up the z-ordering for the models the way it will if you use entityorder directly on models) and use 'CameraClsMode <second camera>, False, True' to stop the second camera from clearing the background where your main world will be rendered.

eg.

Function CreateHUD()
; -- Setup HUD camera
HUD_camera = CreateCamera()
PositionEntity HUD_camera, 0.0, -500.0, 0.0
CameraRange HUD_camera, 0.2, 5.0
CameraZoom HUD_camera, 1.6
CameraClsMode HUD_camera, False, True
EntityOrder HUD_camera, -1
End Function

You may also want to consider making your hand and gun model smaller by using ScaleMesh or ScaleEntity, and move them closer to the camera, if they're poking through a wall that's six feet away. Personally though, I have some doubts about the perspective that Blitz3D uses. Everything generally looks half the size it should.

To get correct lighting on the hand and gun models, parent them to the second camera and rotate the second camera to match the rotation of your game character. If this interferes with the lighting on any 3D HUD graphics you may have, you may need a third camera for the HUD graphics.


--


Chad(Posted 2005) [#8]
Thanks for the descriptive writing.. I'll try it and let you know how it goes.


AdrianT(Posted 2005) [#9]
chad, don't know if your using 3dsmax at all, probably not.. but if you are B3d pipeline lets you set up a lot of these types of things within 3dsmax with simple plugin GUI interfaces. The render part of pipeline allows you to set up cameras, draw order and link to camera position/rotation etc automaticly.

If you have 3dsmax I'd recommend playing with that. If not then the other methods are sound, just not as straight forward. Allthough saying that you will learn something doing it the hard way too (as always)


Chad(Posted 2005) [#10]
No, I can't afford 3d max.. I wish but way to expensive for me.. And I'm not the type that does cracks or warez or whatever else they call it. When I do something, I want it to be original and legal, so then I don't have bad feelings for what I did if I did do something wrong.

Unfortunately, I spent a good half hour to an hour trying to get the double render to work and I couldn't get it. Here's my code if you guys can try to get it working..

Graphics3D 800,600, 0, 1					
SetBuffer BackBuffer()						

Const PLAYER_COL= 1
Const LEVEL_COL = 2
Const ENEMY_COL = 3
Const BULLET_COL= 4

sky = CreateSkyBox()

Type bullettype							
  Field entityhandle						
End Type

Type badguytype							;set up the badguy type
  Field entityhandle						;will contain the handle of the badguys mesh
  Field state							;will contain the state that the badguy is currently in
End Type

light = CreateLight()						;Create a light to see
RotateEntity light, 30, 30, 0					;angle the light
player = CreatePivot()						;A simple pivot is all we need to represent the player
camera = CreateCamera(player)					;create the camera and attach it to the player
level = LoadMesh("town.3ds")					;load in the level mesh



weapon1 = LoadMesh("glock.b3d", camera2)			;load in the weapon mesh and attach it to the camera
;ScaleEntity = weapon1 .5,.5,.5
;weapon1 = CreateCylinder(32, 1, camera):RotateMesh weapon1, 90, 0, 0:ScaleEntity weapon1, .05, .05, .2:EntityColor weapon1, 50, 50, 50
;bulletmesh = LoadMesh("bullet.b3d")				;load in a bullet mesh (this will be a template mesh)
bulletmesh = CreateCone():RotateMesh bulletmesh,90,0,0:ScaleEntity bulletmesh,.1,.1,.1
EntityType bulletmesh, BULLET_COL				;set up collision type for the bullet
EntityRadius bulletmesh, .01					;set up collision radius for the bullet
;badguymesh = LoadMesh("badguy.b3d")				;load in badguy mesh (this will also be a template mesh)
badguymesh = CreateCylinder():ScaleEntity badguymesh,.3,.95,.125;.6 wide, 1.9 tall, .25 thick
EntityType badguymesh, ENEMY_COL				;set up collision type for the badguy
EntityRadius badguymesh, .3, .95	 			;set up collision radius for the badguy (1.9 meters tall, .6 meters wide)
HideEntity bulletmesh						;hide the template meshes since they are not actual objects
HideEntity badguymesh						;this will also exclude them from collisions

For iter = 1 To 10						;create some badguys from the template badguy mesh
  badguy.badguytype = New badguytype				;create a new badguy
  badguy\entityhandle = CopyEntity(badguymesh)			;give him a mesh
  badguy\state = Rnd(1, 2) 					;1=Guard 2=Search 3=Evade 4=Attack 5=Dead
Next

MoveEntity camera2, 0, .9, 0					;move camera up to height of players head (also moves weapon)
MoveEntity weapon1, .1, -.15, .1				;move weapon to bottom right of camera
MoveEntity player, 20, 3, -20					;move the player to the starting position

For badguy = Each badguytype					;iterate through all of the badguys
  PositionEntity badguy\entityhandle, Rnd(100)-50, .95, Rnd(100)-50	;move the badguy to a random starting position
Next

EntityType player, PLAYER_COL					;set up collision type for the player
EntityRadius player, .3, 2					;set up the players collision radius (1.9 meters tall, .6 meters wide)
EntityType level, LEVEL_COL					;set up collision type for the level
Collisions PLAYER_COL, LEVEL_COL, 2, 2				;player to level
Collisions PLAYER_COL, ENEMY_COL, 1, 2				;player to badguy
Collisions ENEMY_COL, LEVEL_COL, 2, 2				;badguy to level
Collisions BULLET_COL, LEVEL_COL, 2, 1				;bullet to level
Collisions BULLET_COL, ENEMY_COL, 2, 1				;bullet to badguy


While Not KeyHit(1) 						;ESC key

  wkey = KeyDown(17)						;collect user input
  skey = KeyDown(31)						;It's a good practice to collect these inputs only once
  akey = KeyDown(30)						;per loop.  This will prevent odd behaviors from happening,
  dkey = KeyDown(32)						;for instance if the state of a key changes between multiple
  spacekey = KeyDown(57)	
  mouse1 = MouseHit(1)						;checks of that key while still in the same loop.

  If wkey Then MoveEntity player, 0, 0, .1			;Forward - w key
  If skey Then MoveEntity player, 0, 0, -.1			;Back    - s key
  If akey Then MoveEntity player, -.1, 0, 0			;Left    - a key
  If dkey Then MoveEntity player, .1, 0, 0			;Right   - d key
  If spacekey Then MoveEntity player, 0, .8, 0

  TurnEntity player, 0, -MouseXSpeed()/5.0, 0			
  TurnEntity camera, MouseYSpeed()/5.0, 0, 0			
  If EntityPitch(camera) < -45					;don't allow camera to look below -45 degrees
    RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera)
  EndIf 
  If EntityPitch(camera) > 45					;don't allow camera to look above 45 degrees
    RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera)
  EndIf
  MoveMouse GraphicsWidth()/2, GraphicsHeight()/2		;reset mouse position to middle of screen

  TranslateEntity player, 0, -.1, 0				;simple gravity

  If mouse1							;check if left mouse button was pressed
    bullet.bullettype = New bullettype				;create a bullet
    bullet\entityhandle = CopyEntity(bulletmesh)		;create the bullet mesh
    PositionEntity bullet\entityhandle, EntityX(weapon1, 1), EntityY(weapon1, 1), EntityZ(weapon1, 1)	;place the bullet at the guns position
    RotateEntity bullet\entityhandle, EntityPitch(weapon1, 1), EntityYaw(weapon1, 1), EntityRoll(weapon1, 1);orientate the bullet with the gun
    ResetEntity bullet\entityhandle				;otherwise bullet could hit enemy while moving from 0,0,0 to current position
  EndIf

  For thisbullet.bullettype = Each bullettype			;iterate through all of the bullets
    MoveEntity thisbullet\entityhandle, 0, 0, 2			;move the bullet forward along the bullets Z axis
    If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000		;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000	;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000	;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    EndIf
  Next

  UpdateWorld							;figures out collisions

  For thisbullet = Each bullettype				;iterate through all of the bullets
    If CountCollisions(thisbullet\entityhandle) > 0		;check if bullet collided with something
      enemyhit = EntityCollided(thisbullet\entityhandle, 3)	;note which enemy bullet collided with (if any)
      If enemyhit > 0						;enemyhit contains entity handle of enemy that was hit
        For thisbadguy.badguytype = Each badguytype		;iterate through all of the badguys
          If enemyhit = thisbadguy\entityhandle			;check if the enemy hit = this badguy
            If thisbadguy\state <> 5				;check if badguy is alive
              thisbadguy\state = 5 ;dead			;make him dead
              RotateEntity thisbadguy\entityhandle, 90, 0, 0	;make him horizontal
              EntityType thisbadguy\entityhandle, 0		;turn off collisions for this badguy
              TranslateEntity thisbadguy\entityhandle, 0, -.9, 0;set him on the ground
              Exit						;exits the badguy For-Next loop (no need to check rest of badguys)
            EndIf
          EndIf
        Next
      EndIf
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    EndIf
  Next

  RenderWorld							;draws the 3d scene
  Flip								;displays the scene to the screen
Wend								;loop until the ESC key is pressed

Function CreateCamera(weapon1) 
; -- Setup HUD camera 
camera2 = CreateCamera(weapon1) 
PositionEntity camera2, 0.0, -500.0, 0.0 
CameraRange camera2, 0.9, 5.0 
CameraZoom camera2, 1.6 
CameraClsMode camera2, False, True 
EntityOrder camera2, -1 
End Function 

Function CreateSkyBox()
    mesh = CreateMesh()

    ;front face
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\front6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,-1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,-1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;left face
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\left6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,-1,0,0
    AddVertex surface,+1,+1,+1,1,0
    AddVertex surface,+1,-1,+1,1,1
    AddVertex surface,+1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;back face
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\back6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,-1,+1,+1,1,0
    AddVertex surface,-1,-1,+1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
 
    ;right face
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\right6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,0
    AddVertex surface,-1,+1,-1,1,0
    AddVertex surface,-1,-1,-1,1,1
    AddVertex surface,-1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;top face
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\top6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,1
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,-1,+1,-1,1,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
   
    ;bottom face 
    brush = LoadBrush("C:\Documents and Settings\user\Desktop\Soldiers Helmet\Skybox\bottom6.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,-1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddVertex surface,-1,-1,+1,0,0
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
    
    ScaleMesh mesh,200,200,200
    FlipMesh mesh
    EntityFX mesh,1 ; make fullbright
    Return mesh
End Function