perl-opengl-鼠标事件与球体视角

#!/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=rand(1);
my $look=0.1;
my $lookx=0.1;
my $looky=0.1;

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(-2,2,-2,2,-2,2);
gluLookAt($look,$look,$look,0.0,0.0,0.0,0.0,$look,0.0); 
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(\&mydis);
glutMouseFunc(\&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 ($button,$state,$myx,$myy)=@_;
	if ($button==GLUT_LEFT_BUTTON  and $state==GLUT_DOWN)
	{
		   $look=($myx+$myy)/2/400;	
 		   $lookx=($myx-200)/400;
		   $looky=(200-$myy)/400;	        		        		
	}
	print "mouse x:$myx-y:$myy-look:$look\n";
}

sub qiu()
{
  my $x;
  my $y;
  my $z;
  my $c=3.1415926/180;
  glLoadIdentity();
  gluLookAt($lookx,$looky,$look,0.0,0.0,0.0,0.0,$look,0.0);
  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();
  }
}




 



 



 

 

OpenGL学习笔记(三)-变换-坐标系统-摄像机 参考网址:LearnOpenGL 中文版 哔哩哔哩教程 1.5 变换 为了使物体变成动态的,需要使用多个矩阵对象变换一个物体。 1.5.1 向量 向量包含方向和模。由于向量是一个方向,很难用位置表示,因此可指定原点,然后指向一个方向,对应一个点,使其变为位置向量。 1、向量与标量运算:数学中是没有这个运算的,但是在许多线性代数的库中支持这样的运算。该运算就是将向量的每个元素,与标量进行运算。其中的+可以是+,-,·或÷。注意-和÷运算时不能颠倒(标量-/÷向量),因为颠倒的运算是没有定义的。 2、向量取反 阅读详情

相关推荐

OpenGL鼠标视角交互

OpenGL鼠标视角交互1. 欧拉角2. 鼠标输入 1. 欧拉角 欧拉角(Euler Angle)是可以表示3D空间中任何旋转的3个值,一共有3种欧拉角:俯仰角(Pitch)、偏航角(Yaw)和滚转角(Roll),下面的图片展示了它们的含义: 俯仰角是描述我们如何往上或往下看的角 偏航角表示我们往左和往右看的程度 滚转角代表我们如何翻滚摄像机 把三个角结合起来我们就能够计算3D空间中任何的旋转向量 本摄像机系统仅关注俯仰角和偏航角 对于俯仰角,观察Y轴朝上的方向: 俯仰角的Y值 等于sinθ dir

牵LV小猪精的博客 2381

OpenGL学习记录(七)

添加第一人称摄像机系统。

weixin_47260762的博客 916

css3滚动的圆球动画特效

css3滚动的圆球动画特效

GLFW按键及鼠标事件等

GLFW按键及鼠标事件等,事件回调包括键盘、鼠标、滚动、游标、游戏手柄等

sq8706的专栏 1778

OpenGL实现鼠标点选并旋转物体

用opengl实现鼠标点选物体,并通过鼠标移动来旋转物体。像3Dmax那样有个轨迹球,点击相应球来绕特定方向旋转。

纯CSS3实现的3D小球动画在线演示

纯CSS3实现的3D小球动画在线演示,供大家一起共同分享学习。

[OpengGL] 摄像机[10]

  在上一章中,我们讨论了视图矩阵以及如何使用视图矩阵在场景中移动(我们向后移动了一点)。 OpenGL 本身并不熟悉相机的概念,但我们可以尝试通过反向移动场景中的所有对象来模拟一个相机,给人一种我们正在移动的错觉。  在本章中,我们将讨论如何在 OpenGL 中设置相机。 我们将讨论一种可让您在 3D 场景中自由移动的飞行式相机。 我们还将讨论键盘和鼠标输入,并以自定义相机类结束。  当我们谈论相机/观察空间时,我们谈论的是从相机的角度看作为场景原点的所有顶点坐标:视图矩阵将所有世界坐标转换为相对于相机位

unity尧明的博客 781

OPENGL鼠标拾取与选择

OPENGL鼠标拾取与选择

glfw 鼠标事件处理

glfw 鼠标事件

代码波士 2321

OpenGL的鼠标键盘事件

OpenGL的鼠标键盘事件机制,简单的例子代码!

LSF0108电平转换芯片设计要点与调试实战指南

在嵌入式系统从5V向3.3V、1.8V等低压域演进的过程中,不同电压域之间的信号互连成为硬件设计的常见挑战。电平转换技术通过调整信号高低电平的电压范围,确保MCU、传感器与外设之间稳定通信。以I2C总线为代表的双向开漏信号,对电平转换器的方向感知能力和导通特性提出了更高要求。LSF0108作为一款8通道自动方向感知的MOSFET型电平转换芯片,凭借宽电压范围、无需方向控制和低成本优势,在多路双向信号场景中被广泛采用。理解其参考电压与外部上拉的协同原理,合理计算上拉电阻、处理OE引脚时序,并掌握标准的调试流程

weixin_30036289的博客 266

GLFW输入系统全面解析:从键盘鼠标到事件处理

GLFW输入系统全面解析:从键盘鼠标到事件处理 【免费下载链接】glfw A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input 项目地址:...

gitblog_00106的博客 591

Webots+UR机械臂仿真全流程:手把手教你用Python实现Pick-and-Place轨迹规划

本文详细介绍了使用Webots和Python实现UR六自由度机械臂的Pick-and-Place轨迹规划全流程。从环境搭建、运动学正逆解计算到轨迹规划实战技巧,涵盖工业场景中的关节补偿、末端校准等实际问题解决方案,帮助开发者快速掌握机械臂精准控制技术。

weixin_29083649的博客 290

5、OpenGL-GLFW事件响应

事件回调函数:窗体激活的情况下,用于响应窗口变化、键盘、鼠标等操作消息的函数。

qq_51355375的博客 1599

在 Ubuntu 上安装和配置 PostgreSQL 实录

本文介绍了在Ubuntu系统上安装和配置PostgreSQL数据库的完整步骤。主要内容包括:1)通过官方源或PPA源安装最新版本;2)修改配置文件(postgresql.conf和pg_hba.conf)以允许远程访问;3)设置postgres用户密码;4)创建新用户并配置权限;5)防火墙设置和重启服务;6)验证安装和远程连接方法。文章提供了详细的命令行操作指导,帮助用户完成从安装到远程访问的全部配置过程。

qq_58168857的博客 1219

【Arduino 动手做】六舵机自平衡 Rotary Stewart 平台

《Arduino六舵机自平衡Rotary Stewart平台项目》 该项目展示了一个基于Arduino的六自由度Rotary Stewart平台,通过六个舵机实现动态平衡控制。设计采用激光切割框架和TAMIYA 70171套件,提供详细组装指南和开源固件(GitHub可获取)。开发者丹·罗耶分享了3D打印文件、视频演示及运动学优化需求,强调该平台可扩展应用于游戏控制(如Kerbal Space Program)或教育领域。项目链接包含完整资源包,鼓励用户参与改进并分享创作成果。该案例体现了Arduino在机

雕爷学编程 1109

鼠标点击画出几何图(glad+glfw的方法进行opengl开发)

思路:点击窗口,获取窗口的位置后存储下来,以此完成所有点击点的信息。并在每一帧的渲染中渲染出全部的顶点,即可完成画三角形。 在这里使用了如下两个函数,检测是否鼠标有移动或者点击动作: 在鼠标点击后,在vector中添加顶点位置信息: 同时,在glfwCursorPosCallback函数中,会得到当前帧鼠标的位置,但是鼠标位置需要计算在当前opengl窗口的位置,由于该函数会实时更新数据,因此可以在此函数中更新GPU中的缓存数据,完成实时显示的显示效果: 最后设定好渲染器后,可显示画三角形: .

coding的博客 1685

最强AI插件Augment,适配idea、vscode,对标cursor!

Augment是一款新兴的AI辅助编码工具,能够无缝集成到IDEA和VS Code等主流IDE中,直接对标专业AI编码工具Cursor。其核心优势包括多IDE适配、无缝集成、代码理解与生成以及对话式编程体验。Augment通过插件形式保留原IDE功能和快捷键习惯,降低学习成本,同时提供深度理解项目上下文和生成高质量代码的能力。此外,Augment还具备审查变更、检查点、代理与代理自动等核心功能,支持从简单配置更改到复杂功能实现的各种开发任务。Augment代表了AI辅助编程工具的新方向,通过增强开发者熟悉的

todoitbo的博客 1万+

OpenGL使用笔记【2】鼠标交互操作

这篇文章属于通过鼠标交互实现点击画点操作

qq_62791684的博客 1223

代码接单:用 ComfyUI 搭建电商模特换装工作流(保姆级教程)

在闲鱼和小红书上,搜一下“AI 模特图”或者“服装换模特”,你会发现大量的接单需求。太贵:请个外模拍一套图,动辄几千块。太慢:寄样品、排期、拍摄、修图,半个月过去了。太卷:竞对都在上新,你还在等图。“给我一张你的衣服平铺图(或假人图),我 10 分钟给你生成真人上身图,一张只要 50 块。对于商家是省钱,对于你是纯利润。为什么不用 Midjourney?因为 MJ 抽卡不可控,无法保持衣服版型一致。只有 ComfyUI,才能做到精准控制,实现工业化量产。

BUG猿的博客 1805

嵌入式面试题精选100道及参考答案(4万字长文)

指针是C语言中一种特殊的变量,它存储的是另一个变量的内存地址。指针的使用提供了一种间接访问和操作内存的方法。地址操作:通过使用运算符,可以获取变量的地址,并将这个地址赋值给指针变量。间接引用:使用运算符可以访问指针指向的变量的值。动态内存分配:指针用于动态地分配和释放内存。数组操作:指针可以用于遍历和操作数组。函数参数:指针作为函数参数可以改变原始数据。字符串操作:在C语言中,字符串通常以字符数组的形式存在,并通过字符指针进行操作。// 指向数组的第一个元素i < 5;++i) {在这个例子中,

大模型大数据攻城狮的专栏 2000

OpenGL中最简单的窗体创建和渲染(初始化GLFW、GLAD、定义视口大小和resize回调、双层缓冲、输入事件处理)

GLFW的配置说明 步骤:创建的窗口对象容纳了所有的窗口数据(初始化之后的代码段)。 最后一行代码的目的是让我们窗口的context成为当前线程的主context。glfwGetProcAddress根据操作系统提供函数。 定义视口大小 定义并注册resize事件 准备engines 为了不让应用程序画一帧就关掉窗口,使用while定义render loop。 glfwWindowShouldClose检验窗体是否被关闭 glfwSwapBuffers交换颜色缓存(是一个巨大的包含GLFW窗口的每个

weixin_43399489的博客 1799

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

GLFW中的鼠标滑动事件

GLFW中的鼠标滑动事件 以下是glfw3.h中关于设置鼠标滑动回调函数的方法: /*! @brief Sets the scroll callback. * * This function sets the scroll callback of the specified window, which is * called when a scrolling device is used...

dexfire ’s blog 3638

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

OpenGL第三方库:GLFW入门篇

前言:GLFW是继GLUT,FreeGLUT之后,当前最新的用来创建OpenGL上下文,以及操作窗口的第三方库。官方网址为:http://www.glfw.org/。 错误处理机制:在使用GLFW之前,有必要设置一个错误处理机制,这样如果出现任何问题,GLFW都可以及时的告知我们。设置接口定义如下: GLFWWerrorfun* glfwSetErrorCallback(GLFWWerrorfu...

phymat.nico的专栏 1863

深度学习工具包 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")

上一篇: perl-opengl键盘事件与色彩
下一篇: perl-opengl-glutMotionFunc鼠标事件
deepfuture
博客等级 码龄17年 211粉丝 1287原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址