[solved] How to do Translation instead of Rotation in this code? Coin3D

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

[solved] How to do Translation instead of Rotation in this code? Coin3D

Post by DorinDXN »

Due to the great help from this forum I'm able to rotate camera with this code

Code: Select all

def RotateView(axisX,axisY,axisZ,angle):
    #Macro_Rotation_Z_axis droite
    import math
    from pivy import coin
    try:
        cam = Gui.ActiveDocument.ActiveView.getCameraNode()
        rot = coin.SbRotation()
        rot.setValue(coin.SbVec3f(axisX,axisY,axisZ),math.radians(angle))
        nrot = cam.orientation.getValue() * rot
        cam.orientation = nrot
RotateView(0,0,1,1)
How to do translation only, no rotation, on, say, the x axis?

Appreciate any help.

take care,
cheers,
Dorin
Last edited by DorinDXN on Sat Aug 06, 2022 6:26 pm, edited 3 times in total.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: How to do Translation instead of Rotation?

Post by Syres »

Based on a simple search I believe (unless it's changed) you require something like to move to X5, Y0, Z0:

Code: Select all

camera.position.setValue(FreeCAD.Vector(5,0,0))
Have a look at https://forum.freecadweb.org/viewtopic.php?p=82414 for some inspiration.
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to do Translation instead of Rotation?

Post by DorinDXN »

Thanks,

I want camera to translate 5 on X axis instead of rotate
i.e. relative translation from the current position.
I guess I'll need to read the camera position first, then increase with 5 on x, then set camera position.

cheers,
Dorin
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to do Translation instead of Rotation?

Post by onekk »

DorinDXN wrote: Sat Aug 06, 2022 9:57 am Thanks,

I want camera to translate 5 on X axis instead of rotate
i.e. relative translation from the current position.
I guess I'll need to read the camera position first, then increase with 5 on x, then set camera position.

cheers,
Dorin
Hello,

Sorry for the intrusion.

Could you please specify in the title that "Translation and Rotation" are relative to the camera view (managed by Coin3D) and not to the "geometric kernel" OCCT?

You could edit the title as you are the OP (Original Poster).

Simply to follow one of the advices of some developers that "forum posts are for future", this way it will be clear without opening the post that is relative to Visualization, Coin3D, "View Tab" and not Translation and Rotation properties of objects, and relative.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to do Translation instead of Rotation in this code?

Post by DorinDXN »

added "in this code"

the code provided performs rotations of the camera, I want translation instead.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to do Translation instead of Rotation in this code?

Post by onekk »

DorinDXN wrote: Sat Aug 06, 2022 11:41 am added "in this code"

the code provided performs rotations of the camera, I want translation instead.
Thanks,

Coin3D is not know from much people (other than some coders), probably I've not explained correctly things, as I was reasoning as a "programmer" my fault, sorry.

Probably adding also information about you FC version using istruction provided here:

https://forum.freecadweb.org/viewtopic.php?f=3&t=2264

it will be better as it is versioned in case of "future changes", as forums posts hopefully will be retained for a long time, doing that if the solution proposed and proved to be useful in say 0.20.1 (as a simple example) it will be immediate to have some doubt that if it will not work in FreeCAD 2.00 as something could have changed.

For the title, IMHO maybe it is better to write something like this:

How to do camera Translation instead of Rotation?

Sorry again for bothering and thanks for your kindness.

Regards

Carlo D.

PS as example my version of FC is (among others):

Code: Select all

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
 Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: Italian/Italy (it_IT)
Installed mods: 
  * Curves 0.5.2
you could easily see that this version is compiled using:
Python 3.9.13
Qt 5.12.9
Coin 4.0.0
OCC 7.5.3

that have some relevance when coding in Python, maybe some Python construct supported by 3.9.13 could not working of worse work different from maybe Python 3.10.0 or in Python 3.8.7.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to do Translation instead of Rotation in this code? Coin3D

Post by DorinDXN »

Solved :)

Code: Select all

def TranslateView(axisX,axisY,axisZ):
	cam = Gui.ActiveDocument.ActiveView.getCameraNode()
	pos = cam.position.getValue().getValue()
	cam.position.setValue(FreeCAD.Vector(pos[0]+axisX, pos[1]+axisY, pos[2]+axisZ))
	
TranslateView(5,0,0)
cheers,
Dorin
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to do Translation instead of Rotation in this code? Coin3D

Post by onekk »

https://forum.freecadweb.org/viewtopic. ... 419#p82419

but how getValue() is doubled in:

Code: Select all

pos = cam.position.getValue().getValue()
Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: [solved] How to do Translation instead of Rotation in this code? Coin3D

Post by DorinDXN »

You can try this

Code: Select all

cam = Gui.ActiveDocument.ActiveView.getCameraNode()
print(cam.position.getValue())
print(cam.position.getValue().getValue())
cheers,
Dorin
Post Reply