In the code below I am loading three models and when I try to move individual model the whole scene moves along. I want to select and control models separately. Can someone please help me with the changes I have to make to achieve it. Thanks in advance.
from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
# Load the environment model.
self.environ = self.loader.loadModel("models/environment")
# Reparent the model to render.
# Apply scale and position transforms on the model.
self.environ.setScale(0.25, 0.25, 0.25)
self.environ.setPos(-8, 42, 0)"""
self.box = self.loader.loadModel("models/xbox")
self.box.setScale(2.0, 2.0, 2.0)
self.box.setPos(8, 50, 0)
self.cube = self.loader.loadModel("models/cubemodel")
self.cube.setPos(-6, 50, 0)
self.sphere = self.loader.loadModel("models/sphere")
# Add the spinCameraTask procedure to the task manager.
# Define a procedure to move the camera.
def spinCameraTask(self, task):
angleDegrees = task.time * 6.0
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
app = MyApp()
Hmm… Perhaps I’m missing something.
For the sake of clarity, what do you mean by “the whole scene”, and trying to “move the model”? For the former, do you mean that all three of cube, box and sphere move when you move one? For the latter, are you referring to the three “setPos” calls for each of those three objects, the camera spinning task (which seems to be commented out) or some other code elsewhere?
I notice that the environment model seems to be commented out, so am I correct in presuming that that is not the “scene” referred to?
Offhand, I don’t see a problem with what you have presented.
I am sorry if i was not clear with my question. By whole scene I meant that the cube,box and the sphere move when I try to move one. I want to control the cube,box and sphere individually. Can you help me with the changes i need to make to the code to accomplish this.
You don’t have any code here to move things around though, this code is just loading models in certain positions.
Perhaps you are moving the camera?
Can you please provide some sample examples or point to url that has some tutorials , which would move models around. I am not much a programmer and this would really help me. Thanks in advance
Did you move any of them using mouse ?
I am not able to individual objects using mouse. When i try to move all the loaded object move together. One thing I figured out is that after loading the model I have to reparent it to the camera. Do you have any other suggestions. Thank you
By default, the mouse controls camera movement, not any other object.
You see all your models move because it’s the camera changes position.
What’re you trying to achieve anyway ?
What I am trying to achieve is Select and Unselect individual models. When a particular model is selected I want to have two options . The first option is to duplicate the model and second one to move the model in the world (follow the mouse position).I hope the above explanation is clear.
Have you tried the Chessboard sample in your Panda3d instalation /samples directory ?
No. but I surely check that example. Thanks a lot.