perl-opengl-glutMotionFunc鼠标事件

#!/usr/bin/perl -w
use strict;
use warnings;
use OpenGL qw/ :all /;
use OpenGL::Config;   

#!/usr/bin/perl -w
use strict;
use warnings;
use OpenGL qw/ :all /;
use OpenGL::Config;   


my $a=rand(1);
my $b=rand(1);
my $c=1;
my $look=0.1;
my $lookx=0.1;
my $looky=0.1;
my $ispress=0;

glutInit();
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("my  OpenGL program");
glClearColor(0,0,0,255);
glClear(GL_COLOR_BUFFER_BIT);  
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-3,3,-3,3,-3,3);
gluLookAt($look,$look,$look,0.0,0.0,0.0,0.0,$look,0.0); 
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(\&mydis);
glutMotionFunc(\&mymouse);
glutMainLoop();

 sub mydis()
{
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  glClearColor(0,0,0,255);
  glClear(GL_COLOR_BUFFER_BIT); 
  &qiu();
}

sub mymouse()
{
	my ($myx,$myy)=@_;
	$look=($myx+$myy)/2/400;	
 	$lookx=($myx-200)/200;
	$looky=(200-$myy)/200;	
    glLoadIdentity();
    gluLookAt($lookx,$looky,$look,0.0,0.0,0.0,0.0,$look,0.0);	
	glutPostRedisplay();
	print "mouse x:$myx-y:$myy-look:$look\n";
}

sub qiu()
{
  my $x;
  my $y;
  my $z;
  my $c=3.1415926/180;
  for (my $phi=-80.00;$phi<=80.00;$phi+=20.00)
  {

      my $phir=$c*$phi;
      my $phir20=$c*($phi+20);     
      glBegin(GL_QUAD_STRIP); 
	  glColor3f($a,$b,$c);
      for (my $theta=-180.00;$theta<=180.00;$theta+=20.00)
      {
          my $thetar=$c*$theta;
          $x=sin($thetar)*cos($phir);
          $y=cos($thetar)*cos($phir);
          $z=sin($phir);
          glVertex3d($x,$y,$z);	
          $x=sin($thetar)*cos($phir20);
          $y=cos($thetar)*cos($phir20);
          $z=sin($phir20);          
          glVertex3d($x,$y,$z);				  
	  }  
      glEnd();	
	  glFlush();
  }
}

 按下鼠标按钮时,球体会随着鼠标的操作而转动 


 



 

 

7.6 glutMotionFunc, glutPassiveMotionFunc

  glutMotionFunc and glutPassiveMotionFunc set the motion and passive motion callbacks respectively for the current window.

Usage

void glutMotionFunc(void (*func)(int x, int y));
void glutPassiveMotionFunc(void (*func)(int x, int y));
func
The new motion or passive motion callback function.

 

Description

glutMotionFunc and glutPassiveMotionFunc set the motion and passive motion callback respectively for the current window. The motion callback for a window is called when the mouse moves within the window while one or more mouse buttons are pressed. The passive motion callback for a window is called when the mouse moves within the window while no mouse buttons are pressed.

The x and y callback parameters indicate the mouse location in window relative coordinates.

Passing NULL to glutMotionFunc or glutPassiveMotionFunc disables the generation of the mouse or passive motion callback respectively.

 

 

计算技术【52】 按下鼠标按钮时,球体会随着鼠标的操作而转动。 阅读详情

相关推荐

鼠标控制物体缩放旋转(opengl+glut)

基于glutMouseFunc和glutMotionFunc的用鼠标控制物体的缩放和旋转的小例子,分享学习一下。

OPENGL中和鼠标、键盘事件有关的函数

1. void glutMotionFunc(void (*func)(int x, int y)) 当鼠标在窗口中按下并移动时调用glutMotionFunc注册的回调函数,x和y为按下鼠标时鼠标的位置 2. void glutPassiveMotionFunc(void (*func)(int x, int y)) 当鼠标在窗口中移动时调用glutPassiveMotionFunc注册的回调函...

Milkha的博客 2346

【多无人机协同目标运输任务】多无人机协同目标运输任务中的路径规划与动态控制研究(Matlab代码实现) ​

内容概要:本文聚焦于多无人机协同执行目标运输任务中的关键问题,系统研究了复杂环境下多无人机系统的路径规划与动态控制策略,并提供了基于Matlab的完整仿真代码实现。研究内容包括多智能体协同机制设计、高效路径规划算法(如改进RRT*、A*等)的应用、动态响应控制策略(如反步控制、滑模控制等)的集成,以及任务过程中无人机间的协调控制逻辑。通过高保真度仿真验证了所提方法在不同场景下的有效性、鲁棒性与实用性,代码配备详尽注释,便于理解与二次开发。; 适合人群:具备一定控制理论基础和Matlab编程能力,从事无人机控制、多智能体系统、智能交通或机器人协同等方向的科研人员及研究生(工作1-3年或研一以上水平);; 使用场景及目标:①用于多无人机协同运输任务的算法设计与仿真验证;②支撑科研论文复现、课题开发及工程原型构建;③深入理解路径规划与动态控制在多机协同中的耦合关系与实现方式;; 阅读建议:建议结合Matlab代码逐模块调试运行,配合控制理论教材深化对控制律设计的理解;建议先掌握单无人机基本控制原理,再逐步过渡到多机协同逻辑的学习,以提升整体系统认知与实践效率。

(六)注册回调函数

glutDisplayFunc 注册当前窗口函数 glultReshapeFunc 注册当前窗口的形状变化回调函数 glutMouseFunc 注册当前窗口的鼠标回调函数 glutMotionFunc 设置移动回调函数 glutIdleFunc 设置全局的空闲回调函数 glutVisibilityFunc 设置当前窗口的可视回调函数 glutKeyboardFunc、glutSpecialFu...

遥望星河的博客 2443

关于小样本学习综述论文的总结

对小样本学习综述的个人总结

qq_46176086的博客 5460

Android 默认授予所有应用权限以及特殊权限处理

PackageManagerService作为android的主要系统服务之一,包含处理应用权限相关的职责。源码地址如下:在PMS成功启动时并收到回掉systemReady回进行应用权限授予。DefaultPermissionGrantPolicy为权限处理策略管理类。这里并没有赋予所有系统应用权限,所以当进行应用时还是会显示权限检查的弹框。可通过此方法进行所有应用权限赋予:如果不想所有应用都授予权限,可考虑在system/etc下的权限相关xml文件添加应用包名和所需权限。

Jimmy的专栏 1524

OpenGL 中 GLUT 消息事件处理函数

GLUT 这是一套 OpenGL 的辅助函数库,他使我们能十分简单的设置各种消息处理函数,而且与平台无关,也就是说如果使用glut 在windows 下编译通过的程序无需更改便可在 Linux, 和 Mac OS 下的编译运行,这一点是十分有用的,要知道 Win32 API 繁琐的代码走出了 Windows 的窗户可什么也干不了。给 GLUT  作了这么多广告,让我们看看他是怎么用的。     

qq_28088659的博客 2758

从按下开机键到进入系统:深入主板“后台”,揭秘Super I/O芯片的上电时序与BIOS交互

本文深入探讨了Super I/O芯片(SIO)在电脑启动过程中的关键作用,详细解析了其架构设计、上电时序与BIOS交互机制。通过分析SIO的多功能集成控制器特性,包括低速I/O管理、硬件监控和电源管理,揭示了从按下电源按钮到系统初始化的精密硬件协作过程。文章还提供了常见问题的调试方法,为硬件工程师和嵌入式开发者提供了实用参考。

weixin_27014595的博客 144

Glut处理鼠标事件

检测鼠标单击 要想在OpenGL中处理鼠标事件非常的方便,GLUT已经为我们的注册好了函数,只要我们提供一个方法。使用函数glutMouseFunc,就可以帮我们注册我们的函数,这样当发生鼠标事件时就会自动调用我们的方法。 函数的原型是: void glutMouseFunc(void(*func)(int button,int state,int x,int y)); 参数: fu

循序渐进,可收宏效 2万+

数字IC后端PPA优化实战:Innovus中Timing一致性策略与Module Region布局技巧

本文深入探讨了数字IC后端设计中PPA优化的核心挑战,重点解析了Innovus与PrimeTime之间Timing不一致的根本原因。通过实战案例,详细介绍了在Innovus中设置Timing Margin、Derate以及RC Scale Factor等关键策略,以校准时序视图。同时,文章分享了利用Module Region进行物理布局规划的技巧,将关键模块约束在最优区域,并结合Group Path等进阶方法,有效提升时序收敛效率与PPA结果的可预测性。

f9g0h的博客 2701

浙江大学Fast-Lab从0制作自主空中机器人公开课教程补充及部分注意事项(适用于ubuntu系统和ROS零基础)

浙江大学Fast-Lab从0制作自主空中机器人公开课纯萌新补充(适用于从没接触过ubuntu系统),记录了一些自己不会的地方以及踩过的坑

qq_39986834的博客 2996

【OpenGL】glut 消息事件处理函数 glutMainLoop();

glut这是一套opengl的辅助库,他使我们能十分简单的设置各种消息处理函数,而且与平台无关,也就是说如果使用glut 在windows 下编译通过程序无需更改便可在linux, 和mac os 下的编译运行,这一点是十分有用的,要知道win32api繁琐的代码走出了windows 的窗户可什么也干不了。给glut 作了这么多广告,让我们看看他是怎么用的. GLUT的基本功能

liujiancheng815的专栏 3711

python 爬虫 xpath 存储到数据库

参考

我是张先生 1299

glut中glutPassiveMotionFunc函数使用

类似WinAPI中的WM_MOUSEMOVE,glut的glutPassiveMotionFunc函数就是相应鼠标没有被按下去时,移到鼠标的情形。而常用的glutMotionFunc是响应鼠标键按下去后,移到鼠标的情形!自己写个MouseMiton函数。将该函数作为参数传给上面的两个回调函数即可: glutMotionFunc(&myApplication::mouseMotion); g

dizuo的专栏 6983

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

WW、forever的博客 498

FPGA+CUYSB3014实现USB3.0功能

CYUSB3014是赛普拉斯在近几年推出的新一代USB3.0的外设控制器,可以解决USB2.0带宽限制,或者单独开发USB协议和驱动的难题。赛普拉斯将CYUSB3014简称为EZ-USB FX3,具有高度的灵活特性,开发人员只需要下载FX3的固件库,就能使用USB3.0的功能。目前在一些电子产品中,使用主控器加PHY芯片最流行的方式是用FPGA+FX3这种搭配来实现USB3.0接口。......

D_Katter的博客 7082

OpenGL学习笔记(二)

1、OpenGL实用工具包(GLUT)OpenGL包含渲染函数,但被涉及成独立于任何窗口系统和操作系统。因此,OpenGL并没用用于打开窗口以及检测键盘或鼠标事件的函数。GLUT库被用来简化这些相关任务,此外还提供了一些用于创建复杂三位物体(如球体、圆环和茶壶等)的函数。    窗口管理函数   glutInit(int *argc, char **argv),初始化GLUT并处理命令行参数,应在

孟源的专栏 2880

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

OpenGL中常用的 GLUT 函数

GLUT函数说明一、初始化void glutInit(int* argc,char** argv) 这个函数用来初始化GLUT库。对应 main 函数的形式应是: int main(int argc,char* argv[]); 这个函数从 main 函数获取其两个参数。 void glutInitWindowSize(int width,int height); void glutInit

麦田里的码农 1万+

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Glut 回调函数小结

void glutDisplayFunc(void(* func)(void)); 注册当前窗口的显示回调函数   参数:func:形为void func()的函数,完成具体的绘制操作 这个函数告诉GLUT当窗口内容必须被绘制时,那个函数将被调用。当窗口改变大小或者从被覆盖的状态 // ********* *****************************************...

xianhua7877的博客 1770

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

GLUT函数说明--注册回调

void glutDisplayFunc(void (*func)(void) );为当前窗口设置显示回调函数void glutOverlayDisplayFunc(void (*func)(void) );注册当前窗口的重叠层的显示回调函数void glutReshapeFunc(void (*Func)(int width, int height) );指定当窗口的大小改变

hua_007的专栏 1300

OpenGL---GLUT教程(九) GLUT鼠标

           GLUT教程              鼠标在前几节,我们看了怎么使用GLUT的keyboard函数,来增加一个OpenGL程序的交互性。现在,是时候研究下鼠标了。GLUT的鼠标接口提供一些列的选项来增加鼠标的交互性。也就是检测鼠标单击,和鼠标移动。 检测鼠标Clicks和键盘处理一样,GLUT为你的注册函数(也就是处理鼠标clicks事件的函数)

xie_zi的专栏 1万+

GLUT及其函数

GLUT - The OpenGL Utility Toolkit glut是基本的窗口界面,是独立于gl和glu的,如果不喜欢用glut可以用MFC和Win32窗口等代替,但是glut是跨平台的,这就保证了我们编出的程序是跨平台的,如果用MFC或者Win32只能在windows操作系统上使用。选择OpenGL的一个很大原因就是因为它的跨平台性,所以我们可以尽量的使用glut库。 回调函数 回...

风刘人物的博客 1095
上一篇: perl-opengl-鼠标事件与球体视角
下一篇: prezi desktop
deepfuture
博客等级 码龄17年 211粉丝 1287原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址