Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Creates an "Upright" leg style for creatures whose legs should
reach out to their fully extended length.
  • Loading branch information
Christopher Lane Hinson committed Mar 9, 2011
1 parent 7254257 commit 96a19fa
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
6 changes: 3 additions & 3 deletions roguestar-gl/src/AnimationCreatures.hs
Expand Up @@ -54,7 +54,7 @@ recreantAvatar = genericCreatureAvatar $ floatBobbing 0.25 0.4 $ proc () ->
androsynthAvatar :: (FRPModel m) => CreatureAvatar e m
androsynthAvatar = genericCreatureAvatar $ proc () ->
do libraryA -< (scene_layer_local,Androsynth)
bothLegs ThinLimb ThinLimb (Vector3D 0 0 1) (Point3D (0.07) 0.5 (-0.08)) 0.7 (Point3D 0.07 0 0.0) -< ()
bothLegs ThinLimb ThinLimb Upright (Vector3D 0 0 1) (Point3D (0.07) 0.5 (-0.08)) 0.55 (Point3D 0.07 0 0.0) -< ()
wield_point <- exportCoordinateSystem <<< arr (joint_arm_hand . snd) <<<
bothArms ThinLimb ThinLimb (Vector3D (1.0) (-1.0) (-1.0)) (Point3D 0.05 0.65 0.0) 0.45 (Point3D 0.15 0.34 0.1) -< ()
returnA -< CreatureThreadOutput {
Expand Down Expand Up @@ -88,7 +88,7 @@ caduceatorAvatar = genericCreatureAvatar $ proc () ->
reptilianAvatar :: (FRPModel m) => CreatureAvatar e m
reptilianAvatar = genericCreatureAvatar $ proc () ->
do libraryA -< (scene_layer_local,Reptilian)
bothLegs ReptilianLegUpper ReptilianLegLower (Vector3D 0 0 1) (Point3D (0.05) 0.25 (-0.1)) 0.29 (Point3D 0.07 0 0.0) -< ()
bothLegs ReptilianLegUpper ReptilianLegLower Upright (Vector3D 0 0 1) (Point3D (0.05) 0.25 (-0.1)) 0.29 (Point3D 0.07 0 0.0) -< ()
wield_point <- exportCoordinateSystem <<< arr (joint_arm_hand . snd) <<<
bothArms ReptilianArmUpper ReptilianArmLower (Vector3D 1.0 0.0 1.0) (Point3D (0.05) 0.35 (-0.1)) 0.25 (Point3D 0.07 0.25 0.12) -< ()
returnA -< CreatureThreadOutput {
Expand All @@ -104,7 +104,7 @@ hellionAvatar = genericCreatureAvatar $ proc () ->
(Point3D 0.06 0.55 0)
1.2
(Point3D 0.2 0.8 0.05) -< ()
bothLegs HellionAppendage HellionAppendage (Vector3D 0.5 0 (-1)) (Point3D 0.05 0.55 0) 0.8 (Point3D 0.05 0 0) -< ()
bothLegs HellionAppendage HellionAppendage Upright (Vector3D 0.5 0 (-1)) (Point3D 0.05 0.55 0) 0.8 (Point3D 0.05 0 0) -< ()
wield_point <- exportCoordinateSystem <<< arr (joint_arm_hand . snd) <<<
bothArms HellionAppendage HellionAppendage (Vector3D 1.0 0.0 (-0.5)) (Point3D 0.1 0.6 0) 0.4 (Point3D 0.3 0.25 0.3) -< ()
returnA -< CreatureThreadOutput {
Expand Down
8 changes: 6 additions & 2 deletions roguestar-gl/src/Limbs.hs
Expand Up @@ -134,25 +134,29 @@ bothLegs :: (FRPModel m,
LibraryModelSource lm2) =>
lm1 ->
lm2 ->
LegStyle ->
Vector3D ->
Point3D ->
RSdouble ->
Point3D ->
FRP e m () ()
bothLegs leg_upper
leg_lower
style
bend_vector
hip_anchor
maximum_length
foot_rest = proc () ->
do legs [leg bend_vector
do legs [leg style
bend_vector
hip_anchor
maximum_length
foot_rest
(libraryJointAnimation maximum_length
(toLibraryModel leg_upper)
(toLibraryModel leg_lower)),
leg (swapX bend_vector)
leg style
(swapX bend_vector)
(swapX hip_anchor)
maximum_length
(swapX foot_rest)
Expand Down
45 changes: 45 additions & 0 deletions roguestar-gl/src/Models/Hellion.hs
@@ -0,0 +1,45 @@
module Models.Hellion
(hellion,
hellion_appendage,
hellion_eye)
where

import RSAGL.Math
import RSAGL.Modeling
import Quality
import Models.Materials
import RSAGL.Math.CurveExtras
import RSAGL.Color.RSAGLColors

hellion :: Quality -> Modeling ()
hellion _ = model $
do sphere (Point3D 0 0.6 0) 0.1
hellion_skin

hellion_appendage :: Quality -> Modeling ()
hellion_appendage _ = model $ rotate (Vector3D 1 0 0) (fromDegrees 90) $
do sor $ linearInterpolation $
points2d [(0 ,0),
(0.02,0.25),
(0.03,0.5),
(0.02,0.75),
(0.0,1.0)]
hellion_skin

hellion_eye :: Quality -> Modeling ()
hellion_eye _ = model $
do model $
do openCone (Point3D 0 0 (-0.1),0) (Point3D 0 0 0.1, 0.1)
hellion_skin
model $
do hemisphere (Point3D 0 0 0.1) (Vector3D 0 0 1.0) 0.1
material $ pigment $ pure white
model $
do perspectiveSphere (Point3D 0 0 0.1) 0.103 (Point3D 0 0 0.25)
material $ pigment $ pure blue -- TODO: vary the eye color! Beware the rare red-eyed hellion!
twoSided True
model $
do perspectiveSphere(Point3D 0 0 0.1) 0.106 (Point3D 0 0 0.22)
material $ pigment $ pure black
twoSided True

3 changes: 2 additions & 1 deletion rsagl-demos/ModelView.hs
Expand Up @@ -75,7 +75,8 @@ walking_orb_animation qo_orb qo_glow_orb qo_orb_upper_leg qo_orb_lower_leg =
sceneObject $ return qo_orb_lower_leg)
orb_legs = legs $
rotationGroup (Vector3D 0 1 0) 25 $
leg (Vector3D 0 1 1)
leg Insectoid
(Vector3D 0 1 1)
(Point3D 0 0.5 0.5)
2
(Point3D 0 0 1.8) $
Expand Down
23 changes: 17 additions & 6 deletions rsagl/RSAGL/Animation/InverseKinematics.hs
Expand Up @@ -5,6 +5,7 @@

module RSAGL.Animation.InverseKinematics
(leg,
LegStyle(..),
Leg,
jointAnimation,
legs,
Expand Down Expand Up @@ -35,7 +36,7 @@ import RSAGL.Math.Types

-- foot works by reading two odometers, one for forward movement and another for
-- sideways movement. This is like spinning the wheel by a magical odometer
-- instead of spinning the odometer by the wheel.
-- instead of spinning the odometer by the wheel. (INVERSE kinematics!)
--
-- 'pre_stepage' is the total odometer reading for all travel in both
-- directions. 'stepage_adjustment' is the amount by which we need to increase
Expand All @@ -49,10 +50,10 @@ foot :: (CoordinateSystemClass s,s ~ StateOf m) =>
FRP e m Bool (CSN Point3D,Bool)
foot forward_radius side_radius lift_radius = proc emergency_footdown ->
-- total forward travel of the foot:
do fwd_total_stepage <- arr (* recip forward_radius) <<<
do fwd_total_stepage <- arr (* recip (2*forward_radius)) <<<
odometer root_coordinate_system (Vector3D 0 0 1) -< ()
-- total sideways travel of the foot
side_total_stepage <- arr (* recip side_radius) <<<
side_total_stepage <- arr (* recip (2*side_radius)) <<<
odometer root_coordinate_system (Vector3D 1 0 0) -< ()
-- total travel of the foot
let pre_stepage = sqrt $ fwd_total_stepage^2 + side_total_stepage^2
Expand All @@ -72,7 +73,7 @@ foot forward_radius side_radius lift_radius = proc emergency_footdown ->
let stepage_offset = if cyclic_stepage > 1
then 1.5 - cyclic_stepage
else cyclic_stepage - 0.5
let step_vector = scale (Vector3D side_radius 0 forward_radius) $
let step_vector = scale (Vector3D (2*side_radius) 0 (2*forward_radius)) $
vectorScaleTo stepage_offset $
Vector3D side_total_stepage 0 fwd_total_stepage
foot_position <- importA <<<
Expand All @@ -82,6 +83,8 @@ foot forward_radius side_radius lift_radius = proc emergency_footdown ->
translate (Vector3D 0 foot_lift 0) foot_position
returnA -< (csn_foot_position,cyclic_stepage > 1)

data LegStyle = Upright | Insectoid

-- | A description of a leg.
data Leg e m = Leg (FRP e m [Bool] [Bool])

Expand All @@ -95,6 +98,7 @@ instance (CoordinateSystemClass s,StateOf m ~ s) =>
-- more information on how some of these parameters
-- are interpreted.
--
-- * style - See LegStyle.
-- * bend - The bend vector of the articulated joint
-- * base - the base or shoulder or fixed point of the joint
-- * len - the total length of the articulation
Expand All @@ -104,13 +108,14 @@ instance (CoordinateSystemClass s,StateOf m ~ s) =>
-- as it walks.
-- * animation - an animation to display the joint
leg :: (CoordinateSystemClass s,StateOf m ~ s) =>
LegStyle ->
Vector3D ->
Point3D ->
RSdouble ->
Point3D ->
(FRP e m Joint ()) ->
Leg e m
leg bend base len end animation = Leg $ proc feet_that_are_down ->
leg style bend base len end animation = Leg $ proc feet_that_are_down ->
do let declare_emergency_foot_down =
length (filter id feet_that_are_down) <
length (filter not feet_that_are_down) &&
Expand All @@ -122,7 +127,13 @@ leg bend base len end animation = Leg $ proc feet_that_are_down ->
animation -< joint bend base len p
returnA -< (foot_is_down || declare_emergency_foot_down) :
feet_that_are_down
where foot_radius = sqrt (len^2 - (distanceBetween base end)^2) / 2
where insectoid_style = sqrt (len^2 - foot_ideal_distance_squared) / 4
upright_style = case (base,end) of
(Point3D _ base_y _,Point3D _ end_y _) -> sqrt $ len^2 - (base_y - end_y)^2
foot_ideal_distance_squared = distanceBetweenSquared base end
foot_radius = case style of
Insectoid -> insectoid_style
Upright -> upright_style

-- | Combines a group of legs into a group that will try to keep at least half
-- of the legs on the ground at all times.
Expand Down

0 comments on commit 96a19fa

Please sign in to comment.