Comments (4)
This sketch may help...especially the screenToWorld() method in the DwCoordinateTransform class. https://www.openprocessing.org/sketch/496458
from p5.easycam.
Wow... thank you very much... i'm diving into it to find my solution... in my own solution i could get the mouse position right when there was no rotation, but if i rotate the scene, 3d coordinates differ from mouse coordinates...
thanks again... i will check that right now :-)
from p5.easycam.
@jwdunn1
hi again dear james, well i tried to figure your project, but it was way different that p5.easycam... anyway i looked at your conversion method and they both looked identical algorithmically... i will post my code here, maybe i've missed something. thanks for your kind help:
the function getResultMouse is the main method... toRealProject(mx,my) get the mouse X and mouse Y position and produce a ray in that direction.. and the getRayPoint(ray) takes the ray and gives the amount of ray (t) where the ray meets a specific plane (here y=-100)... and then getResultMouse takes the ray and the t and gives out the answer... if i look forward ( i mean at (0,0,-1)) everything works great and as expected, but when i rotate the screen, there seems i'm missing something there as the projected vertice is not under mouse coordinates... please help me :-(
function toRealProject(mx,my)
{
let x=(2*mx)/width -1;
let y= 1- (2*my)/height;
let z=-1;
let vecRayClip=[x,y,z,1];
let PMatrix=RENDERER.uPMatrix.copy();
let invPM=matrix_invert(PMatrix);
let vecRayEye=multiply(invPM,vecRayClip);
let vecRayEyeNew=[vecRayEye[0],vecRayEye[1],-1,0];
let VMatrix=RENDERER.uMVMatrix.copy();
let invVM=matrix_invert(VMatrix);
let multEYEVM=multiply(invVM,vecRayEyeNew);
let w_inv = 1/multEYEVM[3];
let vecRayWorld=createVector(multEYEVM[0]*w_inv,multEYEVM[1]*w_inv,multEYEVM[2]*w_inv);
vecRayWorld.normalize();
return vecRayWorld;
}
function getRayPoint(ray) {
let normal = createVector(0,1,0);
let fixedpoint= createVector(0,-100,0); //seems this is better!!
let mousepos= mainCam.getPosition();
let denom = p5.Vector.dot(ray,normal);
let vecmf= p5.Vector.sub(fixedpoint,mousepos);
let nom= p5.Vector.dot(vecmf,normal);
return nom/denom;
}
function getResultMouse() {
let thisvecray=toRealProject(mouseX,mouseY);
let t=getRayPoint(thisvecray);
let tn=p5.Vector.mult(thisvecray,t);
let campos=createVector(mainCam.getPosition()[0],mainCam.getPosition()[1],mainCam.getPosition()[2]);
let answer= p5.Vector.add(campos,tn);
return answer;
}
from p5.easycam.
hi to those people reading this... i found the solution, and it was unbelievably strange!! i just commented part the inverted the view matrix... so i just multiplied the view matrix into my vecRayEyeNew... and now everything is working as expected!!! sooo strange...
from p5.easycam.
Related Issues (20)
- Camera is not a function error HOT 4
- HUD usage HOT 1
- written for node_modules HOT 1
- Submit to be included on the p5.js website's libraries page HOT 1
- Limiting rotation angles
- EasyCam not working for p5.js 0.9.0! HOT 2
- Dw.EasyCam is not defined p5.js & Vue.js Integration HOT 4
- New release of p5.EasyCam available
- Does not work properly with meshes. HOT 1
- Codesandbox "n.camera is not a function" HOT 1
- NPM release?
- BUG FOUND AND FIXED: dwgl.js bug in uniformT
- HUD can't be fixed with New p5 1.6 Version HOT 1
- Rotations around world axes HOT 4
- renderer.pop() needs a style returned by renderer.push() HOT 1
- PeasyCam Broken with p5.js v0.7.2 September 02, 2018 HOT 10
- is full screen available only?
- what is mouseDragPan()? HOT 3
- HighDPI handling HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p5.easycam.