使对象跟随鼠标
与这个主题相关的其他问题似乎并不能帮助我理解它。我刚刚开始使用 Visual Studio 和 Direct2D 进行编程,但我无法理解如何使两只“眼睛”(即椭圆内的椭圆)跟随我的鼠标。
在函数 void MainWindow::CalculateLayout()
内部,我用来
const float radius3=radius/4;
const float radius3_2=radius/5;
const float x3=x-100;
const float y3=y-150;
ellipse3 = D2D1::Ellipse(D2D1::Point2F(x3, y3), radius3, radius3_2);
//left eye
const float radius4=radius/4;
const float radius4_2=radius/5;
const float x4=x+100;
const float y4=y-150;
ellipse4 = D2D1::Ellipse(D2D1::Point2F(x4, y4), radius4, radius4_2);
//right eye
const float radius5=radius/8;
const float radius5_2=radius5/2;
const float x5=x-100;
const float y5=y-150;
ellipse5 = D2D1::Ellipse(D2D1::Point2F(x5, y5), radius5, radius5_2);
// left eyeball
const float radius6=radius/8;
const float radius6_2=radius6/2;
const float x6=x+100;
const float y6=y-150;
ellipse6 = D2D1::Ellipse(D2D1::Point2F(x6, y6), radius6, radius6_2);
// right eyeball
设置眼睛和眼球的位置。我认为沿着 this 应该用于控制鼠标所在的位置。我正在尝试从空白项目而不是表单中执行此操作。解决方案是简单地将 const float x5=x-100
替换为 MouseMove
的 X
值吗?
Other questions close to this topic don't seem to help me understand it very much. I'm just starting programming using Visual Studio and Direct2D and I'm having trouble understanding how to make two "eyes," which are ellipses inside of ellipses, follow my mouse.
Inside of the function void MainWindow::CalculateLayout()
I'm using
const float radius3=radius/4;
const float radius3_2=radius/5;
const float x3=x-100;
const float y3=y-150;
ellipse3 = D2D1::Ellipse(D2D1::Point2F(x3, y3), radius3, radius3_2);
//left eye
const float radius4=radius/4;
const float radius4_2=radius/5;
const float x4=x+100;
const float y4=y-150;
ellipse4 = D2D1::Ellipse(D2D1::Point2F(x4, y4), radius4, radius4_2);
//right eye
const float radius5=radius/8;
const float radius5_2=radius5/2;
const float x5=x-100;
const float y5=y-150;
ellipse5 = D2D1::Ellipse(D2D1::Point2F(x5, y5), radius5, radius5_2);
// left eyeball
const float radius6=radius/8;
const float radius6_2=radius6/2;
const float x6=x+100;
const float y6=y-150;
ellipse6 = D2D1::Ellipse(D2D1::Point2F(x6, y6), radius6, radius6_2);
// right eyeball
to set up where the eyes and eyeballs are. I think that something along the line of this should be used to control where the mouse is. I am trying to do this from a blank project, not from a form. Is the solution to simply replace const float x5=x-100
with the X
value of MouseMove
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要替换
x5
的定义,但您需要使用一个公式来完成此操作,该公式将限制它留在眼球内。您的公式将如下所示:
希望这会有所帮助。
要在光标非常接近时获得斗鸡眼效果,您应该让每个眼球计算自己的角度,例如左侧的角度为 leftAngle = arctan( (mouseY - (y-150)) / (mouseX - (x-100)) )
You need to replace the definition of
x5
, but you need to do it with a formula which will bound it to stay within the eyeball.Your formula will look something like this:
Hope this helps.
To get the cross-eyed effect when the cursor is very near, you should have each eyeball compute its own angle, for example the left's would be
leftAngle = arctan( (mouseY - (y-150)) / (mouseX - (x-100)) )