PDA

View Full Version : Coordinate System Measurements


docaberle
05-19-2009, 03:50 PM
I'm trying to get x,y values from a set of vertexes on an object as the object animates via 4x4 ffd, but I want the x,y values to be referenced from the camera viewport, not 3ds max's xyz system. I will use maxscript to get these values somehow because I'll be getting about 50 x,y values for each frame and then there's 100 to 150 frames.

This might sound crazy, but I'll be importing these values into Adobe Flash for animated reference points to place movieclips at the points. I have other 3ds video that will have the same camera view, hence I need the xy points from the camera view.

Is this an easy task or complicated? What would code even come close to looking like?

DaveWortley
05-19-2009, 04:12 PM
There was a topic not too long ago with something similar. A place to start would be looking at GetViewTm() for the transformation matrix of the viewport. It's not massively simple to do what you want to I'm affraid but have a search I think someone wanted to do something very similar.

SyncViewS
05-19-2009, 04:40 PM
Hi Jeffrey,
you can take a look at Practical Space Mapping for interaction (http://www.illusioncatalyst.com/mxs.php), an article about how to express values in different Coordinate Systems. I guess you need verts world position expressed in screen pixels. I hope it helps.

- Enrico

docaberle
05-20-2009, 02:16 AM
Hello Enrico,
I have studied your:
Space mapping: WorldCS —> GridCS / WorldCS —> ScreenCS
and am a little confused.

The last line:
p2PointScreenPos = [ceil(gw.transPoint p3PointWorldPos).x, ceil(gw.transPoint p3PointWorldPos).y]
What is the reference point. I run the maxscript but the x,y value that max returns I can't make sense of because I don't know the origin. I'm looking for a simple way to have a helper point as a reference say in the upper left hand corner of a viewport. Then have another helper somewhere else in the viewport that has an x,y value relative to the reference. x and y would both be positive with the reference in the upper left hand corner.

I will be happy to pay if needed. We all need to make a living.

Thanks,
Jeff Aberle

Bobo
05-20-2009, 02:30 AM
See the MAXScript Reference > How To ... Develop a Vertex Renderer

SyncViewS
05-20-2009, 09:17 AM
Hi Jeff,
here is a code sample to show the procedure: it creates a box in the scene, converts it to an Editable Poly, then cycles over its verts and takes their position in world space 3D coordinates, then converts them in screen space 2D coordinates relative to current viewport upper left corner. It then stores them in an array and shows it in the listener after the whole process. if you need to export such data take a look at "FileStream" too, to create and fill a text file and to "Format" options to create a string for import. You may want to look at "at time" context to make your script work on an animation range, but it has to tested, I'm not sure it works when dealing with viewport changes.

(
oPoly = convertToPoly(Box())

local iNumVerts = polyOp.getNumVerts oPoly

gw.setTransform (Matrix3 1)

local p3PointWorldPos = [0,0,0]
local p2PointScreenPos = [0,0]

local ap2PointScreenPos = #()
ap2PointScreenPos[iNumVerts] = [0,0]

for iVert = 1 to iNumVerts do
(
p3PointWorldPos = polyOp.getVert oPoly iVert
ap2PointScreenPos[iVert] = [ceil(gw.transPoint p3PointWorldPos).x, ceil(gw.transPoint p3PointWorldPos).y]
)

format "Points in Screen CS\nRelative to current viewport upper left corner:\n"

for p2Pos in ap2PointScreenPos do
format "%\n" p2Pos
)
If you got an Editable Mesh, the code is the same, just use meshOp:

p3PointWorldPos = polyOp.getVert PolyObject iVertIndex
-- becomes:
p3PointWorldPos = meshOp.getVert MeshObject iVertIndex
- Enrico

CGTalk Moderation
05-20-2009, 09:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.