Results 1 to 6 of 6

Thread: [RESOLVED] hi im having trouble converting frrom 2d screen coordinates to local coordinates

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Resolved [RESOLVED] hi im having trouble converting frrom 2d screen coordinates to local coordinates

    hi im not sure where to put this.
    these are my local coordinates of 1 of my triangle points
    Code:
         With ONEobject
         .LocalCoord(0).X = -1
         .LocalCoord(0).Y = -0.5
         .LocalCoord(0).z = 2.5
         End With
    and this is how project the 3d coordinats on to a 2d plane
    Code:
    Private Sub LocaltoScreen()
      
      Dim lngIncr   As Long         'counter
      Dim tempcoord As Point3d      'buffer to hold temporary converted coordinates
      
        With ONEobject
            For lngIncr = 0 To .NumVertices
                'converts local coordinates into world ones relative to the supplied Canvas
                tempcoord.X = .rotatedLocalCoord(lngIncr).X + .CenterofWorld.X
                tempcoord.Y = .rotatedLocalCoord(lngIncr).Y + .CenterofWorld.Y
                tempcoord.z = .rotatedLocalCoord(lngIncr).z + .CenterofWorld.z
                'now we project the 3d coordinats on to a 2d plane with perspective
                .ScreenCoord(lngIncr).X = (tempcoord.X * HPC / tempcoord.z) + HCW
                .ScreenCoord(lngIncr).Y = (-tempcoord.Y * VPC * ASPECT_COMP / tempcoord.z) + HCH
            Next '  LNGINCR
        End With 'ONEobject
     
    End Sub

    using my mouse i will add three points to the screen ,how do i turn these screen coordinats
    into local coordinats or is there a better way other than local coordinats?
    thanks

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: hi im having trouble converting frrom 2d screen coordinates to local coordinates

    That's not a true reversible action, mapping a point from 2D-Screen-Coords-Space back exactly into the 3D-World.
    At least not "with a single click" (if there's no sufficient side-condition defined).

    This first "single click" in your Screen-View to position something new in 3D-Space, can only make
    "reasonable guesses" (e.g. finding the next nearest already defined objects or points in the surroundings
    of the area you clicked - and then calculate a "near average" for x, y and z of the surrounding nearest
    objects or points - and then derive the "depth-info" for your new point from that average.

    To "elevate" the placement of your new point to an exact operation (so far, you have only a "good guess"
    about the correct depth - you could rotate the current view e.g. about 90Degree horizontally - and then
    correct the point you've just set.

    Or instead of such a manually accomplished (per extra-click) "follow-up-rotation", you could additionally
    offer a second, always visible view onto the scene (kinda like a Stereo-View) - and then e.g. make your
    click in one view - and correct it in the other (or vice versa).

    Olaf

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: hi im having trouble converting frrom 2d screen coordinates to local coordinates

    You could try PMing Jacob Roman to this thread. He should have experience dealing with this sort of thing since he writes a lot of game related stuff.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: hi im having trouble converting frrom 2d screen coordinates to local coordinates

    hey
    im making a 3d Model Maker if it works out.
    schmidt your saying make different views then?

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: hi im having trouble converting frrom 2d screen coordinates to local coordinates

    Quote Originally Posted by flyhigh View Post
    hey
    im making a 3d Model Maker if it works out.
    schmidt your saying make different views then?
    Only if you need that in a fashion, which requires to position single points accurately.
    There's just no exact placement of a 3D-Point possible from a 2D-ScreenView-Coordinate -
    not enough info "to hang onto".

    If it's only thought for a Designer (beaming new, complete Objects into the 3D-Space),
    then one approach could be, to place the center of the new Object exactly at the
    Center of your World - or at whatever "central 3D-place" makes sense at that point -
    and *that*could be accomplished with a simple MouseAction - you could then move
    the Object from this central WorldPoint the User always expects it to shine up, to
    different places in the World - along with Rotations around the internal Center,
    (using the local-Coord-System of your newly placed 3D-Object) you should be able
    to place it exactly where it needs to end-up in the scene.

    So, what I mean is a bit similar to the VB6-IDE-behaviour, when you DoubleClick
    at a Control-Icon in the Selector-Panel.
    In this case you also don't give a specific position for the Control on the Destination -
    the new Control will just end up centered on the Form - a place you expect it to shine
    up - then you move it from there (e.g. using <Ctrl>+<ArrayKeys>).

    Just trying to make the principle more clear, which you could follow in your UI.

    Olaf
    Last edited by Schmidt; Mar 7th, 2014 at 08:13 PM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: hi im having trouble converting frrom 2d screen coordinates to local coordinates

    thank yall

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width