- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用以下代码在 C++ 中的 opengl 中实现“缩放到鼠标点”功能。大部分代码来自 OpenGL Google maps style 2D camera / zoom to mouse cursor但由于 GLM ( http://glm.g-truc.net/0.9.5/index.html) 代码库发生了变化,我不得不更改一些包含语句。
#include <GL/freeglut.h>
#include <iostream>
using namespace std;
#define GLM_SWIZZLE_XYZW
#define GLM_FORCE_RADIANS
#include "glm/glm.hpp"
#include "glm/detail/setup.hpp"
#include "glm/detail/_swizzle.hpp"
#include "glm/detail/_swizzle_func.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
glm::dvec3 Unproject( const glm::dvec3& win )
{
glm::ivec4 view;
glm::dmat4 proj, model;
glGetDoublev( GL_MODELVIEW_MATRIX, glm::value_ptr( model ) );
glGetDoublev( GL_PROJECTION_MATRIX, glm::value_ptr( proj ) );
glGetIntegerv( GL_VIEWPORT, glm::value_ptr( view ) );
glm::dvec3 world = glm::unProject( win, model, proj, view );
return world;
}
// unprojects the given window point
// and finds the ray intersection with the Z=0 plane
glm::dvec2 PlaneUnproject( const glm::dvec2& win )
{
glm::dvec3 world1 = Unproject( glm::dvec3( win, 0.01 ) );
glm::dvec3 world2 = Unproject( glm::dvec3( win, 0.99 ) );
// u is a value such that:
// 0 = world1.z + u * ( world2.z - world1.z )
double u = -world1.z / ( world2.z - world1.z );
// clamp u to reasonable values
if( u < 0 ) u = 0;
if( u > 1 ) u = 1;
return glm::swizzle< glm::X, glm::Y >( world1 + u * ( world2 - world1 ) );
}
// pixels per unit
const double ppu = 80.0;
glm::dvec2 center( 0 );
double scale = 1.0;
void ApplyCamera()
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
const double w = glutGet( GLUT_WINDOW_WIDTH ) / ppu;
const double h = glutGet( GLUT_WINDOW_HEIGHT ) / ppu;
glOrtho( -w/2, w/2, -h/2, h/2, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glScaled( scale, scale, 1.0 );
glTranslated( -center[0], -center[1], 0 );
}
glm::dvec2 centerStart( 0 );
int btn = -1;
void mouse( int button, int state, int x, int y )
{
ApplyCamera();
y = glutGet( GLUT_WINDOW_HEIGHT ) - y;
btn = button;
if( GLUT_LEFT_BUTTON == btn && GLUT_DOWN == state )
{
centerStart = PlaneUnproject( glm::dvec2( x, y ) );
}
if( GLUT_LEFT_BUTTON == btn && GLUT_UP == state )
{
btn = -1;
}
glutPostRedisplay();
}
void motion( int x, int y )
{
y = glutGet( GLUT_WINDOW_HEIGHT ) - y;
if( GLUT_LEFT_BUTTON == btn )
{
ApplyCamera();
glm::dvec2 cur = PlaneUnproject( glm::dvec2( x, y ) );
center += ( centerStart - cur );
}
glutPostRedisplay();
}
void wheel( int wheel, int direction, int x, int y )
{
y = glutGet( GLUT_WINDOW_HEIGHT ) - y;
ApplyCamera();
glm::dvec2 beforeZoom = PlaneUnproject( glm::dvec2( x, y ) );
const double scaleFactor = 0.90;
if( direction == -1 ) scale *= scaleFactor;
if( direction == 1 ) scale /= scaleFactor;
ApplyCamera();
glm::dvec2 afterZoom = PlaneUnproject( glm::dvec2( x, y ) );
center += ( beforeZoom - afterZoom );
glutPostRedisplay();
}
void display()
{
glClearColor( 0, 0, 0, 1 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
ApplyCamera();
glBegin( GL_QUADS );
glVertex2i( -1, -1 );
glVertex2i( 1, -1 );
glVertex2i( 1, 1 );
glVertex2i( -1, 1 );
glEnd();
glutSwapBuffers();
}
int main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
glutInitWindowSize( 600, 600 );
glutCreateWindow( "GLUT" );
glutMouseFunc( mouse );
glutMotionFunc( motion );
glutMouseWheelFunc( wheel );
glutDisplayFunc( display );
glutMainLoop();
return 0;
}
错误
error: 'swizzle' is not a member of 'glm'
error: 'X' is not a member of 'glm'
error: 'Y' is not a member of 'glm'
排队
return glm::swizzle< glm::X, glm::Y >( world1 + u * ( world2 - world1 ) );
我知道 glm::swizzle
显然是错误的,但是 glm::detail::_swizzle
需要 8 个参数,而 glm::swizzle 之前需要 2 个参数
。新参数是什么?另外,我不知道如何更正 glm::X
和 glm::Y
。有人可以帮忙吗?
最佳答案
实际上在这种情况下您根本不需要 swizzling,因为有一个 dvec2
构造函数可以为您切掉 z 坐标。
将 PlaneUnproject()
的最后一行更改为:
return glm::swizzle< glm::X, glm::Y >( world1 + u * ( world2 - world1 ) );
为此:
return glm::dvec2( world1 + u * ( world2 - world1 ) );
我更新了我的 original answer 中的完整代码.
尽管如果您真的想要调配:
减少你的#include
:
#define GLM_SWIZZLE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
然后将 PlaneUnproject()
的最后一行更改为:
return glm::swizzle< glm::X, glm::Y >( world1 + u * ( world2 - world1 ) );
为此:
return ( world1 + u * ( world2 - world1 ) ).xy();
关于c++ - 'swizzle' 不是 'glm' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882773/
我们在 Objective-C 中使用 Swizzling。为方便起见,我们使用 CoconutKit 的辅助方法来实现此目的: HLSSwizzleSelectorWithBlock_Begin([
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
如果我在我的 iOS 应用程序中添加 2 个 SDK,它在内部为相同的方法“ViewDidAppear”进行方法调配,那么在运行时可能会发生什么(好的 + 坏的)。 最佳答案 根据 swizzling
我正在开发一个 iOS 框架,需要编写一个 swizzling 方法(用于 UIViewController 中的 viewDidAppear 方法)。 我的 swizzling 方法在我的应用程序中
Swizzling 不执行动态方法交换。这是我使用的代码。我听说这是一个无法在 xcode 7 中的 XCTest 中进行依赖注入(inject)的解决方案。你能给我解释一下 DI(依赖)上的 Swi
我正在构建一个带有电话号码登录的屏幕。我一遍又一遍地检查,该项目是新创建的,但是,我收到了以下日志: 7.2.0 - [Firebase/Auth][I-AUT000015] The UIApplic
我有一个主应用程序,我们称之为应用程序。 它链接两个静态库:StatLib1 和 StatLib2。 StatLib1 链接 StatLib2 库。 如您所见,StatLib2 库链接了两次。 在St
我目前正在尝试测试一些使用 AVAudioSession 的代码,并且我尝试模拟它,因为它是一个单例,到目前为止证明是困难的,我做了一些研究并想到了这个想法调配它的方式是它的实例,然后按照您的意愿实际
我的应用程序的一个 viewController 变得非常大,特别是因为我添加了一个“教程状态”,它为我通过检查控制的此类的许多方法添加了不同的实现 _tutorialEnabled? 所以,我的问题
我正在关注这个 article更好地理解方法调配的工作原理。我有这样的主视图 Controller (这是一个新项目): #import "GLViewController.h" #import @
我有很多类,在类内部定义了很多方法。当这些方法中的每一个被调用时,我需要执行一组特定的操作。我可以在每个方法中编写一组操作。但我不想弄乱代码。所以我创建了一个帮助程序类,我将在其中传递一组类和选择器。
我正在尝试更改应用程序语言并使用 Swizzling 函数,但在调用 DoTheSwizzling() 时出现问题,选择器崩溃了!我认为找不到“specialLocalizedStringForKey
我们正在开发一款可以将大量内容保存到 Core Data 中的应用程序。它保存的东西主要是NSDate NSNumber & NSString 但它也将很多图片和视频保存为NSData。我正在尝试更改
我正在尝试通过创建 UIResponder 扩展来调整 UITouch 生命周期事件。以下是描述 touchesBegan 实现的摘录。 public extension UIResponder {
您好,我正在实现 FCM(基于 Fire 的云消息传递)。我已经让应用程序接收来自 FCM 控制台的通知和数据。我有我的服务器通知和 firebase 通知。我想分别处理两种类型的通知(来 self
我最近收到了一个私有(private)硬件 SDK,可以集成到我公司的移动应用程序中。一切都很好,除了他们使用的是 UIAlertView作为一些不透明方法调用的结果,我的设计团队想要标记它。我无权访
我正在尝试调整 UIView 上的 backgroundColor 属性。 在我调酒之前,我执行以下操作: @implementation UIView (Cat1) +(void)load { NS
我正在尝试搜索以防止在我当前的库中使用 Method Swizzle,但我发现的每篇文档或博客文章或多或少都是关于如何实现 Swizzling 的。我有几个关于 Method swizzling 的问
我已经尝试使用 Swizzle Stream 库来替换输入流中的标记。 String RESOURCE_PATH = "FakePom.xml"; InputStream pomIS = Ja
我正在使用以下代码在 C++ 中的 opengl 中实现“缩放到鼠标点”功能。大部分代码来自 OpenGL Google maps style 2D camera / zoom to mouse cu
我是一名优秀的程序员,十分优秀!