![]() |
|
#1
|
|||
|
|||
|
inheritence question
Hi,
I'm trying to make custom class called car a subclass of the VizNode class, but I'm having a few problems. Here is the main part of my constructor for the car class: Code:
class Car(viz.VizNode): def __init__(self, direction = "right", id = sys.carID): randomCar = random.randint(1,14) if (randomCar == 10): randomCar += 1 if (randomCar > 10): self.tempCar = viz.add( "cars\car_" + str(randomCar) + ".ive" ) else: self.tempCar = viz.add( "cars\car_0" + str(randomCar) + ".ive" ) viz.VizNode.__init__( self, self.tempCar.id ) If I add the following code to the car constructor: Code:
self.tempCar.collideBox() self.tempCar.setVelocity([10,0,0]) however, if I type the following code outside of the car class: Code:
viz.go() viz.phys.enable() car = Car() car.collideBox() car.setVelocity([100,0,0]) Cannot collideBox with invalid bounding box collideBox is not the only method that does not work. I've also tried methods like car.setPosition(10,0,0) which also does not do anything. Any ideas? |
|
#2
|
|||
|
|||
|
Can you provide a minimal working sample that reproduces the problem? The following code works for me:
Code:
class Car(viz.VizNode):
def __init__(self):
model = viz.add('mini.osgx')
viz.VizNode.__init__(self,model.id)
import viz
viz.go()
c = Car()
c.setPosition(0,0,10)
c.setEuler(180,0,0)
c.addAction(vizact.spin(0,1,0,90))
|
|
#3
|
|||
|
|||
|
Alright I figured out the problem. It had to do with getting a child object from the model that was imported as a "car". This was code that was in the constructor that I didn't include in my previous post because I didn't think it was important (oops.):
Code:
self.frontWheels = self.tempCar.getChild( '0' + str(randomCar) + 'tyresBack-OFFSET' ) self.backWheels = self.tempCar.getChild( '0' + str(randomCar) + 'tyresFront-OFFSET' ) this needed to be changed to: Code:
self.frontWheels = self.getChild( '0' + str(randomCar) + 'tyresBack-OFFSET' ) self.backWheels = self.getChild( '0' + str(randomCar) + 'tyresFront-OFFSET' ) |
|
#4
|
|||
|
|||
|
Sorry I forgot, I also had to change the name of the ID parameter in the constructor. It must have been scope problems with tempcar.id or something..
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| viztask question | asimbh | Vizard | 1 | 11-20-2007 09:12 AM |
| Another color question | mjabon | Vizard | 4 | 07-31-2007 03:04 PM |
| question about yaw, pitch, roll | TunTun | Vizard | 2 | 05-23-2007 12:46 PM |
| to rephrase my question... | shai | Vizard | 2 | 10-27-2004 10:55 AM |
| Lots of Question | Karthi | Vizard | 4 | 02-20-2004 06:42 PM |