Rotate camera clock/counterclockwise

Creator
Creator

Hi guys,

 

I'm using C# and I'm trying to rotate the camera clock/counterclockwise, but I couldn't figure out what's the calculation to determine the new X,Y,Z for doing that. Here's an example:

 

In this case it's easy, it's just rotating the Y axis:

Picture 1

 

Result:

2.png

 

But if the object is in a different position, I need to rotate another axis instead.

I found some similar questions in the forum but none of them are exactly what I'm looking for.

 

Here's my code:

 

public void RotateFace(int angle, bool isClockwise)
{
   var axis = new double[3];

   // Just rotating Y axis
   axis[0] = 0;
   axis[1] = isClockwise ? 1 : -1;
   axis[2] = 0;

   view.RotateCamera(angle, 0, 0, 0, axis[0], axis[1], axis[2]);
}

 

 

Thanks everyone.

9 REPLIES

Re: Rotate camera clock/counterclockwise

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Josh,

 

I just wanted to let you know that I'm deeply interested in what you're trying to do. I wish so bad that I understood the math side of CAD better. My lack of a good math education is showing...

 

I spoke with a dear friend of mine, John Hilton, on Skype tonight. John is absolutely amazing with this kind of stuff but getting his time is difficult. I poked and prodded him to jump in here and answer your question so we'll have to wait and see if he has time. Fingers crossed.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Rotate camera clock/counterclockwise

Creator
Creator
Hi Jason,
Thanks for the effort, man. Hopefully he'll show up here. Last time I've asked something related to that in this forum, a guy called Martin helped me a lot. Seems he's no longer here though.

Re: Rotate camera clock/counterclockwise

Genius
Genius

Josh,

 

hope I understand your requirements.

 

In the video below I transformed the rootpoint and the normalvector of the refplane at the tip of the arrows to the topassembly and used

view.RotateCamera(angle, X(rootpoint), Y(rootpoint), Z(rootpoint), _
                                     n*X(normalvector), n*Y(normalvector), n*Z(normalvector))

 

Rotate Camera

 

regards
Gerald

Re: Rotate camera clock/counterclockwise

Creator
Creator
Hi Gerald, youtube says the video is private. Can you make it public, please? Or maybe post some pieces of code here? Thanks

Re: Rotate camera clock/counterclockwise

Genius
Genius

Josh,

 

the video is public now.

 

I wrote a module to get and transform Rootpoint, Normalvector and Matrix, it works for me but unfortunately I don't really know why.

 

Occurrence.GetMatrix TM(1 to 16)

RefPlane.GetRootPoint RP(1 to 3)

RefPlane.GetNormal NV(1 to3)

 

For i = 1 to 3

  RP_Transformed= TM(i) * RP(1) + TM(i + 4) * RP(2) + TM(i + 8) * RP(3) + TM(i + 12)
  NV_Transformed= TM(i) * NV(1) + TM(i + 4) * NV(2) + TM(i + 8) * NV(3)

next

 

RP_Transformed and NV_Transformed are my values to rotate the camera.

 

HTH
Gerald

Re: Rotate camera clock/counterclockwise

Creator
Creator

Hi Gerald,


Thanks for your reply. In your video you are pretty much rotating axis X, Y and Z individually. I'm looking for some sort of calculation to rotate all of them at once, no matter what's the current position of the object. I think it would be something like this:

 

var eye = new double[3];
var target = new double[3];
var up = new double[3];
var isPerspective = false;
double scale = 0;

view.GetCamera(out eye[0], out eye[1], out eye[2], out target[0], out target[1], out target[2], out up[0], out up[1], out up[2], out isPerspective, out scale);

const int angle = 20;

 

// Compute the normalized view direction
var viewDir = new double[3];
viewDir[0] = target[0] - eye[0];
viewDir[1] = target[1] - eye[1];
viewDir[2] = target[2] - eye[2];
double len = Math.Sqrt(viewDir[0] * viewDir[0] + viewDir[1] * viewDir[1] + viewDir[2] * viewDir[2]);
if (len > 1.0E-5)
{
   viewDir[0] /= len;
   viewDir[1] /= len;
   viewDir[2] /= len;
}

 

// var axis = DO SOME CALCULATION HERE TO DETERMINE X, Y, Z


view.RotateCamera(angle, 0, 0, 0, axis[0], axis[1], axis[2]);

Re: Rotate camera clock/counterclockwise

Genius
Genius

Josh,

 

it depends on the position of the arrow.

 

regards
Gerald

Re: Rotate camera clock/counterclockwise

Genius
Genius

Josh,

 

if you want to rotate around the axis of the camera like in the video below you can use

 

view.RotateCamera(angle, out target[0], out target[1], out target[2], out eye[0] - out target[0], out eye[1] - out target[1], out eye[2] - out target[2]);

 

Gerald

Re: Rotate camera clock/counterclockwise

Creator
Creator
Gerald, you the guy! With your code I could achieve what I was looking for! Thanks man