AW: [vtkusers] matrix rotation "jumps"

rohlof rohlof at gmx.de
Tue Oct 26 03:27:38 EDT 2004


First...the earth rotates around the sun. ;)

Second: Are the other elements of your rotation- and transformation matrix
respectively correct? You should check this (Element(3,3) and Element(4,4)
have to be '1', the others '0').
Perhaps the two positioning functions collide. With your matrix you set
rotation and position (position elements are probably '0') like you do with
'light->SetPosition(-1.0,0.0,0.0)'. Though VTK says that this should work, I
would test it.

Third: I have done this with a transformed actor (Prop3D) by setting
'actor->SetUserTransform(matrix)'. This works fine. But other attempts with
'vtkTransform' or 'vtkLinearTransform' don't work correct. Perhaps there are
some bugs in these functions (or in my code...).

I would try the same with your sphereactor. Afterwards you could see, if the
transforming is working.

Greets, Timo Frenzel.

-----Ursprüngliche Nachricht-----
Von: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] Im Auftrag
von Christopher.Moore at noaa.gov
Gesendet: Dienstag, 26. Oktober 2004 02:44
An: vtkusers at vtk.org
Betreff: [vtkusers] matrix rotation "jumps"


I'm using the GetTransformedPosition() method in vtkLight to simply rotate a
light's position around the origin (as the sun would rotate around the
earth).

I set up a vtkMatrix4x4 with the proper elements to rotate around the z
axis, and use a callback to repeatedly call:

light->SetPosition(light->GetTransformedPosition());

It works great until it reaches a certain point in the orbit (angle=3pi/2)
where it "jumps" to angle=0.

Any ideas?

Just when I thought I was getting good at this, Chris

sample code (sorry so long):
don't forget to press "u" to see the action...

#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkLight.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkMatrix4x4.h"
#include "vtkCommand.h"

vtkLight *light;
vtkMatrix4x4 *matrix;

class rotateCallback : public vtkCommand {
public:
  static rotateCallback *New() {
    return new rotateCallback;
  }
  virtual void Execute(vtkObject *caller, unsigned long, void*) {
    vtkRenderWindowInteractor *rwi =
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
    light->SetPosition(light->GetTransformedPosition());
    rwi->GetRenderWindow()->Render();
  }
};

int main( int argc, char *argv[] ) {

  float angle = 0.1; // radians

  vtkRenderWindow *renWin = vtkRenderWindow::New();
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  vtkSphereSource *ss = vtkSphereSource::New();
  vtkPolyDataMapper *sMapper = vtkPolyDataMapper::New();
  vtkActor *sphereActor = vtkActor::New();

  renWin->AddRenderer(ren);
  iren->SetRenderWindow(renWin);

  matrix = vtkMatrix4x4::New();
  matrix->Identity();
  matrix->SetElement(0, 0, cos(angle));
  matrix->SetElement(0, 1, -1.0 * sin(angle));
  matrix->SetElement(1, 0, sin(angle));
  matrix->SetElement(1, 1, cos(angle));

  light = vtkLight::New();
  light->SetLightTypeToSceneLight();
  light->SetIntensity(1.0);
  light->SetPosition(-1.0,0.0,0.0);
  light->SetFocalPoint(1.0,0.0,0.0);
  light->SetTransformMatrix(matrix);
  light->SwitchOn();
  ren->AddLight(light);

  ss->SetRadius(1.0);
  sMapper->SetInput(ss->GetOutput());
  sphereActor->SetMapper(sMapper);
  ren->AddActor(sphereActor);

  rotateCallback *rotate = rotateCallback::New();
  iren->AddObserver(vtkCommand::UserEvent, rotate);

  iren->Start();

}


_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list