Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
pravdomil committed Apr 14, 2017
0 parents commit 448a40a
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/NativeTrackpad.build
/NativeTrackpad.dylib
/NativeTrackpad.xcodeproj/project.xcworkspace/xcuserdata
/NativeTrackpad.xcodeproj/xcuserdata
14 changes: 14 additions & 0 deletions NativeTrackpad.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"autodeskProduct": "Fusion360",
"type": "addin",
"author": "",
"description": {
"": ""
},
"supportedOS": "mac",
"editEnabled": true,
"id": "a4597288-1620-4f08-9f0f-1b349b92d841",
"version": "",
"runOnStartup": false,
"sourcemac": "NativeTrackpad.xcodeproj"
}
114 changes: 114 additions & 0 deletions NativeTrackpad.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

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

#include <math.h>

#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>

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

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

void orbit(/*Ptr<Point2D>& screenCoordinateCenter, */double deltaX, double deltaY) {
Ptr<Camera> camera = app->activeViewport()->camera();
camera->isSmoothTransition(false);

Ptr<Point3D> eye = camera->eye();
eye->x(eye->x() + deltaX);
eye->y(eye->y() + deltaY);
camera->eye(eye);

app->activeViewport()->camera(camera);
app->activeViewport()->refresh();
}

Ptr<Vector3D> getViewportCameraUpVector() {
return app->activeViewport()->camera()->upVector();
}

Ptr<Vector3D> getViewportCameraRightVector() {
auto camera = app->activeViewport()->camera();

auto right = camera->upVector();

auto rotation = Matrix3D::create();
auto axis = camera->eye()->vectorTo(camera->target());
rotation->setToRotation(M_PI / 2, axis, Point3D::create(0, 0, 0));
right->transformBy(rotation);

return right;
}

void panViewportCameraByVector(Ptr<Vector3D> vector) {
auto camera = app->activeViewport()->camera();
camera->isSmoothTransition(false);

auto eye = camera->eye();
eye->translateBy(vector);
camera->eye(eye);

auto target = camera->target();
target->translateBy(vector);
camera->target(target);

app->activeViewport()->camera(camera);
app->activeViewport()->refresh();
}

void pan(double deltaX, double deltaY) {
auto right = getViewportCameraRightVector();
right->scaleBy(deltaX);

auto up = getViewportCameraUpVector();
up->scaleBy(deltaY);

right->add(up);

panViewportCameraByVector(right);
}

void install() {
NSEvent * (^handler)(NSEvent*);
handler = ^NSEvent*(NSEvent* event) {
if(event.modifierFlags & NSEventModifierFlagShift) {
orbit(event.scrollingDeltaX, event.scrollingDeltaY);
return nil;
}

if(event.modifierFlags & NSEventModifierFlagOption) {
pan(event.scrollingDeltaX, event.scrollingDeltaY);
return nil;
}

return event;
};
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel handler:handler];
}

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

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

int i = 0;
while (i++ < -1) {
pan(1, 1);
nanosleep((const struct timespec[]){{0, 500000000L}}, NULL);
}

install();

return true;
}

extern "C" XI_EXPORT bool stop(const char* context) {
return true;
}
Loading

0 comments on commit 448a40a

Please sign in to comment.