home *** CD-ROM | disk | FTP | other *** search
- unit Robot_B; { Listing 10-6 }
-
- interface
-
- uses Graph, Mouse, Crt, RobotSeg, Robot_A;
-
- type
-
- RobotArm2Ptr = ^RobotArm2;
-
- RobotArm2 = object( RobotArm )
- NextSeg : RobotArm2Ptr;
- constructor Init( AnchorX, AnchorY,
- ArmLen, HandLen : Integer;
- Position : Degrees;
- RotStat, DispQ : Boolean;
- pToNextSeg : pointer);
- procedure MoveAxial( var i : integer ); virtual;
- procedure MoveTo( APoint : Point; DispQ : boolean );
- procedure ShowLimit; virtual;
- end;
-
- implementation
-
- constructor RobotArm2.Init( AnchorX, AnchorY,
- ArmLen, HandLen : Integer;
- Position : Degrees;
- RotStat, DispQ : Boolean;
- pToNextSeg : pointer );
- begin
- Segment.Init( AnchorX, AnchorY, ArmLen, Position, RotStat );
- NextSeg := pToNextSeg;
- if NextSeg <> nil then
- NextSeg^.Init( BusyEnd.X, BusyEnd.Y, HandLen, 0,
- Round(Position + 90),
- false, true, nil );
- if DispQ = true then
- begin
- if NextSeg <> nil then
- begin
- ShowLimit;
- ShowBase;
- end;
- Show;
- end;
- end;
-
- procedure RobotArm2.MoveAxial( var i : integer );
- var D : real;
- begin
- Hide;
- if NextSeg <> nil then
- NextSeg^.Hide;
- D := Distance( Anchor, BusyEnd );
- if D-i >= Length then
- D := Length+i;
- if (D <= i) and (Orientation > PI) then
- begin
- Orientation := Orientation - PI;
- D := -(D + i);
- i := -i;
- end
- else
- if D <= i then
- begin
- Orientation := Orientation + PI;
- D := -(D + i);
- i := -i;
- end;
- BusyEnd.X := Round(Anchor.X + cos(Orientation)*(D-i));
- BusyEnd.Y := Round(Anchor.Y - sin(Orientation)*(D-i));
- Show;
- if NextSeg <> nil then
- begin
- NextSeg^.MoveAnchor(BusyEnd.X,BusyEnd.Y);
- NextSeg^.Show;
- end;
- end;
-
-
- { this insures that all segments (except the first one) will not have
- the base shown with them }
- procedure RobotArm2.MoveTo( APoint : Point; DispQ : boolean );
- var D : integer;
- RotDir : integer;
- AxDir : integer;
- begin
- RobotArm.MoveTo( APoint, DispQ );
- if NextSeg <> nil then
- NextSeg^.MoveTo(APoint, false);
- ShowLimit;
- end;
-
- procedure RobotArm2.ShowLimit;
- begin
- if NextSeg <> nil then
- begin
- Graph.SetColor( red);
- with Anchor do
- Rectangle( X - Length,
- Y - NextSeg^.Length,
- X + Length,
- Y + NextSeg^.Length );
- Graph.SetColor(white);
- end;
- end;
-
-
- end.