Rotating camera

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
DjZU
Posts: 10
Joined: Friday 13 April, 2012 - 10:03

Rotating camera

Post by DjZU »

Hello,

I would like to visualize the entire model in 3D with a defined camera that would rotate around a center point. I mean the targeted point would remain the same while the camera (the point of view) would rotate around the same targeted point. I tried to achieve this goal without success in two ways:
- I added the following code in the On2dDraw event: RotateCoords(time,0,0,1,0,0,0)
- I also tried to set rotation speed around container in the Spatial tab of the camera Atom Editor

Both ways I get the atom camera moving in 2D layout but not in 3D.

Could you give me a clue ?

Thank you.
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Rotating camera

Post by HarryBunnik »

Ha DjZU,

What I would do to achieve what you have in mind is the following:

First I would change the camera type from it's default type (Freehand) to a Target type. This ensures that the camera will focus on a specified object. This can be done in 2 ways. The first is via the menu of the 3D model view (Camera => Mode=> Target), or on code using the Interact (SHIFT + F6) and typing:

Code: Select all

SetCameraType(CT_Target)
Next you'll have to specify on which the camera has to target itself. In this case I took an atom which I selected in the 2D model view. You can also give in the x,y and z using fixed values, or just whatever suits you best. Again you can run the code from the interact:

Code: Select all

SetCameraTarget(xAbsLoc(animatom, model), yAbsLoc(animatom, model),zAbsLoc(animatom, model))
Than finally on a 3D Event you write code to update the position of the camera. In this case the camera will rotate at a radius of 40 meters from the earlier selected atom at a height of 2 meters, while constantly having that atom at the center of your 3D model view. I limited the speed at which it rotates to 1 degree per minute, just to give you an idea:

Code: Select all

  
SetCameraPosition(
    Sin(Mod(Time/60, 360)) * 40,
    Cos(Mod(Time/60, 360)) * 40,
    2
)
I hope this helps you further,

Cheers,

Harry

P.S.

The RotateCoords you used is more to manipulate the position or rotation of objects (by changing the coordinate system) that you draw in 3D or 2D. But the camera is the not such an 3D object. Therefor you have to use the SetCameraPostion and or SetCameraRotation to get the camera moving.
DjZU
Posts: 10
Joined: Friday 13 April, 2012 - 10:03

Re: Rotating camera

Post by DjZU »

Hello HarryBunnik,

Thank you very much for your help and explanation, the camera is now moving like I expected it to do.

I would have other request: how to do to have a fixed speed of rotation of the camera?

You suggest to update the position of the camera with this code, where Time depends on the speed of simulation. I haven't found any RealTime function to replace with...

Code: Select all

  
SetCameraPosition(
    Sin(Mod(Time/60, 360)) * 40,
    Cos(Mod(Time/60, 360)) * 40,
    2
)
Cheers,
DjZU
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Rotating camera

Post by HarryBunnik »

Ha DjZU,

So if I understand it correctly you want the camera to move with a speed not based on the simulation time, but on the real time?

I that case I would use the function "now" instead of "time". "Now" gives back the system time of your computer (in seconds that have passed since 30 December, 1899 to be precise ;-) )

I hope this helps you!

Cheers,

Harry
DjZU
Posts: 10
Joined: Friday 13 April, 2012 - 10:03

Re: Rotating camera

Post by DjZU »

Hello HarryBunnik,

Thank you again, that's exactly what I was looking for: the function Now. I achieved to do what I need.

Cheers!

DjZU
Post Reply