# camera class $include "keysyms.icn" # $include "C:\Program Files\Unicon\ipl\gincl\keysyms.icn" link printf # link graphics class Camera( world, posx, posy, posz, lookx, looky, lookz, cam_lx, cam_lz, cam_angle, framefactor, stepdelta, lasttimeofday) method speed_control() # control frame rate thistimeofday := gettimeofday() thistimeofday := thistimeofday.sec * 1000 + thistimeofday.usec / 1000 if (delta := thistimeofday - \lasttimeofday) < framefactor then { delay(framefactor - delta) } lasttimeofday := thistimeofday end # method speed_control method cam_move(dir) local deltax, deltaz deltax := dir * cam_lx deltaz := dir * cam_lz # write ( " cam move cur_room dir deltax deltaz ",world.curr_room.name," ",dir," ",deltax," ",deltaz) if world.curr_room.disallows(posx+deltax,posz+deltaz) then { deltax := 0 if world.curr_room.disallows(posx+deltax,posz+deltaz) then { deltaz := 0; deltax := dir*cam_lx if world.curr_room.disallows(posx+deltax,posz+deltaz) then { # write ( " cam move fails dir deltax deltaz ",dir," ",deltax," ",deltaz) fail } } } #calculate new position posx +:= deltax posz +:= deltaz # write ( " cam move succeeds dir deltax deltaz ",dir," ",deltax," ",deltaz) # write ( " " ) #update look at spot lookx := posx + cam_lx lookz := posz + cam_lz end # Orient the camera method cam_orient_yaxis(turn) #update camera angle cam_angle +:= turn if abs(cam_angle) > 2 * &pi then cam_angle := 0.0 cam_lx := sin(cam_angle) cam_lz := -cos(cam_angle) lookx := posx + cam_lx lookz := posz + cam_lz end # set initial paramerters or reset if lost in space method reset() posx := world.posx posy := world.posy posz := world.posz lookx := world.lookx looky := world.looky lookz := world.lookz cam_lx := world.cam_lx cam_lz := world.cam_lz cam_angle := world.cam_angle framefactor := world.framefactor stepdelta := world.stepdelta end initially(worl) world := worl reset() # is it legal to call methods in a constructor??? this works. lasttimeofday := &null end # ====== end of active code - anything below is for reference ================= # ====== end of file ==========================================================