Getting position after/before a model

Hi again my freiends ! [sorry 4 dat (and 4 english):d ]

I want to get position before a panda model, simple doing 3rd cam, i do this, but it doesnt work correctly, i dont know what i should do to do this, ( i found similar code from pawn i i transalted to python ^^ )

def spinCameraTask(self, task):

position = self.pandaActor.getPos()
kat = self.pandaActor.getHpr()

dist = 0
origin = position 

if dist is not 0:
origin[0] = position [0] + dist * abs(cos(kat[0]))
origin[1] = position [1] + dist * abs(sin(kat[0]))

origin[2] = 100

kat[0] = (180 - (self.pandaActor.getH()*-1))
kat[1] = -20

return Task.cont

Seconds - propaly main information -> i still dont have a lesson about sin/cos [yea, we have bad school system [all are saying that the one of the best ;P]]

More information ? please ask me :slight_smile:

I’m not all that sure what you are asking for, maybe it would be easier to write it in Polish so…

Witam. Nie do końca rozumiem o co chodzi, ale jak napiszesz jeszcze raz po polsku (najlepiej od razu co chcesz osiągnąć) to nawet jak nie będę w stanie pomóc to przynajmniej przetłumaczę dla innych. Pozdrawiam.

Am I correct in thinking that you want a camera to follow behind an object, as though attached via a pole?

If so, then the simplest way might be to simply make the camera object a “child” of the object being followed. In short, this results in the transformation of the object being “passed on” to the camera, and the camera’s transformation to be relative to the transformation of that object. For a fuller description of this, take a look at these two manual pages: The Scene Graph and Scene Graph Manipulations–in particular the section titled “Reparenting nodes and models” on the latter page.

The code to might look something like this:
#  Since the camera is now a child of self.pandaActor, its position and orientation
# are by default relative to self.pandaActor., dist, 100)

Note that this needn’t be executed repeatedly (as in the task in your version), I believe. You may also want to experiment with the exact values used there.

As to sin and cos, those are part of trigonometry (in particular the two non-right angles of a right-angled triangle), and I’m afraid that I’m rather too tired at the moment to trust myself with an attempt to teach them properly. ^^;

By the way, one problem that I see in the code that you posted is that “dist” seems to never be set to anything other than zero, and so the code within your “if”-statement may never be run.

@Thumaturge, your option is not great, i dont want to attach camera to model,
i want to do it using a math, but my experience is not great, because i still havent a lessons about sin/cos/rad/abs…


    def _follow_player(self, task):
	origin = self.pandaActor.getPos()
   	angles = self.pandaActor.getHpr()

   	output = origin
    	origin[2] += 20
    	dist = -30

   	output[1] = origin[1] + dist * cos(angles[1]) * abs(cos(angles[0]))
        output[0] = origin[0] + dist * sin(angles[1]) * abs(cos(angles[0]))
        output[2] = origin[2] + dist * sin(angles[0]) - (angles[0]*-1)), -30, angles[2]))
	return Task.cont

and effect:

@wezu, chce zrobic kamere z trzeciej osoby, jak ? [najprosciej :slight_smile:]

sin() and cos() isn’t the tool for the job. It’s just a waste of brainpower to try and figure that out. You can simply let Panda do the vector math to make what you want happen. Just reparent the camera to the model at the appropriate distance. If you want to rotate the camera arbitrarily around the character, you can create a pivot node and attach the camera to that.

Najprościej to tak jak mówi rdb i Thumaturge, nie bawić się w trygonometrię tylko wstawić do sceny dodatkowy węzeł (node)

#set the pos and hpr of the camera to what you want, 100, 50), 0, 0))

self.cameraNode możesz przyłaczyć do swojego avatara albo stworzyć task, który będzie uaktualniał pozycję tego węzła w oparciu o pozycje postaci ( self.cameraNode.setPos(self.pandaActor.getPos()) ), Możesz też teraz niezależnie obracać kamerą używając self.cameraNode.setH(kat), a przybliżać i oddalać kamerę przesuwając ją w jej własnych koordynatach, how_much_to_zoom_in).


But, it is hard to set the special angle, i’m doing it by chanaging pos,lookat,, 20, 8), 0, 5))

This is the best way, to set 3rd camera, without do mathematic-<(solution)

Dizęki wezu, wezo czy jakos tak ;D

If you want to set the angle, you can attach a dummy child to pandaActor, and then parent the camera to that dummy child. Then you can simply rotate the dummy child to change the angle from which the camera looks.