Author Topic: acDisplayDCS matrix  (Read 8030 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: acDisplayDCS matrix
« Reply #15 on: September 10, 2006, 07:15:47 PM »
I've been looking for the relationship of the target in the camera command..
In vba there is no camera but there is a target which doesnt update with  A Pan or zoom.
...

sorry, didn't mean the camera command as such, just the camera/view in general.
It will be hard to find out as the target in the scenario I put up before as the camera/view can see beyond and before the target as it can see the whole graphics viewing volume (unless it's clipped which is effectively reducing the viewing volume). In these cases the target isn't really 'tied' to anything as it doesn't matter.
If I needed an accurate view the best way would be to 'tie' it to some geometry some how so you can update it if required, grabbing the target does not seem to be reliable at all.

I have to do this myself, I currently have a viewing tool to set a clipped view on a 3d solid given a ucs z value and I have the same problem. If I use the target, the new view when set could be anywhere and I have to zoom or pan to find the object I want to see a detail of, this is a throw back from using the target (which is not at what I was looking at). To get around this I will be getting the bbox of the object, find the centre then use that as the target. I will then set my view rect to be a bit larger than the bbox which will (hopefully) set the zoom.

hth.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Bryco

  • Water Moccasin
  • Posts: 1883
Re: acDisplayDCS matrix
« Reply #16 on: September 22, 2006, 08:44:04 PM »
Well I have the target.
Perhaps this will work for other languages as it uses setvars.
It seems the Distance (or Z value in a 2d dwg) is the z value of the viewctr tanslated to display.
Since the Center of the display is the target, this makes sense.
The  viewctr value is  reliable (updates with pan and zoom)
In a 2d drawing you will find the x and y of the target are the x and y of the viewctr translated to world.

This  property gives an updated Target in Wcs

Code: [Select]
Property Get VT() As Variant  'Target 'no update
    'This gives an updated Target in Wcs
    Dim Tar(2) As Double
    Dim C, Cen, dir
    Dim Dist As Double
   
    C = ThisDrawing.GetVariable("viewctr")
    Cen = ToWcs(C)
    dir = VD
    C = UToD(C)
    Dist = -C(2)
    Tar(0) = Cen(0) + Dist * dir(0)
    Tar(1) = Cen(1) + Dist * dir(1)
    Tar(2) = Cen(2) + Dist * dir(2)
    VT = Tar
End Property

Function ToUcs(Pt As Variant) As Variant
    ToUcs = ThisDrawing.Utility.TranslateCoordinates(Pt, acWorld, acUCS, False)
End Function
Function ToWcs(Pt As Variant) As Variant
    ToWcs = ThisDrawing.Utility.TranslateCoordinates(Pt, acUCS, acWorld, False)
End Function
Function UToD(Pt As Variant) As Variant
    UToD = ThisDrawing.Utility.TranslateCoordinates(Pt, acUCS, acDisplayDCS, 0)
End Function
Function WToD(Pt As Variant) As Variant
    WToD = ThisDrawing.Utility.TranslateCoordinates(Pt, acWorld, acDisplayDCS, 0)
End Function

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Camera point.
« Reply #17 on: September 22, 2006, 09:35:52 PM »
The camera point is still eluding me. I've tried everything I can think of.
The camera pt ,view center and target are all on the line of sight, (so on viewdiection vector  through the center.)
The camera point is a vector made by scaling the target along the view direction by the length from the target to the camera point.
This length from zero to the viewdir point is the length from target to the camera point, so we are good to go?
Nope viewdir doesn't update. Acad help:
Quote
VIEWDIR System Variable                                                                                         
 Stores the viewing direction in the current viewport expressed in UCS coordinates.
This describes the camera point as a 3D offset from the target point
The camera length is related to the screensize, it changes with resolution, changing the size of the command  line or the properties window. It changes with zoom but not pan. It is falsely updated with the view toolbar (Eg it will read 0,0,1 instead of 0,0,28) but does update with camera command or 3dorbit. Below gets close
Z = (dir(0) * (Wd + Ht) * 0.846553687811163) + Tar(0)
            Dist = (Z - Cen(0)) / dir(0)

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: acDisplayDCS matrix
« Reply #18 on: November 06, 2006, 09:17:50 PM »
I've had a think on this and I think you will have to do some lower level mojo to get what you want.
I think what's happening is while the view direction is stored as a vector, it is one of the last transformations in the graphics pipeline before displaying to screen. That vector is passed to a matrix for the graphics to rotate the scene just before mapping to the viewport/client area, this means it will never be changed nor does it need to, it has the rotation set and is probably normalised before use. What does change though is the view size, this is actually the viewing volumes' front clipping plane mapped to the window/viewport, pan moves the model around in the viewing volume and zoom changes it's size (note the view width and heights in the view dlg after a zoom), all else outside the volume is clipped away. I had to do exactly this with a little app that I posted here -> http://www.theswamp.org/index.php?topic=13229.0

Now, given this info you would have to find out the view centre, draw a line along the view direction vector from there and find the intersection of this line and say the ucs plane to find the actual camera position in space. This means you can grab the new target and the view size, rotate the view vector and calc the new camera position...in theory anyway :)
Does that make sense?

I'll think on it more as I also need this to fine tune some viewing tools I'm working on, hope it helps.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Bryco

  • Water Moccasin
  • Posts: 1883
Re: acDisplayDCS matrix
« Reply #19 on: November 06, 2006, 11:04:56 PM »
Mick, the view center is on the ucs plane. I have viewctr and target worked out, I guess why I want the camera point is that it must hold the key to some weird number I need for a view matrix. I'm just not sure where to aim for. The view matrix I have made prints out the same as the cad view ucs one but doesn't quite work for angled views. Basically I'm trying to draw diagonal lines to show the screen dimensions and they end up with  some weird offset that I cant figure out. I start by drawing the lines in modelspace using the viewctr, Screensize and viewsize to get widths and hts. Then use the matrix to transform the lines. I'ld post the code but I know you don't use vba.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: acDisplayDCS matrix
« Reply #20 on: November 06, 2006, 11:07:12 PM »
On another note, that little app of yours is cool.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: acDisplayDCS matrix
« Reply #21 on: November 06, 2006, 11:35:13 PM »
Perhaps someone will give this a go and get the ball rolling. Add it to a module and run the DrawViewDiagonals sub. Change the isoviews and run it, then 3d orbit views etc.