Tải bản đầy đủ - 0 (trang)
Chapter 20.  An Articulated, Moveable Figure

Chapter 20.  An Articulated, Moveable Figure

Tải bản đầy đủ - 0trang

andskinning,whichIbrieflymentionattheend.



TheArticulatedFigureApplication

TheMover3Dapplicationdemonstratesthearticulatedfigure

approach.

ThelefthandpictureinFigure20-1showsthefigure'sinitial

stanceandtherighthandoneisthepositionafterthefollowing

commandshavebeenprocessed:



urLegf40,lrLegf-40,ulArmf20,llArmf20,chestt10



Figure20-1.Initialpositionandafterlimb

movement



Thecommandsaretypedintoatextfieldatthebottomofthe

applicationwindowandprocessedwhenEnterispressed.All

thecommandsarecarriedoutasagroup,causingasingle



reorientationofthefigure.

Thefirstfourcommandsspecifyforward(finthecommandline

above)rotationsofthelimbsrepresentingtheupperpartofthe

rightleg(urLeg),thelower-rightleg(lrLeg),theupper-leftarm

(ulArm),andthelowerpartoftheleftarm(llArm).Thechestand

headareturned(t)leftandrightrespectively,sothehead

staysfacingforward.

PressingEnteragainrepeatsthecommands,thoughwhena

limbreachesitspredefinedmaximumpositiveornegative

rotation,operationsthatwouldrotateitbeyondtheselimitsare

ignored.Figure20-2showstheresultofexecutingthe

commandlinefromFigure20-1afewmoretimes.Severalof

thelimbshavereachedtheirrotationallimits,includingthe

upper-rightlegandtheupper-leftarm.



TherightarmpassesthroughtherightlegbecauseMover3Ddoesnot

employcollisionavoidancetopreventlimbsfromintersecting.



Asidefromcommandsthatinfluenceindividuallimbs,several

affecttheentirefigure,movingitoverthefloorandrotatingit

aroundthey-axis.Thesecommandscan



Figure20-2.Repeatedlimbmovements



betypedintothetextfieldorenteredbypressingarrowkeys

onthekeyboard.Figure20-3displaystheoutcomeofthetext

fieldcommands:

f,f,c,c,f,f



Figure20-3.Figuremovement



Thissequencecausesthefiguretomovefromitsstarting

positionat(0,0)onthefloor,forward0.6units(2x0.3),45

degreestoitsright(two22.5degreeturns),andforward

another0.6units.

Themoveincrementandrotationanglearehardwiredintothe

code.Anadvantageof22.5degreesisthatfourturnstotal90

degrees,and16turnsbringthefigurebacktoitsoriginal

orientation.

Figure20-4isaviewofthesceneafterrepeatingthef,f,c,c,

f,fcommandsthreetimes.



Figure20-4.Repeatedfiguremovement



Thefigurecanmoveupanddown(i.e.,itcanfloat),butitcan't

beloweredbelowfloorlevel.Rotationsarelimitedtoclockwise

andcounterclockwisearoundthevertical,withnosupportfor

turnsaboutthex-orz-axes.Thismeans,forexample,thatthe



figurecannotlieonitsbackonthefloor.Themainreasonfor

theserestrictionswastoreducethecomplexityofthe

implementation.

Aswiththelimboperations,allfigurecommandsenteredinto

thetextfieldupdatethefigureatonceafterEnterispressed.

Theoperationsarecarriedoutintheorderspecifiedbyreading

theinputsequencefromlefttoright.Figures20-3and20-4

showthattheentirefiguremovesandrotatesasasingleunit.

Figure20-5illustratestheresultofpressingtheResetbuttonin

theGUI:thefigure'slimbsarerotatedbacktotheirstarting

position,butthefigureremainsatitscurrentpositionand

orientationonthefloor.



BuildingtheFigure

Thefigureiscreatedbyconnectingtogetherinstancesofthe

Limbclass.TheshapeofalimbisspecifiedusingaLatheShape3D

object(introducedinChapter17),anditsappearanceisderived

fromatexture.

Asthelimbsareconnected,theyformaparent/childhierarchy.

Eachlimbcanbegivenaninitialorientationrelativetoits

parentlimb,anditcanberotatedarounditsx-,y-,andz-axes

atruntime.Alimbmaybeinvisible,whichenablesittobeused

asaconnectorbetweenotherlimbswithoutbeingrendered.For

example,invisiblelimbsareusedtoconnectthearmstothe

torso.



Figure20-5.Resetlimbs



Thoughtheaimistomakealimbed,humanfigure,theLimb

classissufficientlygeneraltobeusedtobuildmostkindsof

articulatedshapes.



ForwardandInverseKinematics

Beforetalkingaboutforwardandinversekinematics,it'suseful

toreviewtheparent-childrelationshiputilizedbythenodesina

Java3Dscenegraph.Thishierarchyisparticularlyimportantfor

sequencesofTRansformGroupnodes.

Figure20-6showsasimplehierarchymadeupofaparentand

achildtransformGroup.Theparentholdsatranslationof(1,1,2),

andthechildatranslationof(2,3,1).However,fromthe

world'sviewpoint,thechild'stranslationwillbe(3,4,3),a

combinationoftheparentandchildvalues.Here,the

combinationisanadditionofthelocaltranslations,butit

becomesmorecomplicatedwhenintroducingrotationand

scalingelements.



Figure20-6.AhierarchyofTransformGroups



Ingeneral,theworld(orscene)viewofatransformGroupisa

combinationofitstranslation,rotations,andscalingwiththose

ofitsancestors(parent,grandparent,andsoon).

Thishierarchyisimportantwhendevelopinganarticulated

figuresinceeachlimbcontainsseveralTRansformGroups,andthe

connectionoflimbstomakethecompletefigurecreatesalarge

hierarchyofTRansformGroups.Theconsequenceisthatwhena

limbismoved(byaffectingoneofitsTRansformGroups),thelimbs



linkedtoitaschildrenwillalsomove.

Thistop-downbehaviorisattheheartofforwardkinematics,

oneofthestandardapproachestoanimatingarticulated

figures.Forexample,therotationofafigure'schestcancause

itsarmsandheadtoturneventhoughthebottomandlegs

remainstationary.Fromaprogrammingpointofview,this

meanslessexplicitmanipulationofTRansformGroupsbutrequires

thearmsandheadareconnectedaschildrentothechest's

TRansformGroup.

Forwardkinematicsisespeciallyusefulformovementsthat

originateatthetop-levelofafigureandrippledowntothe

lower-levelcomponents.Aneverydayexampleismovinga

figure:thetranslationisappliedtothetop-mostTRansformGroup,

andalltheothernodeswillmoveaswell.

Forwardkinematicsislesssatisfactoryforoperationsthatstart

atlower-levellimbsandshouldrippleup.Forinstance,the

naturalwayofhavingafiguretouchanobjectinthesceneisto

moveitshandtotheobject'slocation.Asthehandismoved,

thearmandtorsoshouldfollow.Unfortunately,thiswould

requirethatachildtransformGroupbeabletoinfluenceits

ancestors,whichisimpossibleintheparent-childhierarchy

usedbyJava3D.

Thisripple-upanimationtechniqueiscalledinversekinematics

andisastapleofprofessionalanimationpackagessuchas

Poser,Maya,and3DStudioMax.Importantlow-levelnodesare

designatedasend-effectors,andtheseinfluencehigher-level

nodesasthey'remanipulated.Typically,end-effectorsforan

articulatedhumanareitshands,feet,andhead.

Inversekinematicshasproblemsspecifyingtop-downeffects,

soitisoftencombinedwithconstraintsthatlinkend-effectors

toothernodes.Forinstance,whenthebodymoves,theendeffectorscanbeconstrainedtostaywithinacertaindistanceof

thetorso.



Agoodnontechnicalintroductiontoforwardandinverse

kinematicsisStevePizel'sarticle"CharacterAnimation:

SkeletonsandInverseKinematics,"onlineat

http://www.intel.com/cd/ids/developer/asmona/eng/segments/games/resources/modeling/20433.htm.



AsfarasIknow,noJava3Dexamplesuseinversekinematics.TheFAQ

atj3d.orgcontainsafewlinkstodiscussionsofhowtoimplement

inversekinematicsinprocedurallanguages

(http://www.j3d.org/faq/techniques.html#ik).



ForwardKinematicsinMover3D

TheMover3Dapplicationinthischaptercreatesafigurebylinking

Limbobjectstogetherinaparent/childrelationship.AsI'll

explainindetail,eachLimbobjectisacollectionoftransfromGroup

nodes(andotherthings)formingacomplexhierarchicalscene

graph.

Limbmovementisamatteroftranslatingorrotating

transformGroupsinalimb,andchangestothosenodeswillaffect

allthechildnodesbelowit(i.e.,thechildLimbobjects).Inother

words,Mover3Dusesforwardkinematics.



ClassDiagramsforMover3D

Figure20-7showstheclassdiagramsfortheMover3Dapplication.

Theclassnames,publicandprotectedmethods,anddataare

shown.



Figure20-7.ClassdiagramsforMover3D



Mover3Disthetop-levelJFramefortheapplication,containingtwo

JPanels.The3DsceneiscreatedinWrapMover3Danddisplayedin



itspanel,thetextfieldforenteringcommandsandResetbutton

aremanagedbyCommandsPanel.TheLocationBehbehaviordealswith



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 20.  An Articulated, Moveable Figure

Tải bản đầy đủ ngay(0 tr)

×