public:t-vien-10-3:lab_6_materials
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | public:t-vien-10-3:lab_6_materials [2010/10/21 16:14] – angelo | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Lab 6 - Avatars and HUD ====== | ||
+ | ==== Before You Start ==== | ||
+ | |||
+ | * Download and unzip the [[http:// | ||
+ | |||
+ | ==== Roaming Ralph with a HUD ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | In this exercise you'll start with a fully working 3rd person world with Ralph as your avatar. | ||
+ | |||
+ | - **Setting Up:**\\ Get the **advancedralph.py** running and explore the controls, making sure you understand how to control both Ralph himself and the camera (rotating and tilting by approaching the edge of the screen with your mouse; zooming with the mouse wheel). | ||
+ | - **Adding a Health Bar:**\\ The following code is a **HealthBar** object that can be attached to a scene graph. | ||
+ | class HealthBar(NodePath): | ||
+ | """ | ||
+ | | ||
+ | def __init__(self): | ||
+ | NodePath.__init__(self, | ||
+ | self.group = self.attachNewNode(' | ||
+ | self.group.setPos(-0.5, | ||
+ | cmfg = CardMaker(' | ||
+ | cmfg.setFrame(0, | ||
+ | self.fg = self.group.attachNewNode(cmfg.generate()) | ||
+ | cmbg = CardMaker(' | ||
+ | cmbg.setFrame(-1, | ||
+ | self.bg = self.group.attachNewNode(cmbg.generate()) | ||
+ | self.bg.setPos(1, | ||
+ | self.fg.setColor(0, | ||
+ | self.bg.setColor(0.5, | ||
+ | self.value = 0.8 | ||
+ | self.update() | ||
+ | | ||
+ | def update(self): | ||
+ | self.fg.setScale(self.value, | ||
+ | self.bg.setScale(1.0 - self.value, 1, 1) | ||
+ | |||
+ | def setHealth(self, | ||
+ | self.value = value | ||
+ | self.update() | ||
+ | | ||
+ | def decrease(self, | ||
+ | if (self.value - delta) >= 0: | ||
+ | self.value -= delta | ||
+ | self.update() | ||
+ | </ | ||
+ | - **Improving the Health Bar:**\\ | ||
+ | - Since your health bar rotates with your Avatar, you may notice that it fully disappears when you're looking at the Avatar from another angle. | ||
+ | - The healthbar calls a little too much attention to itself on the display. | ||
+ | - **Displaying Dynamic Health:**\\ Now make the healthbar start decreasing **while** the Avatar is running and then gain full health when the Avatar stops running. | ||
+ | - **Adding a Sliding HUD Panel:**\\ So far you have been adding visual information to the 3D scene, but let's create a simple HUD (Heads-Up-Display) panel that stays in front of the 3D scene, no matter where you are looking. | ||
+ | - Attach the panel background image to the panel node. You can create the panel image as a node in a tree with a single call to **[[http:// | ||
+ | - Attach the panel button to the panel node. You can use the following button specification:< | ||
+ | <your button> = DirectButton( | ||
+ | text_fg=(1, | ||
+ | text_shadow=(0, | ||
+ | frameColor=(0.4, | ||
+ | borderWidth=(0.1, | ||
+ | relief=DGG.RAISED, | ||
+ | text=(" | ||
+ | pressEffect=1, | ||
+ | scale=0.035, | ||
+ | frameSize=(-3, | ||
+ | command= <your function here>, | ||
+ | rolloverSound = <your sound here>, | ||
+ | clickSound = <your sound here>, | ||
+ | parent=< | ||
+ | - Set up a couple of intervals that will slide the panel in and out of view. You can make it slide down until all you can see is the button. | ||
+ | - **Adding an Overhead Map:**\\ The following code is an **OverheadMap** object that can be attached to a scene graph. | ||
+ | class OverheadMap(NodePath): | ||
+ | | ||
+ | def __init__(self, | ||
+ | """ | ||
+ | NodePath.__init__(self, | ||
+ | |||
+ | self.setBoundary(x1, | ||
+ | | ||
+ | cmbg = CardMaker(' | ||
+ | cmbg.setFrame(0, | ||
+ | self.prime = self.attachNewNode(cmbg.generate()) | ||
+ | self.prime.setColor(0.5, | ||
+ | | ||
+ | cmav = CardMaker(' | ||
+ | cmav.setFrame(-0.02, | ||
+ | self.avatar = self.prime.attachNewNode(cmav.generate()) | ||
+ | self.avatar.setPos(0, | ||
+ | self.avatar.setColor(0, | ||
+ | | ||
+ | def addLandmarks(self, | ||
+ | """ | ||
+ | as little dots on the map in the given color """ | ||
+ | ## To be filled in... | ||
+ | |||
+ | def setBoundary(self, | ||
+ | """ | ||
+ | offset and scaling values that transform world coordinates to map coordinates""" | ||
+ | self.xoffset = x1 | ||
+ | self.xscale = 1.0/(x2-x1) | ||
+ | self.yoffset = y1 | ||
+ | self.yscale = 1.0/(y2-y1) | ||
+ | | ||
+ | def setAvatarPos(self, | ||
+ | """ | ||
+ | self.avatar.setPos((x-self.xoffset)*self.xscale, | ||
+ | </ | ||
+ | - **Populating the Overhead Map:**\\ Now add some landmarks to your world and have them show up on your map as little red squares. | ||
+ | - **Make it a Game:**\\ If you feel adventurous, |
/var/www/cadia.ru.is/wiki/data/pages/public/t-vien-10-3/lab_6_materials.txt · Last modified: 2024/04/29 13:33 by 127.0.0.1