realbasic-nug
[Top] [All Lists]

Re: 2D Graphics: 2 or more objects moving relative to each other...

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: 2D Graphics: 2 or more objects moving relative to each other...
From: "Joseph J. Strout" <joe at strout dot net>
Date: Fri, 31 Mar 2006 08:28:14 -0700
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <6489b2020603301846x57e99c11ua07feb65ee0989c2 at mail dot gmail dot com> <a06200772c05255562f48 at 10 dot 0 dot 1 dot 2> <6489b2020603310426s2b02bafeh9db58fe91a876572 at mail dot gmail dot com>
At 7:26 AM -0500 3/31/06, Philip Regan wrote:

I would like for them to move parallel to each other. So, when the
user selects a group of objects, they move as a group in their same
positions relative to each other.

Ah. That should be a simple matter of deciding how the group is moving -- i.e., finding the dx and dy that you're going to add to every X and Y position -- and then simply adding it to the positions of all objects.

The math I cooked up to do this is (in awful psuedocode):

(Object(0).Orig(X, Y) - Object(0).New(X, Y)) + Object(n).(X, Y)

Er. This is trying to do too much at once. You must already have a dx and dy calculated somewhere; typically this is done in a MouseDrag event by something like:

  Dim dx as Integer = X - mLastMouseX
  Dim dy as Integer = Y - mLastMouseY
  if dx = 0 and dy = 0 then return  // mouse hasn't moved

Then, simply do something like:

  for i as Integer = 0 to UBound( Objects )
    Objects(i).X = Objects(i).X + dx
    Objects(i).Y = Objects(i).Y + dy
  next

HTH,
- Joe

--

Joseph J. Strout
joe at strout dot net
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>