我正在设计一个QT4课程.到目前为止我的班级看起来像这样:
class GIHNode : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES( QGraphicsItem )
[...]
public:
void setInteger(int);
int getInteger();
[..]
private:
int Integer; Q_PROPERTY(int Integer READ getInteger WRITE setInteger)
// Definition I'd like to replace
The setters and getters are implemented like this:
void GIHNode::setInteger(int x){Integer=x;}
int GIHNode::getInteger(){return Integer;}
Run Code Online (Sandbox Code Playgroud)
我想定义一个宏来完成所有这些工作.我试过这个来定义一个变量和里面的文字Q_PROPERTY:
#define ID(x) x
#define STR_HELPER(x,y) ID(x)y
#define STRGET(x) STR_HELPER(get,x)
#define STRSET(x) STR_HELPER(set,x)
#define EXPORTEDVAR(type,varname) type varname; Q_PROPERTY(type varname READ STRGET(varname) WRITE STRSET(varname))
Run Code Online (Sandbox Code Playgroud)
当我更换线路时:
int Integer; Q_PROPERTY(int Integer READ …Run Code Online (Sandbox Code Playgroud) 我画了很多充满NSGradient的梯形.我希望他们能够无缝地加入,但实际情况并非如此.在这种情况下,我更喜欢使用剪辑而不是使用渐变显式填充NSBezierPath.

这是有罪的代码:
-(void)drawRect:(NSRect)dirtyRect {
[[NSColor blackColor]set];
NSRectFill(self.bounds);
NSPoint v0 = NSMakePoint(100,100);
NSPoint v1 = NSMakePoint(200,100);
NSPoint v2 = NSMakePoint(100,200);
NSPoint v3 = NSMakePoint(200,200);
NSPoint v4 = NSMakePoint(150, 150);
NSBezierPath * triangle0 = [NSBezierPath bezierPath];
[triangle0 moveToPoint:v0];
[triangle0 lineToPoint:v1];
[triangle0 lineToPoint:v2];
[triangle0 closePath];
NSBezierPath * triangle1 = [NSBezierPath bezierPath];
[triangle1 moveToPoint:v1];
[triangle1 lineToPoint:v2];
[triangle1 lineToPoint:v3];
[triangle1 closePath];
NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations:[NSColor whiteColor],0.0,[NSColor orangeColor],1.0,nil];
[NSGraphicsContext saveGraphicsState];
[triangle0 addClip];
[gradient drawFromPoint:v0 toPoint:v4 options:NSGradientDrawsAfterEndingLocation|NSGradientDrawsBeforeStartingLocation];
// [gradient drawFromPoint:v0 toPoint:v4 options:0];
[NSGraphicsContext restoreGraphicsState]; …Run Code Online (Sandbox Code Playgroud) 我正在用滑块编写游戏.为了将游戏从解决状态中洗牌,我想pushRandomPiece定期反复调用以在视觉上改组游戏.
我想首先使用dispatch_after,但是我对触发日期有疑问:
这有效:
-(void)shuffle {
for (int i=0; i<50;i++)
[self performSelector:@selector(pushRandomPiece) withObject:nil afterDelay:i*0.50*2];
}
Run Code Online (Sandbox Code Playgroud)
pushRandomPiece中两个连续调用之间的差异几乎总是等于一秒.
但这不起作用:
-(void)shuffle {
for (int i=0; i<50;i++)
// [self performSelector:@selector(pushRandomPiece) withObject:nil afterDelay:i*0.50*2];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, i*NSEC_PER_SEC*0.5*2), dispatch_get_main_queue(), ^{ [self pushRandomPiece]; });
}
Run Code Online (Sandbox Code Playgroud)
这是连续呼叫之间的时差:
2013-10-01 11:02:53.147 SlidingPuzzle[2006:60b] diff= 1.077376
2013-10-01 11:02:54.262 SlidingPuzzle[2006:60b] diff= 1.111863
2013-10-01 11:02:55.335 SlidingPuzzle[2006:60b] diff= 1.070456
2013-10-01 11:02:56.455 SlidingPuzzle[2006:60b] diff= 1.117381
2013-10-01 11:02:57.542 SlidingPuzzle[2006:60b] diff= 1.084070
2013-10-01 11:02:58.655 SlidingPuzzle[2006:60b] diff= 1.110574
2013-10-01 11:02:59.757 SlidingPuzzle[2006:60b] diff= 1.098654
2013-10-01 11:03:00.862 SlidingPuzzle[2006:60b] diff= 1.103132
2013-10-01 11:03:01.956 …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行XCode文档中包含的噪声OpenCL示例项目.
我有一个我不明白的错误:
----------------------------------------------------------------------
Using active OpenGL context...
----------------------------------------------------------------------
Connecting to NVIDIA GeForce 320M...
----------------------------------------------------------------------
Loading kernel source from file 'noise_kernel.cl'...
----------------------------------------------------------------------
Building compute program...
[CL_DEVICE_NOT_AVAILABLE] : OpenCL Error : Error: Build Program driver returned (10007)
Break on OpenCLErrorBreak to debug.
OpenCL Warning : clBuildProgram failed: could not build program for 0x1022600 (GeForce 320M) (err:-2)
Break on OpenCLWarningBreak to debug.
[CL_BUILD_ERROR] : OpenCL Build Error : Compiler build log:
<program source>:58:21: error: global variables must have a constant address space qualifier …Run Code Online (Sandbox Code Playgroud) 我的UIView正在为其图层使用TBPaperLayer实例.
+(Class)layerClass {
return [TBPaperLayer class];
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个CIFilter来修改这个图层的外观 - 特别是对它应用模糊滤镜.如何使用此代码模糊此图层的一部分?(代码来自:Blur CALayer的Superlayer)
CALayer *blurLayer = [CALayer layer];
CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setDefaults];
blurLayer.backgroundFilters = [NSArray arrayWithObject:blur];
[self.superlayer addSublayer:blurLayer];
Run Code Online (Sandbox Code Playgroud)
期间没有超级层-init.
我在 OS X 上使用i686-apple-darwin11-llvm-gcc-4.2,我正在尝试从这个存档编译各种程序,特别是经典的 FitCurves.c,它通过一系列点拟合贝塞尔曲线。
http://tog.acm.org/resources/GraphicsGems/
某些 void 或 int 函数没有定义返回类型,这会产生警告。
ConcaveScan.c:149:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
compare_ind(u, v) int *u, *v; {return pt[*u].y <= pt[*v].y ? -1 : 1;}
Run Code Online (Sandbox Code Playgroud)
我不太确定:有一个错误
cc -g -Wno-implicit-int -Wreturn-type -c -o AAPolyScan.o AAPolyScan.c
AAPolyScan.c:106:4: error: non-void function 'drawPolygon' should return a value [-Wreturn-type]
return; /* (null polygon) */
Run Code Online (Sandbox Code Playgroud)
据我了解,编译器似乎认为它被隐式声明为一个返回 int 的函数,但该函数返回 void,从而导致错误。return从声明为返回 int 的函数在 C 中有意义吗?我在这里很困惑..
我怎样才能很好地编译它?我不一定无法编译,但警告信息并不多。它是使用旧语法编写的,我知道。
我在CALayer的子类中使用此代码,这些实例是根CALayer的子层.
-(void)setSelected:(bool)s {
selected=s;
if (s)
{
CATransform3D rot = CATransform3DMakeRotation(M_PI, 0, 1, 0);
rot.m34=-1.0 / 200;
[self setTransform:rot];
}
else
{
CATransform3D rot = CATransform3DMakeRotation(0, 0, 1, 0);
rot.m34=-1.0 / 200;
[self setTransform:rot];
}
}
Run Code Online (Sandbox Code Playgroud)
当选定属性设置为TRUE时,会发生以下情况:旋转完成直到角度等于M_PI/2,然后图层消失,因为它是正交的.动画的结尾是错误的:在动画的第一部分(例如在左侧)看起来增长的边缘在左侧而不是右侧结束动画.然而,内容被翻转.
我认为这与两个旋转矩阵之间的插值有关,但我无法准确理解发生了什么.
细节:动画看起来像这样:
翻转的内容是我想要实现的.
这是我得到的动画的帧.如你所见,梯形的小边始终在左边; 它应该在动画结尾的右侧(右上方框架).

假设我有这个几何形状:
glutSolidTeapot(1);
我想将其切成 8 个立方体,例如跨越 3 个平面 (xy)、(yz)、(xz),以制作 3D 拼图。
如何裁剪几何图形?
ios ×3
c ×2
c++ ×1
cocoa ×1
core-image ×1
llvm ×1
objective-c ×1
opencl ×1
opengl ×1
osx-yosemite ×1
perspective ×1
qt4 ×1