Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Orbit, zoom, pan fundamental viewport controls

2 REPLIES 2
Reply
Message 1 of 3
pravdomil
560 Views, 2 Replies

Orbit, zoom, pan fundamental viewport controls

Hello there I'm working on new input device to work with Fusion 360 via 3rd Addins.

And I'm searching for implementation of fundamental viewport controls (pan, zoom, orbit) in C++.

Does anybody have some idea how to do that? This is my code that does not work 😞

void orbit(Ptr& screenCoordinateCenter, double deltaX, double deltaY) {
    Ptr camera = app->activeViewport()->camera();
    camera->isSmoothTransition(false);
    
    Ptr eye = camera->eye();
    eye->x(eye->x() + deltaX);
    eye->y(eye->y() + deltaY);
    camera->eye(eye);
    
    app->activeViewport()->camera(camera);
    app->activeViewport()->refresh();
}

void pan(double deltaX, double deltaY) {
    Ptr camera = app->activeViewport()->camera();
    camera->isSmoothTransition(false);
    
    Ptr eye = camera->eye();
    eye->x(eye->x() + deltaX);
    eye->y(eye->y() + deltaY);
    camera->eye(eye);
    
    Ptr target = camera->target();
    target->x(target->x() + deltaX);
    target->y(target->y() + deltaY);
    camera->target(target);
    
    app->activeViewport()->camera(camera);
    app->activeViewport()->refresh();
}

 

2 REPLIES 2
Message 2 of 3
JakobczakMarek
in reply to: pravdomil

Hello,

 

try this: simple move based on your code, I thing this is not bad point to start.

 

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>

using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;

Ptr<Application> app;
Ptr<UserInterface> ui;



void orbit(Ptr<Camera> screenCoordinateCenter, double deltaX, double deltaY)
{
    Ptr<Camera> cam = screenCoordinateCenter;
    cam->isSmoothTransition(false);
    
    Ptr<Point3D> eye = cam->eye();
    eye->x(eye->x() + deltaX);
    eye->y(eye->y() + deltaY);
    cam->eye(eye);
    
    app->activeViewport()->camera(cam);
    app->activeViewport()->refresh();
}

void pan(double deltaX, double deltaY) {
    Ptr<Camera> cam = app->activeViewport()->camera();
    cam->isSmoothTransition(false);
    
    Ptr<Point3D> eye = cam->eye();
    eye->x(eye->x() + deltaX);
    eye->y(eye->y() + deltaY);
    cam->eye(eye);
    
    Ptr<Point3D> target = cam->target();
    target->x(target->x() + deltaX);
    target->y(target->y() + deltaY);
    cam->target(target);
    
    app->activeViewport()->camera(cam);
    app->activeViewport()->refresh();
}

void delay(int val)
{
    for(int i = 0; i < val; ++i)
    {
        for(int k = 0; k < val; ++k)
        {
            ;
        }
    }
}

extern "C" XI_EXPORT bool run(const char* context)
{
	app = Application::get();
	if (!app)
		return false;

	ui = app->userInterface();
	if (!ui)
		return false;

    ui->messageBox("About to start...");
    
    Ptr<Camera> camera1 = app->activeViewport()->camera();
    
    double x = 0;
    double y = 0;
    for(int i = 0; i < 90; ++i)
    {
        orbit(camera1, x, y);
//        delay(10);
        x += 1.0;
        y += 1.0;
    }
    
	ui->messageBox("Done");

	return true;
}

Goodluck.

Marek

Message 3 of 3
pravdomil
in reply to: JakobczakMarek

Well try pan function, when you rotate camera it no longer goes in the same direction.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report