How focus a JavaFX Group properly and set the pivot (reverse) by using translations in 3D space?

Description:

I m referring to the Oracle tutorial http://docs.Oracle.com/JavaFX/2/transformations/jfxpub-transformations.htm using the transformations.zip source code, which is available for download on this page. I Don t understand why they Center the xylophone in space 3D like this and why they calculate the pivot (reverse) using translations. So they are creating a large number of groups, including rectangles, representing the xylophone, in addition to finally to a group called "cam".    

class Cam extends Group {     
     Translate t  = new Translate();     
     Translate p  = new Translate();     
     Translate ip = new Translate();     
     Rotate rx = new Rotate();     
     { rx.setAxis(Rotate.X_AXIS); }     
     Rotate ry = new Rotate();     
     { ry.setAxis(Rotate.Y_AXIS); }     
     Rotate rz = new Rotate();     
     { rz.setAxis(Rotate.Z_AXIS); }     
     Scale s = new Scale();     
     public Cam() { 
          super(); getTransforms().addAll(t, p, rx, rz, ry, s, ip); 
     }     
}    

final Cam camOffset = new Cam();    
final Cam cam = new Cam();    
...    
camOffset.getChildren().add(cam);    
...    
final Scene scene = new Scene(camOffset, 800, 600, true);    
... 

The Group "cam" is added to another group called "camOffset", which is added to the 'scene' as root the node.

Until there , everything is understandable to me, but there is a method, called "frameCam (.)" which calls 4 other methods: ""

public void setCamOffset(final Cam camOffset, final Scene scene) {         
     double width = scene.getWidth();         
     double height = scene.getHeight();         
     camOffset.t.setX(width/2.0);         
     camOffset.t.setY(height/2.0);     
}    

//=========================================================================    
// setCamScale    
//=========================================================================    

public void setCamScale(final Cam cam, final Scene scene) {        
     final Bounds bounds = cam.getBoundsInLocal();         
     final double pivotX = bounds.getMinX() + bounds.getWidth()/2;         
     final double pivotY = bounds.getMinY() + bounds.getHeight()/2;         
     final double pivotZ = bounds.getMinZ() + bounds.getDepth()/2;         
     double width = scene.getWidth();         
     double height = scene.getHeight();         
     double scaleFactor = 1.0;         
     double scaleFactorY = 1.0;         
     double scaleFactorX = 1.0;         
if (bounds.getWidth() > 0.0001) {            
     scaleFactorX = width / bounds.getWidth(); // / 2.0;        
}        
if (bounds.getHeight() > 0.0001) {            
     scaleFactorY = height / bounds.getHeight(); //  / 1.5;         
}        
if (scaleFactorX > scaleFactorY) {            
     scaleFactor = scaleFactorY;         
} else {            
     scaleFactor = scaleFactorX;         
}        
     cam.s.setX(scaleFactor);         
     cam.s.setY(scaleFactor);         
     cam.s.setZ(scaleFactor);     
}    

//=========================================================================    
// setCamPivot    
//=========================================================================    

public void setCamPivot(final Cam cam) {        
     final Bounds bounds = cam.getBoundsInLocal();         
     final double pivotX = bounds.getMinX() + bounds.getWidth()/2;         
     final double pivotY = bounds.getMinY() + bounds.getHeight()/2;        
    final double pivotZ = bounds.getMinZ() + bounds.getDepth()/2;         

//*1*        
     cam.p.setX(pivotX);         
     cam.p.setY(pivotY);         
     cam.p.setZ(pivotZ);         
//*1*        

//*2*        
     cam.ip.setX(-pivotX);         
     cam.ip.setY(-pivotY);         
     cam.ip.setZ(-pivotZ);         
//*2*     }    

//=========================================================================    
// setCamTranslate    
//=========================================================================    

public void setCamTranslate(final Cam cam) {        
     final Bounds bounds = cam.getBoundsInLocal();         
     final double pivotX = bounds.getMinX() + bounds.getWidth()/2;         
     final double pivotY = bounds.getMinY() + bounds.getHeight()/2;         
     cam.t.setX(-pivotX);         
     cam.t.setY(-pivotY);     
} 

If the method ' setCamScale (...) 'is understandable,' setCamOffset (...) ' puts the root node ('camOffset') in the center of the screen, but I Don t understand the 2 following methods at all. Of course, the child ("cam") is not centered, by putting just the root node ('camOffset') in the center of the screen, but how they focus the xylophone / "cam" and set the pivot, using translations:

Questions:

  1. Why they use 3 different translations (', 'ip', 'p')?
  2. Referring to ' setCamPivot (...) ': Why they are the first translation of 'cam.p' to "pivotX", 'pivotY' and 'pivotZ' and then 'cam.ip' to '-pivotX', '-pivotY' and '-pivotZ' (marked in the source code with * 1 * and * 2 *)? Should he not just put the Group at his position, where it has been positioned before, as if the method has never been called? That would be my guess, because I expect that an object is placed in the same position as before, if I first move with the values X, Y, Z and then return with the same values - X, - Y, - Z in the opposite direction.
  3. Even with the method ' setCamTranslate (...) ' ': Why use another translation "cam.t", moving the Group ("cam") with the same values "-pivotX', '-pivotY' (and not '-pivotZ'), which they used in the"setCamPivot (...) method `?

Annotations:

Of course it works, the xylophone is located in the center of the screen and could turn perfectly, without change of rotation point / pivot point, but I Don t understand how they did it. I read everything about layoutBound, boundsInLocal, boundsInParent, blogs about page layout and page layout goes into javaFX https://blogs.oracle.com/jfxprg/entry/the_peculiarities_of_javafx_layout and http://amyfowlersblog.wordpress.com/2011/06/02/javafx2-0-layout-a-class-tour/ and finally a large number of questions to stackoverflow, but I still Don t understand the meaning behind the methods stated.

Before the call of ' frameCam (...) ', they ask:

double halfSceneWidth = 375;  // scene.getWidth()/2.0;     
double halfSceneHeight = 275;  // scene.getHeight()/2.0;    
cam.p.setX(halfSceneWidth);    
cam.ip.setX(-halfSceneWidth);    
cam.p.setY(halfSceneHeight);    
cam.ip.setY(-halfSceneHeight); 

I deleted these lines, because it doesn't change anything.

The base in place, is that there are three defined different rotations, one around each axis. Of course, these could be combined into a single rotation, but doing so would make the geometry in the mouse dragging very complex managers. As it is, the degree of rotation around each axis can be calculated and changed independently.

In general, the rotations are defined by an angle, an axis and a (pivot) point. The axis is a 3D vector and goes through the pivot point; the rotation is around this axis through that point.

In the configuration in the example, the pivot of each of the individual rotations is set to the default (0,0,0). Because we really want the rotation to be around the center of the group, not the original, the Group translates first point appropriate pivot (ip), the rotations are applied then (around (0,0,0) after translation by ip), then the group is reflected in its location of origin (p). These operations are not commutative, yes show ip, then the rotation, then p is not the same as when you run ip, then p, then the rotation (in the second, ip and p would cancel and rotation would be about (0,0,0) instead of around the Center).

For good measure, there is a scale, that is also applied after ip (so that scaling occurs from the Center, not the original) and then a final translation.

The final effect is that there is a lot of transformations that can be controlled independently. There is a scale (s), a rotation about each axis (rx, ry, rz), and a translation (t). The p in translations and its inverse ip are just "housekeeping" to ensure that rotation and scaling are done from the center of the screen, instead of (0,0,0).

So:

  1. Why they use 3 different translations (', 'ip', 'p')?

p and ip are translations for the rotation and scaling are done from the Center and not to the origin. t is a general translation, the user sees.

Referring to ' setCamPivot (...) ': Why they are the first translation of 'cam.p' to "pivotX", 'pivotY' and 'pivotZ' and then 'cam.ip' to '-pivotX', '-pivotY' and '-pivotZ' (marked in the source code with * 1 * and * 2 *)? Should he not just put the Group at his position, where it has been positioned before, as if the method has never been called?

He puts the group to its original position, but other changes are between p and ip. These transformations behave differently (in a planned way) because the group is translated when they are applied.

Even with the method ' setCamTranslate (...) ' ': Why use another translation "cam.t", moving the Group ("cam") with the same values "-pivotX', '-pivotY' (and not '-pivotZ'), which they used in the"setCamPivot (...) method `?

The t values are changed in the mouse Manager (with alt-middle mouse button-drag, which I can't test actually using my trackpad...). As you have noted, the effect of p and IP translation cancel out, so we end up with t, which can be changed by the user. They could have combined t and p a single transformation, but updated since the mouse Manager would have been more delicate, and the intent of the code would be less clear.

Tags: Java

Similar Questions

  • How to create a default domain and deploy the app in jdeveloper using a script or code (not manually)

    Hello

    I installed Jdev using silent installation.

    Now I have some apps already created I want to create a default domain, and then to deploy apps in it through any script or ants?

    Can someone help me on this?

    Thank you and best regards,

    Vivek Pemawat

    Hi This worked for me I checked the log of the jdev, how he creates the domain and then using that I created the field

    I used the python script for deploying applications:

    Connect ('weblogic', 'welcome1 ','slc01fnw:7103 ')

    deploy (appName = ' Application13 ', path='/home/rasubra/jdeveloper/mywork/Application13/deploy/Application13_Project1_Application13.ear' target = 'DefaultServer')

    Exit()

    called using wlst.sh TestAppsDeploy.py

    Thanks for all the help!

  • How to get and set the length and the width of the content of the layer?

    How to get and set the length and the width of the content of the layer

    All layers are packed not equal. a layer as adjustment have no limits. Layer to smart object can have two different sizes. The size of the object and the size of the object may be transformed. All smart object layers have an associated transform. To transform a smart object layers you need to work with the size of the object the generated pixels fot the layer. Text layer can be resized with a transform or by changing the font size. Pixelated layers are resize via a transformation.  The script method is resize.  When you resize the number of pixelsits made by interpolation. You can specify what method to use or set Photoshop interpolation preferably by default.

    There is also a bug in Photoshop scripts if you pause the story said make a selection and use resize. Photoshop will properly support up to a State before where you suspended history. This bug seems to be in all versions of Photoshop.

    If you look ate the script in my bug report, you should get a good idea of how to resize a layer.

    Photoshop: Bug Script resize the rear paper folded to a history State

  • How can I enter BIOS compaq610 screen and set the date, time

    How can I enter BIOS compaq610 screen and set the date, time

    Hello

    See Page 94 or Page 100 (according to what's relevant) of your & Maintenance Guide.

    Kind regards

    DP - K

  • HI, how can I scan a picture and only the witout the rest. On a HP Officejet Pro 8600 Plus?

    HI, how can I scan a picture and only the witout the rest. On a HP Officejet Pro 8600 Plus?

    When I scan I got my photo and all white for the rest of the screen

    It has no function of machine harvest in the 8600 software. To get the exact size, you will need to manually set the size for the scans that you do. You can find the setting by clicking on the blue link to advanced settings in the first scan window. Will take you to a place that will allow you to change the size of the scanning area. Hope that helps.

  • Create bookmark and set the Page Destination Script

    Greetings,

    I created a batch Script that will create children bookmarks and set the destination page.

    Bookmarks are listed in the script in the order in which they appear in ascending order.  (for example, Name1, name2, Name3, name4)

    However, once the script is run, the bookmarks are inserted in descending order. for example (Name3, name4, Name1, name2).

    Can someone advise please how do I get the script to create bookmarks in ascending order, as noted in the script?

    var bm =
    this.bookmarkRoot.createChild ("Name1", "this.pageNum = 0");
    this.bookmarkRoot.createChild ("Name2", "this.pageNum = 1");
    this.bookmarkRoot.createChild ("Name3", "this.pageNum = 2");
    this.bookmarkRoot.createChild ("Conjoint4", "this.pageNum = 3");

    var bm = this.bookmarkRoot.children [0];

    BM. Color = color.red;

    The script should also be changed to all bookmarks in red color.  The script for color bookmarks only works on the first bookmark.  Any intervention on changing the script for this would be most appreciated as well?

    Thank you.

    Use something like this:

    var bm;

    this.bookmarkRoot.createChild ("Bill Smith","this.pageNum = 0", 0);

    BM = this.bookmarkRoot.children [0];

    BM. Color = color.red;

    this.bookmarkRoot.createChild ("David Smith", "this.pageNum = 1", 1 ");

    BM = this.bookmarkRoot.children [1];

    BM. Color = color.red;

  • My 4th generation Apple TV installed an update and asked my password which he refused to accept time and time again. How to go beyond this screen and reset the unit?

    My 4th generation Apple TV installed an update and asked my password which he refused to accept time and time again. How to go beyond this screen and reset the unit?

    If she needs your Apple ID password and you have enabled 2-factor authentication, you might have to temporarily disable the connection to complete.

    Also, you need an internet connection to perform this step here.

    If your problem is not of the above, please describe more completely. Furthermore, to give specific messages on the screen.

  • How can I get my contacts and all the other stuff I had on the old email?

    Original title: I changed my email because they said my old email was invalid... How can I get my contacts and all the other stuff I had on the old email? They said, it has been deleted

    If my email isn't valid how I used it?

    Hello

    1. which email account you are referring to?

    2. What is the version of Windows installed on the computer? For example, Windows 7, Vista

    Please answer these questions and provide additional information so that we can better guide you.

  • How to install volume control program and retrieve the sound icon in the start bar

    How to install volume control program and retrieve the sound icon in the start bar

    He runs this Microsoft Fixit usually solves http://support.microsoft.com/kb/319095

  • Can any can give Live or online app Development on QNX IDE support and setting the goal as device Bb10. run the application etc?

    Can any can give Live or online app Development on QNX IDE support and setting the goal as device Bb10. run the application etc?

    The best way is to start basic: https://developer.blackberry.com/cascades/documentation/getting_started/index.html

  • Problem with burning Audio files to a blank CD error "Windows Media Player encountered an error when burning. Check that the burner is connected properly and that the disc is clean and not damaged"

    I recently burned music CD blank so I can enjoy some songs in the car. After that a few discs engraved with success, I received the message "Windows Media Player encountered an error when burning. Check that the burner is connected properly and that the disc is clean and not damaged"when trying to burn audio. To see if it was the m drive, I tried to burn audio files to four separate discs and each of them had the error message. The discs are brand new and have no information on them. I do something wrong or is my burner disconnected? Thanks for all your help and your support! I hope that we can find the cause of this problem so I can continue to make the CDs.

    Consumers concerned,

    Cody bridges

    Could you also confirm that it is playing the discs ok?

    Run the sfc tool and see if it shows anything... instructions here.

    http://support.Microsoft.com/kb/929833/en-us

  • Get and set the value to allow selected rolling Shuffle and facing page

    Hello world

    I work with the page and spread,

    For now, I want to value page spead shuffle and type of document.

    but I just find the function to get and set the value for the Document Pages allow Shuffle using the

    InterfacePtr < IPageLayoutPrefs > iPageLayoutPrefs (static_cast < IPageLayoutPrefs * > (: QueryPreferences (IID_IPAGELAYOUTPREFERENCES, iDocument)))

    It has no function to set and get the value of enable selected rolling Shuffle and facing page

    No one knows about it?

    I thank in advance

    There is no code for this example in the SDK or internet. Just understand and apply the concept.

    Find the code for the shuffle spread and together following spread shuffle...

    // Get active spread
    UIDRef GetActiveSpread() {
        UIDRef spreadRef = UIDRef::gNull;
    
        InterfacePtr layoutData(Utils()->QueryFrontLayoutData());
        if(layoutData) {
      spreadRef = layoutData->GetSpreadRef();
      }
    
      return spreadRef;
    }
    
    // Get spread shuffle of passed in spread
    bool16 GetSpreadShuffle(UIDRef& spreadRef) {
        InterfacePtr spread(spreadRef, UseDefaultIID());
        if(!spread)
      return kFalse;
    
      InterfacePtr iBoolData(spread, IID_IISLANDSPREAD);
        if(iBoolData) {
            return iBoolData->GetBool();
        }
    
        return kFalse;
    }
    
    // Set spread shuffle of passed in spread
    // @param bValue: kTrue = no shuffle, kFalse = allow shuffle
    ErrorCode SetSpreadShuffle(UIDRef spreadRef, bool16 bValue) {
        ErrorCode status = kFailure;
    
        InterfacePtr spreadCmd(CmdUtils::CreateCommand(kSetIslandSpreadCmdBoss));
        if(!spreadCmd)
            return status;
    
        spreadCmd->SetItemList(UIDList(spreadRef));
    
        InterfacePtr iBoolData(spreadCmd, UseDefaultIID());
        if(iBoolData) {
            iBoolData->Set(bValue);
        }
    
        status = CmdUtils::ProcessCommand(spreadCmd);
        return status;
    }
    
  • How can I uninstall adobe CD and reinstall the original adobe acrobat reader software

    How can I uninstall adobe CD and reinstall the original adobe acrobat reader software

    Sign out of your account... Uninstall... to run vacuuming...

    -non-Cloud programs, to disable the service before uninstalling

    -http://helpx.adobe.com/creative-cloud/help/install-apps.html (and uninstall)

    -using the vacuuming after uninstalling and before reinstalling is often necessary

    -https://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.html

    Download and install the old version by entering your serial number when required

    kglad links in response to #1 here can help https://forums.adobe.com/thread/2017859

  • I need something to smooth out grainy photos and set the color.  I have several photos that I need to use which has a blue cast on them.  Photoshop will remove the color blue?  I need an answer immediately.

    I need something to smooth out grainy photos and set the color.  I have several photos that I need to use which has a blue cast on them.  Photoshop will remove the color blue?  I need an answer immediately.

    Yes, photoshop can remove noise and remove color casts

  • How can I uninstall a computer and reinstall to a new computer using the same account?

    How can I uninstall a computer and reinstall to a new computer using the same account?

    Hello

    For uninstallation, please use the uninstall program: CC help | Uninstall the creative desktop application Cloud

    Please refer to the help documents below to download the application Adobe CC:

    Creative cloud to desktop

    Download, install, update or uninstall applications

    Kind regards

    Sheena

Maybe you are looking for