在C++中,我们可以围绕任意轴旋转一个点:
void radRotateAxis( float a, float b, float c, float theta )
{
float newX = (
x*( a*a*(1-cos(theta)) + cos(theta) ) +
y*( a*b*(1-cos(theta)) - c*sin(theta) ) +
z*( a*c*(1-cos(theta)) + b*sin(theta) ) );
float newY = (
x*( a*b*(1-cos(theta)) + c*sin(theta) ) +
y*( b*b*(1-cos(theta)) + cos(theta) ) +
z*( b*c*(1-cos(theta)) - a*sin(theta) ) );
float newZ = (
x*( a*c*(1-cos(theta)) - b*sin(theta) ) +
y*( b*c*(1-cos(theta)) + a*sin(theta) ) +
z*( c*c*(1-cos(theta)) + cos(theta) ) );
x … 在google appengine上,您可以通过执行查询来检索哈希键值
select __key__ from furniture
但是appengine数据存储区为每种类型维护了一个很好的自动增量字段ID.
如何从查询中访问它?
select ID from furniture
不行
在C++中是self不是完全可以互换this?
它似乎与消息传递一起工作([ self sayHi ]可以在任何方法中工作).
我不太明白为什么我不能使用self来访问对象的私有成员(在下面的示例中,我显示我无法使用self.width)
#import <Foundation/Foundation.h>
// Write an Objective-C class
@interface Rectangle : NSObject
{
int width ;
}
-(int)getWidth;
-(void)setWidth:(int)w;
-(void)sayHi;
-(void)sayHi:(NSString*)msg ;
@end
@implementation Rectangle
-(int)getWidth
{
// <b>return self.width ; // ILLEGAL, but why?</b>
// why can't I return self.width here?
// why does it think that's a "method"?
return width ;
}
-(void)setWidth:(int)w
{
// <b>self.width = w ; // ILLEGAL</b>
// again here, I …Run Code Online (Sandbox Code Playgroud) 在objective-c中你看到了
[object retain] ;
向retain对象发送消息意味着什么,为什么要使用它?
我正在尝试在C++中创建一个静态结构:
static struct Brushes
{
static HBRUSH white ;
static HBRUSH yellow ;
} ;
但它不起作用,我得到:
Error 4 error LNK2001: unresolved external symbol "public: static struct HBRUSH__ * Brushes::white"
为什么?
这样做是为了能够使用Brushes::white,Brushes::yellow在整个程序中,而无需创建的实例Brushes.
所以,我使用AlphaBlend () 将一个矩形从一个 HBITMAP 复制到另一个。
它有效,但有一个问题。每当我使用 FillRect() 函数时,HBITMAP 中的 alpha 值都会被猛击为 0。每次。
因此,在每次调用诸如 FillRect() 之类的 Win32 api 函数之后,我必须 GetDIBits(),将 alpha 重置回 255,然后是 SetDIBits()。
那么,有没有办法创建 HBRUSH 或以其他方式告诉 FillRect() 不要触摸它要绘制到的 HBITMAP 中的 alpha 通道值?
好吧,我试图避免使用已弃用的DirectInput.
但是我需要在游戏的每个"框架"或"迭代"中抢夺所有关键状态,以便我可以采取相应的行动.例如,如果玩家在VK_RIGHT键上按下,那么他将在该帧上仅移动一个smidgen.
WM_INPUT消息的问题是它们每帧可能出现不可预测的次数,因为游戏循环的编写方式如下:
MSG message ;
while( 1 )
{
if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) )
{
if( message.message == WM_QUIT )
{
break ; // bail when WM_QUIT
}
TranslateMessage( &message ) ;
DispatchMessage( &message ) ;
}
else
{
// No messages, so run the game.
Update() ;
Draw() ;
}
}
因此,如果堆叠了多个 WM_INPUT消息,那么它们将在Update()/ Draw()之前被处理.
我通过使用BOOL数组来解决这个问题,以记住关键是什么:
bool array_of_keys_that_are_down[ 256 ] ;
case WM_INPUT :
if( its keyboard input )
{
array_of_keys_that_are_down[ VK_CODE … 我只是想知道,如果一个线程处于关键部分,它是否可以被抢占?
如果线程A抢占,并且互斥锁被线程A卡住,那么可以做些什么呢?
MSVC++"实用程序"标头中make_pair的定义是:
template<class _Ty1,
class _Ty2> inline
pair<_Ty1, _Ty2> make_pair(_Ty1 _Val1, _Ty2 _Val2)
{ // return pair composed from arguments
return (pair<_Ty1, _Ty2>(_Val1, _Val2));
}
我一直使用make_pair,但不将参数类型放在尖括号中:
map<string,int> theMap ;
theMap.insert( make_pair( "string", 5 ) ) ;
我不应该告诉make_pair第一个论点是std::string不是char*?
怎么知道的?