Sign in to follow this  
qqqzp

How can I draw a ray from a point when angle and end are variable?

Recommended Posts

Hi everyone.

I am new to Pixi.js and I took a project about optics simulation.

I was planning to use Pixi.js to implement a effect like the pic below.When the angle of the flashlight changes, the lazer sweeps over the canvas and sometimes reflected by a mirror or optical lens.

But I found a trouble that I can't tell where the ray will interact with other items, thus make it hard to draw a line without a certain end.😢

So I was hoping someone could tell how can I draw a ray with just one start and a certain angle, or maybe there is any easier way to impliement it.

Much thanks for any answers.

1.png

Share this post


Link to post
Share on other sites

But I found a trouble that I can't tell where the ray will interact with other items, thus make it hard to draw a line without a certain end.😢

PixiJS has very limited options for physics and 2d math in general. It only has affine transforms and rectangular bounds.

If you calculated coords - just fill up "PIXI.Graphics" with your lines.

Do you have any experience with p2, matter and other physics engines that have raytrace function in them? Connect one of them and use it. In case of "p2" I can warn you that you have to build it from github repo, dont use it from npm.

That's all I have regarding your information.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.