Class: avarcron


API

move_part(Name, Dir, Angle) Purpose: to move a particular body part either vertically or horizontally Parameters: Name - name of the part to be moved Dir - direction in which it is to move Angle - angle for which it is to be rotated move_part_complex(name,x,z) Purpose: to move a body part in x,z direction freely USED for pointing Parameters: name - name of the body part to be moved x - angle along the x-axis z - angle along the z-axis move(X,Y,Z,Angle) Purpose: to move the avatar Parameters: [X,Y,Z] - current x, y, z coordinates Angle - angle in which the avatar should be turned talkingOn() talkingOff() sitDown() standUP() actions(n) possess(object) unpossess(object) getX() getY() getZ()

Source Code

class humanoid:avatar ( origx,origy,origz, # current X,Y,Z coordinate ro, # rotate matrix over whole avatar mv, # traslates matrix " " angle, # angle by which rotation should occur # Instances of following classes h, # head b, # body la, # left arm ra, # right arm lg, # left leg rg, # right leg fint,rarm,larm, # counters used for actions cam_angle, # angle of the avatar vertical_ptr,horizontal_ptr # angles for pointing ) # # move_part(Name, Dir, Angle) # Purpose: to move a particular body part either vertically or horizontally # Parameters: Name - name of the part to be moved # Dir - direction in which it is to move # Angle - angle for which it is to be rotated # method move_part(partName, dir, angle) if partName == "right_arm" then { ra.setAngle(angle, dir) } else if partName == "left_arm" then { la.setAngle(angle, dir) } else if partName == "right_leg" then { rg.setAngle(angle, dir) } else if partName == "left_leg" then { lg.setAngle(angle, dir) } end # # move_part_complex(name,x,z) # Purpose: to move a body part in x,z direction freely # USED for pointing # Parameters: name - name of the body part to be moved # x - angle along the x-axis # z - angle along the z-axis # method move_part_complex(partName,x,y,z) if partName == "right_arm" then { ra.setAngleComplex(x,y,z) } else if partName == "head" then { h.setAngleComplex(x,y,z) } else if partName == "left_arm" then { la.setAngleComplex(x,y,z) } end # # move(X,Y,Z,Angle) # Purpose: to move the avatar # Parameters: [X,Y,Z] - current x, y, z coordinates # Angle - angle in which the avatar should be # turned # method move(posx,posy,posz,angle) degree:=rtod(angle) # convert angle(radian) to degree ro.angle:=degree # update the angle of rotation matrix (e.g. ro) mv.x := posx mv.y := posy mv.z := posz end # # talkingface(newface) # Purpose: to update the face picture with a new one # Parameter: newface - name of the new face picture file # method talkingOn() h.talkingOn() end method talkingOff() h.talkingOff() end # # initializer # method initialize(n) parser(n) end # # setup() # Purpose: to set up each part of avatar by instantiating # the body part # method setup(x,y,z) # Setting up: origx:=x;origy:=y;origz:=z # Current coord. fint:=0;rarm:=0;larm:=0 # counters for parts cam_angle:=0 # angle of the avatar vertical_ptr:=0;horizontal_ptr:=0 # angles for pointing h := head() # head and neck b := body() # body la := arm() # left arm ra := arm() # right arm lg := leg() # left leg rg := leg() # right leg render() end # # render() # Purpose: to render graphics of each part thus a whole # avatar # method render() PushMatrix() Scale(xsize,height,zsize) # size the avatar mv:=Translate(origx,origy,origz) # move the avatar ro:=Rotate(0,0,1,0) # and turn it h.render(face,color,hdchoice) # head and neck b.render(scolor,name,sex) # body la.render("l",color,scolor) # left arm and shoulder ra.render("r",color,scolor) # right arm and shoulder lg.render("l",pcolor,shcolor) # left leg rg.render("r",pcolor,shcolor) # right leg PopMatrix() end # # robot () # Purpose: to make an avatar of its own mind. When called, # this avatar does his own thing when any keyboard # action takes place (i.e. pressing down keys). # This is a start-up code for you to create something # like an artificial intelligent agent (i.e.Cyber Frank) # method robot() end # # actions() # method actions(type) case type of { # # move FORWARD # 1: { origz:=origz+cos(cam_angle)*0.1 origx:=origx+sin(cam_angle)*0.1 move(origx, origy, origz, cam_angle) if fint < 3 then { if rarm = 0 then { move_part("right_arm", "fb", 10)} move_part("left_leg", "fb", 10) if larm = 0 then { move_part("left_arm", "fb", -10)} move_part("right_leg", "fb", -10) fint:=fint+1 } else { if rarm = 0 then { move_part("right_arm", "fb", -10)} move_part("left_leg", "fb", -10) if larm = 0 then { move_part("left_arm", "fb", 10)} move_part("right_leg", "fb", 10) fint:=fint+1 if fint = 6 then { fint:=0 }} Refresh() } # # move BACKWARD - moon-walk style # 2: { origz:=origz-cos(cam_angle)*0.1 origx:=origx-sin(cam_angle)*0.1 move(origx, origy, origz, cam_angle) if fint < 3 then { if rarm = 0 then { move_part("right_arm", "fb", 10)} move_part("left_leg", "fb", 10) if larm = 0 then { move_part("left_arm", "fb", -10)} move_part("right_leg", "fb", -10) fint:=fint+1 } else { if rarm = 0 then { move_part("right_arm", "fb", -10)} move_part("left_leg", "fb", -10) if larm = 0 then { move_part("left_arm", "fb", 10)} move_part("right_leg", "fb", 10) fint:=fint+1 if fint = 6 then { fint:=0 }} Refresh() } # # move SIDEWAY-right # 3: { origx:=origx-sin(1.571-cam_angle)*0.1 origz:=origz+cos(1.571-cam_angle)*0.1 if fint < 3 then { move_part("right_leg", "s", -10) Refresh() move(origx, origy, origz, cam_angle) Refresh() fint:=fint+1} else { move_part("right_leg", "s", 0) fint:=fint+1 if fint = 6 then { fint:=0 }} } # # move SIDEWAY-left # 4: { origx:=origx+sin(1.571-cam_angle)*0.1 origz:=origz-cos(1.571-cam_angle)*0.1 if fint < 3 then { move_part("left_leg", "s", 10) Refresh() move(origx, origy, origz, cam_angle) Refresh() fint:=fint+1} else { move_part("left_leg", "s", 0) fint:=fint+1 if fint = 6 then { fint:=0 }} } # # turn LEFT # 5: { cam_angle:=cam_angle+0.05 if abs(cam_angle) > 2 * &pi then cam_angle := 0.0 move(origx, origy,origz, cam_angle) } # # turn RIGHT # 6: { cam_angle:=cam_angle-0.05 if abs(cam_angle) > 2 * &pi then cam_angle := 0.0 move(origx, origy,origz, cam_angle) } # # Raising Right Arm # 7: { if rarm = 0 then { rarm:=1 move_part("right_arm", "fb", 180)} else { rarm:=0 move_part("right_arm", "fb", 0)} } # # Raising Left Arm # 8: { if larm = 0 then { larm:=1 move_part("left_arm", "fb", 180)} else { larm:=0 move_part("left_arm", "fb", 0)} } # # back to NORMAL # 9 : { move_part("right_arm", "fb", 0) move_part("left_leg", "fb", 0) move_part("left_arm", "fb", 0) move_part("right_leg", "fb", 0) } # # pointing # 10: { # Everything goes back to normal move_part("right_arm", "fb", 0) move_part("left_leg", "fb", 0) move_part("left_arm", "fb", 0) move_part("right_leg", "fb", 0) # BRINGS THE RIGHT ARM UP vertical_ptr:=270 horizontal_ptr:=0 move_part("right_arm", "fb", 270) Refresh() } # # talking-on # 11: { talkingOn() } # # talking-off # 12: { talkingOff() } 13: { if vertical_ptr > 210 then vertical_ptr:=vertical_ptr-1 move_part_complex("right_arm", vertical_ptr, 0, horizontal_ptr) move_part_complex("head", vertical_ptr-270, horizontal_ptr, 0) } 14: { if vertical_ptr < 330 then vertical_ptr:=vertical_ptr+1 move_part_complex("right_arm", vertical_ptr, 0, horizontal_ptr) move_part_complex("head", vertical_ptr-270, horizontal_ptr, 0) } 15: { if horizontal_ptr > -30 then horizontal_ptr:=horizontal_ptr-1 move_part_complex("right_arm", vertical_ptr, 0, horizontal_ptr) move_part_complex("head", vertical_ptr-270, horizontal_ptr, 0) } 16: { if horizontal_ptr < 30 then horizontal_ptr:=horizontal_ptr+1 move_part_complex("right_arm", vertical_ptr, 0, horizontal_ptr) move_part_complex("head", vertical_ptr-270, horizontal_ptr, 0) } 17: { move_part_complex("right_arm",0,0,0) move_part_complex("head",0,0,0) } } end end