Reply
Contributor
13 Posts
9 Kudos

Orbit, zoom, pan fundamental viewport controls

60 Views, 2 Replies
2 weeks ago

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();
}

 

Explorer
2 Posts
1 Solution

Re: Orbit, zoom, pan fundamental viewport controls

2 weeks ago 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

Highlighted
Contributor
13 Posts
9 Kudos

Re: Orbit, zoom, pan fundamental viewport controls

2 weeks ago in reply to: JakobczakMarek

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