[vtkusers] vtkTransform and matrices
David Gauldie
dgauldie at hotmail.com
Tue Jul 25 11:55:01 EDT 2000
Hi Everyone,
I posted a question about vtkTransform earlier but didn't get a response. I
am tracking a target using a 3D camera and I am gathering 4X4 matrixes at
different time points. for each matrix, I turn it into a cone shape and I
want to translate the cone in the direction that its tip is facing by a
scalar value.
I've tried to do this by using the code located below (don't laugh, I'm new
at VTK). But my results are skewed, and the translation isn't in the correct
direction. Is there an easier (and correct) way to do this?
Thanks for any help on this matter,
David Gauldie
{
vtkMatrix4x4 *mat;
float offset;
float normal[3];
vtkConeSource *cone = vtkConeSource::New();
cone->SetRadius(20);
cone->SetHeight(100);
// gets the vtkMatrix4x4 of the position of the target
mat = theDataPasser.GetPosition(i);
// gets the scalar of how much we want to translate
offset = theDataPasser.GetOffset(i);
vtkTransform *trans = vtkTransform::New();
trans->PreMultiply();
trans->SetMatrix(*mat);
// gets the z orientation from the matrix
// (i think the the cone point in the z direction)
normal[0] = mat->GetElement(0,2);
normal[1] = mat->GetElement(1,2);
normal[2] = mat->GetElement(2,2);
// multiply the vector by the offset scalar
float x = normal[0] * offset;
float y = normal[1] * offset;
float z = normal[2] * offset;
// translate the matrix by the new vector
trans->Translate(x,y,z);
// get the new matrix
trans->GetMatrix(mat);
vtkDataSetMapper *map = vtkDataSetMapper::New();
map->SetInput(cone->GetOutput());
vtkActor *act = vtkActor::New();
act->SetMapper(map);
act->SetUserMatrix(mat);
this->Renderer->AddActor(act);
}
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
More information about the vtkusers
mailing list