Author Topic: acDisplayDCS matrix  (Read 3956 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1850
acDisplayDCS matrix
« on: September 04, 2006, 08:08:53 PM »
This is a tricky one to track down.
I've got as far as the Z axis or normal is the viewdir-ucsorg normalised.
I then used the  arbitrary axis algorithm to create the x-direction and y-direction
Then use the ucsorg for the translating part.
Unfortunately this doesn't compare with the ucsmatrix when the ucs is set to view.
The Z and translation are the same but the x and y fail.
The getvar viewctr translated to wcs seems to be same as the vba viewport.center but has  a z value.
So I'm not quite sure if there is a point available to create a plane. Even then I'm not sure how make an x axis, perhaps it is a unit vector that goes along the viewtwist angle.
As for target, I cant believe how stingy the help is on that one.

Thanks in advance for help on this one.

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #1 on: September 04, 2006, 08:24:43 PM »
I'm not quite sure what you want to do, do you want to create a plane/ucs based on the current view?
Remember though that the view direction vector does not necessarily point to the ucsorg a vector has no real location, only direction and length. Given the viewdir vec the AAAlgo should work fine.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #2 on: September 04, 2006, 08:32:24 PM »
Quote
create a plane/ucs based on the current view?
Yes to that. Mick I have been  replacing the translation functions with my own and got stuck on both the acDisplayDCS translation and the current view matrix

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #3 on: September 04, 2006, 08:43:51 PM »
What do you need to tranlate and in which direction.
I'm guessing this is for viewport alignment or similar?
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #4 on: September 04, 2006, 08:59:43 PM »
It'll end up that way. I've been having a hard time getting the grip of views. I seem to get close then lose it.
The viewtwist doesn't help.
I started writing a sub to add 2 diagonal lines across the screen.
I can do this by translating the 4 points but cant seem to make a reliable 4x4 matrix to use transform by.
Making a ucs matrix with ucsxdir and ucsydir is easy but the view matrix is a bit confusing.
As I said I have the z just need the x

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #5 on: September 04, 2006, 09:11:56 PM »
What you need is the 'camera' position and ocs. I'll have a look at the arx help to see what turns up.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #6 on: September 04, 2006, 09:18:27 PM »
Thanks Mick, Its odd how they give the target but not the camera.

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #7 on: September 04, 2006, 09:27:25 PM »
looking at the vba help, the view centre is what you need only it gives it to you as a 2d point (as you said).
You should be able to calculate the z value of the view centre from the target point using trig with the angle of the vector etc. and the 2d centre point.
Then to get an xvec, if your view doesn't have any twist you can use the wcs z vector to create your axes.
xvec = viewdir crossproduct(wcs.zvec);
yvec = viewdir crossproduct(xvec);
or reversed if you want the matrix with z pointing away from camera.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #8 on: September 04, 2006, 09:52:00 PM »
I'll give that a go, but the target point only seems to line up with the view center  only when you use 3dorbit as in the view is normal to the ucs. I cant really say what it is. Using the wcsZ vector is what I have done and it didn't give the right answer. Actually I use below
Code: [Select]
Function GetOcsFromNormal(N As Variant) As Variant
    'N is the normal vector.
    'Wy is the world Y axis, which is always (0,1,0).
    'Wz is the world Z axis, which is always (0,0,1).
    Dim Wy(2) As Double
    Dim Wz(2) As Double
    Dim Nx As Double, Ny As Double
    Dim Ax, Ay, Ocs(1) As Variant
   
    N = NormaliseVector(N)
    Wy(0) = 0: Wy(1) = 1: Wy(2) = 0
    Wz(0) = 0: Wz(1) = 0: Wz(2) = 1
    Nx = N(0): Ny = N(1)
    If (Abs(Nx) < 1 / 64) And (Abs(Ny) < 1 / 64) Then
         'Ax = Wy X N (where “X” is the cross-product operator).
         Ax = Crossproduct(Wy, N)
    Else
         Ax = Crossproduct(Wz, N)
    End If

    Ocs(0) = NormaliseVector(Ax)
 
    Ay = Crossproduct(N,Ax)   'edit-had this wrong

    Ocs(1) = NormaliseVector(Ay)
    GetOcsFromNormal = Ocs

End Function
and perhaps I need to use the z value
« Last Edit: September 06, 2006, 12:26:57 AM by Bryco »

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #9 on: September 06, 2006, 12:45:19 AM »
Forgot that the x-axis must be horizontal.
It works out the GetOcsFromNormal function gives a correct answer but the x and y vectors need to be rotated by minus the viewtwist amount around the z (viewdir). I have a matrix that does that, rotates around a vector that I adapted to vba but couldn't possibly work out myself.But it seems like a it could be done with a little less math.
Anyway I can at least match a view ucs matrix now.

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #10 on: September 06, 2006, 01:06:04 AM »
nice one.
The simplest way to rotate around a vector is to move the ucs so that the vector is the z axis (rotation axis), it doesn't matter which way the x and y are pointing as long as they're still orthoganal as you are only rotating around the z axis by a given amount regardless.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #11 on: September 10, 2006, 01:13:37 PM »
To use this matrix I still need to find some magic number.
I think it is tied into the center of the 3d view mentioned in acad help
Quote
When the 3DORBIT command is active, the default target location is the center of the 3D view, which is not always the center of the objects you are viewing
Whatever that is.
« Last Edit: September 10, 2006, 01:14:55 PM by Bryco »

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #12 on: September 10, 2006, 04:18:23 PM »
Here is an example of the confusion I'm having.
Run this sub then run the 3dorbit command.
The aim is to find the center of the 3dorbit,
 It works great for a while.
Run it again and it's no good.
Code: [Select]
Sub OrbitCenter()
    Dim C, T, O, P As AcadPoint
    Dim Util As AcadUtility
   
    Set Util = ThisDrawing.Utility
    ThisDrawing.SetVariable "PDSIZE", 0.5
    ThisDrawing.SetVariable "PDMODE", 35
    C = ThisDrawing.GetVariable("viewctr")
    C = Util.TranslateCoordinates(C, acUCS, acWorld, 0)

   
    T = ThisDrawing.GetVariable("target")
    T = Util.TranslateCoordinates(T, acUCS, acWorld, 0)
   
    Set P = ThisDrawing.ModelSpace.AddPoint(C)
    P.color = acGreen
    Set P = ThisDrawing.ModelSpace.AddPoint(T)
    Dim dMid(2) As Double
    dMid(0) = (C(0) + T(0)) / 2
    dMid(1) = (C(1) + T(1)) / 2
    dMid(2) = (C(2) + T(2)) / 2
   
    Set P = ThisDrawing.ModelSpace.AddPoint(dMid)
    P.color = acYellow
    ThisDrawing.ModelSpace.AddLine C, T

End Sub

In a new drawing the target getvar is 0,0,0
type camera and
Command: ca CAMERA Specify new camera position <6.0000,4.8571,18.3799>: 
Specify new camera target <6.0000,4.8571,0.0000>:  Regenerating model.
Since I'm in an inch dwg the x and y values are the center of the  limits (12,9) (I presume the actual number varies with resolution).
A new target value seems to start with the old z value and take the screen center x and y.
But where does the 18.3799 come from?

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: acDisplayDCS matrix
« Reply #13 on: September 10, 2006, 06:23:38 PM »
Yep, that's a hard one. The view target probably gets transformed when zooming in and out and panning with an internal function so really you will never know where the target will be unless you ask for it or give it to your function (perhaps by giving it the centre of your geometry's bounding box). Notice that while zooming using the mouse wheel and moving the mouse it also pans which effectively moves the target.
ie, I think the target moves with the camera unless you are zooming which then moves the target away, 'tis a triicky one without seeing how it ticks. Maybe worth a look at seeing if that is indded what happens??
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Bryco

  • Water Moccasin
  • Posts: 1850
Re: acDisplayDCS matrix
« Reply #14 on: September 10, 2006, 06:56:23 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.
The target in the camera command does update as you know.
So far the z value seems to be something like 0.52855 times the viewsize, I havent related that to twisted views yet.