Posted: 15th Jan 2004 21:33
This is just some code I made for a friend of mine who wanted to make a FPS with bulletholes. I didn't use the intersect object command, but I am wondering if it's possible with that command considering you don't know a thing about the poly you intersect with, or do you? (I mean how do you rotate the bullethole plain properly without that info). I though that this might be useful to someone, so I posted it here. Plz tell me if you know a better method, I'd like to know too.

Use the mouse to move around and press space (not hold) to shoot.

http://www.dannywartnaby.co.uk/rgt/attachments/bulletholes.rar
or
http://www.dannywartnaby.co.uk/rgt/attachments/bulletholes.zip

Kevil
Posted: 16th Jan 2004 1:39
Thanks Kevil, Im sure this will resolve many many many questions to come

Thanks for all your great coding

RPGamer
Posted: 16th Jan 2004 21:20
d-man wrote that a long time ago, a method, which is using the intersect object command...

+ Code Snippet
sync on : sync rate 0
set display mode 1024,768,16
hide mouse
 
ink RGB(0,255,0),0
line 0,12,25,12
line 12,0,12,25
 
get image 1,0,0,25,25
 
cls RGB(192,192,192)
 
ink 0,0
for y=0 to 15
  line 0,17*y,256,17*y
  for x=0 to 9
    if y/2.0=y/2 then line 25.6*x,17*y,25.6*x,17*(y+1) else line 25.6*x+12.8,17*y,25.6*x+12.8,17*(y+1)
  next x
next y
 
get image 2,0,0,256,256
 
cls
 
ink 1,0
 
for r=1 to 3
  circle 4,4,r
next r
 
get image 3,0,0,9,9
 
make object box 1,5,5,0.1
texture object 1,2
 
make object sphere 2,2
hide object 2
 
make object plain 3,0.1,0.1
texture object 3,3
set object transparency 3,1
 
time=timer()
r#=3000
obj=4
 
autocam off
 
do
  dt#=(timer()-time)/1000.0
  time=timer()
  yrotate camera wrapvalue(camera angle y()+mousemovex())
  xrotate camera wrapvalue(camera angle x()+mousemovey())
  if upkey()=1 then move camera 50*dt#
  if downkey()=1 then move camera -50*dt#
  sprite 1,screen width()/2-12,screen height()/2-12,1
  if mouseclick()=1
    mmcoord(screen width()/2,screen height()/2,r#,60)
    dist#=intersect object(1,camera position x(),camera position y(),camera position z(),object position x(2),object position y(2),object position z(2))
    if dist#>0
      i#=dist#/r#
      x#=camera position x()+(object position x(2)-camera position x())*i#
      y#=camera position y()+(object position y(2)-camera position y())*i#
      z#=camera position z()+(object position z(2)-camera position z())*i#
      clone object obj,3
      if object position x(1)<x# then inc x#,0.0001 else dec x#,0.0001
      if object position y(1)<y# then inc y#,0.0001 else dec y#,0.0001
      if object position z(1)<z# then inc z#,0.0001 else dec z#,0.0001
      position object obj,x#,y#,z#
      rotate object obj,object angle x(1),object angle y(1),object angle z(1)
      inc obj
    endif
  endif
  sync
loop
 
 
function mmcoord(scrx#,scry#,r#,FOV#)
 
  ax#=camera angle x()
  ay#=camera angle y()
  scrw#=screen width()
  scrh#=screen height()
 
  hmax# = r#*tan(FOV#/2)
  mh#   = (((scrh#/2-scry#)*2)/scrh#)*hmax#
  wmax# = r#*scrw#/scrh#*tan(FOV#/2)
  mw#   = (((scrx#-scrw#/2)*2)/scrw#)*wmax#
 
  cl#   = r#*cos(ax#)
  ch#   = -r#*sin(ax#)
 
  sl#   = mh#*cos(90-ax#)
  sh#   = mh#*sin(90-ax#)
 
  ox#    = camera position x() + (cl#+sl#)*sin(ay#) + mw#*cos(ay#)
  oy#    = camera position y() + (ch#+sh#)
  oz#    = camera position z() + (cl#+sl#)*cos(ay#) - mw#*sin(ay#)
 
  position object 2,ox#,oy#,oz#
 
endfunction
Posted: 16th Jan 2004 22:23
That's not really the same. That code will only work on a box like that. If you use it on anything else, the holes won't be rotated correctly. (try changing the box into a sphere)
That's exactly why I didn't use the intersect object command.

Kevil
Posted: 17th Jan 2004 11:45
great stuff! although i did find that when i put the hole size up to 10, firing two bullets in nearly the same place causes some dodgy flickering effects
Posted: 17th Jan 2004 13:27
@Kevil

That's some impressive but seriously obfuscated code.
Posted: 17th Jan 2004 23:42
Obfuscated? Whats that mean o_o
Posted: 18th Jan 2004 0:02
very very cool, kinda complicated but goog job
could you make a function of it? would be easier to use then
Posted: 18th Jan 2004 2:50
Yeah, I think I could, when I got the time. (which is not this week)

And the code only looks complicated. It's your basic line/plane intersection and point in triangle code. My own version of the intersect object command. Only now I know which poly has been hit and I have the normal data of that poly, which makes it easy to place bullethole planes.

Kevil
Posted: 18th Jan 2004 14:23
I know how you did it, not because of your code but I tought of doing it this kind of way to, just never actually tried it.