[vtkusers] 3D, constant view size, billboard object?
Jeff Lee
jeff at cdnorthamerica.com
Wed Mar 24 14:43:46 EST 2004
here goes in java. First you'll need a couple of methods to convert
points back and forth
public double[] ComputeWorldToDisplay(double x, double y, double z) {
currentRenderer.SetWorldPoint(x, y, z, 1.0);
currentRenderer.WorldToDisplay();
return currentRenderer.GetDisplayPoint();
}
public double[] ComputeDisplayToWorld(double x, double y, double z) {
currentRenderer.SetDisplayPoint(x, y, z);
currentRenderer.DisplayToWorld();
double[] worldPt = currentRenderer.GetWorldPoint();
if (worldPt[3] != 0) {
worldPt[0] /= worldPt[3];
worldPt[1] /= worldPt[3];
worldPt[2] /= worldPt[3];
worldPt[3] = 1.0;
}
return worldPt;
}
now you add an observer to your render window
rw.AddObserver("StartEvent", this, "StartRender");
now in your StartRender method, you can do something like:
public void StartRender() {
double[] pos = _yourPos;
double[] displaypt = ComputeWorldToDisplay(pos[0], pos[1], pos[2]);
displaypt[0] += 5;
double[] worldpt = ComputeDisplayToWorld(displaypt[0], displaypt[1],
displaypt[2]);
vtkMath m = new vtkMath();
double radius = m.Distance2BetweenPoints(pos, worldpt);
double len = Math.sqrt(radius);
// now you can scale by this radius...
}
if you want to do orientation, you can do this by grabbing the camera
and something like
double[] rx = new double[3];
double[] rz;
double[] cpos = camera.GetPosition();
if (camera.GetParallelProjection() == 1)
{
rz = camera.GetDirectionOfProjection();
rz[0] = -rz[0];
rz[1] = -rz[1];
rz[2] = -rz[2];
}
else
{
double dist = Math.sqrt(
(cpos[0] - pos[0])*(cpos[0] - pos[0]) +
(cpos[1] - pos[1])*(cpos[1] - pos[1]) +
(cpos[2] - pos[2])*(cpos[2] - pos[2]));
for (j = 0; j < 3; j++)
{
rz[j] = (cpos[j] - pos[j])/dist;
}
}
myActor.SetOrientation(0,0,0);
double[] yaxis = new double {0.0, 1.0, 0.0}; // y-axis or natural orientation of actor
vtkMath m = new vtkMath();
m.Cross(yaxis,rz,rx);
m.Normalize(rx);
myActor.RotateWXYZ(
180.0*Math.acos(m.Dot(yaxis,rz))/Math.PI,
rx[0], rx[1], rx[2]);
}
}
syntax is a little different in c++, but this is the idea...
-Jeff
BURRELL Benjamin wrote:
>Hi Jeff,
>
>I was wondering if you could describe a bit further with code, I think I kind of understand what your getting at but I am not sure how to go about implementing it in VTK.
>
>Thanks,
>Benjamin Burrell
>
>-----Original Message-----
>From: Jeff Lee [mailto:jeff at cdnorthamerica.com]
>Sent: Saturday, March 20, 2004 3:26 AM
>To: BURRELL Benjamin
>Cc: vtkusers at vtk.org
>Subject: Re: [vtkusers] 3D, constant view size, billboard object?
>
>
>Hi,
>In a nutshell, you need to add an observer to your renderwindow
>StartRender event. In your callback, you
>1. Convert a billboard world point to display
>2. nudge the display point by a couple of pixels
>3. convert the nudged point back to world
>4. the distance between the original point and the point from (3) will
>give you a radius by which you can scale your billboard object before it
>renders.
>
>if this is too sketchy, i could probably cobble up some code... let me
>know.
>-Jeff
>
>BURRELL Benjamin wrote:
>
>
>
>>Hi,
>>
>>I am wondering if anyone has any suggestions on how to solve the following:
>>What I require is 3D object (which might be some simple line drawn symbols or a 3D model) that always appears the same size on screen, even when I move the camera close to it. I need this to happen in real-time, eg. I am probably going to use the vtkInteractorStyleTrackballCamera interactor and use the mouse. This interactor 'dollies' the camera (moves the camera closer and further away) compared to the std. interactor style which zooms in and out.
>>I am guessing I will need to overwrite the dolly callback function but I am not sure how to do it, and what to implement to get the desired result of having the 3D object stay the same size on screen.
>>
>>I might also want the 3D model to actually be a billboard object, eg. face the camera all the time with a 2D image.
>>Does anyone have a suggested vtkObject to do this with. It will also need to stay the same size on the screen no matter how close/far away the camera gets.
>>
>>Thank you for your help.
>>
>>Regards,
>>Benjamin Burrell
>>
>>
>>_______________________________________________
>>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