我正在学习XNA以及http://creators.xna.com/en-US/上发现的几乎所有教育工具包.我总是在向量上看到对Normalize()的调用.我理解,normalize基本上将向量转换为单位长度,所以它给出的只是方向.
现在我的问题是何时进行标准化以及它对我有什么帮助.我正在进行2D编程,因此请在2D概念而不是3D中进行解释.
编辑:这是XNA工具包中的代码,为什么要调用Normalize?
if (currentKeyboardState.IsKeyDown(Keys.Left) ||
currentGamePadState.DPad.Left == ButtonState.Pressed)
{
catMovement.X -= 1.0f;
}
if (currentKeyboardState.IsKeyDown(Keys.Right) ||
currentGamePadState.DPad.Right == ButtonState.Pressed)
{
catMovement.X += 1.0f;
}
if (currentKeyboardState.IsKeyDown(Keys.Up) ||
currentGamePadState.DPad.Up == ButtonState.Pressed)
{
catMovement.Y -= 1.0f;
}
if (currentKeyboardState.IsKeyDown(Keys.Down) ||
currentGamePadState.DPad.Down == ButtonState.Pressed)
{
catMovement.Y += 1.0f;
}
float smoothStop = 1;
if (catMovement != Vector2.Zero)
{
catMovement.Normalize();
}
catPosition += catMovement * 10* smoothStop;
Run Code Online (Sandbox Code Playgroud)
}
这就是杀了我!
我有一个观点.在.h文件中我这样做:
@interface SearchLogs : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UIActionSheetDelegate, UIPickerViewDelegate> {
NSString *startDate;
NSDateFormatter *thisFormatter;
}
@property (nonatomic, retain) NSString *startDate;
@property (nonatomic, retain) NSDateFormatter *thisFormatter;
@end
Run Code Online (Sandbox Code Playgroud)
@interface和@properties中还有其他东西......但这就是我所做的startDate.
在.m文件中我这样做:
@implementation SearchLogs
@synthesize startDate;
@synthesize thisFormatter;
- (void)viewDidLoad {
NSLog(@"viewDidLoad\n");
[super viewDidLoad];
thisFormatter = [[NSDateFormatter alloc] init];
[thisFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *today = [[NSDate alloc] init];
NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);
startDate = [thisFormatter stringFromDate:today];
NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);
[today release];
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"viewWillAppear\n");
[super viewWillAppear:animated];
NSLog(@"startDate refcount: …Run Code Online (Sandbox Code Playgroud) 为什么以下代码会产生红色而不是黑色?
HTML:
<div class="error classA" att="A"></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div {
width: 100px;
height: 100px;
}
[att=A].classA {
background-color: red;
}
.error {
background-color: black;
}
Run Code Online (Sandbox Code Playgroud)
如果我移除[att=A],它会像预期的那样变黑.这是为什么 ?
您可以使用24位PNG制作一些很酷的技巧,它具有从不透明到完全透明的渐变.在PNG下方滑动的元素在褪色时似乎会消失.
这是否可以仅使用CSS与谷歌浏览器?我只需要针对这个浏览器.
我想避免使用具有不同opacity设置的一片1px高的元素.
谢谢
在PHP中,我们有number_format().传递给它的值如下:
number_format(3.00 * 0.175, 2);
Run Code Online (Sandbox Code Playgroud)
返回0.53,这是我所期望的.
但是,在JavaScript中使用 toFixed()
var num = 3.00 * 0.175;
num.toFixed(2);
Run Code Online (Sandbox Code Playgroud)
返回0.52.
好吧,也许toFixed不是我想要的......也许是这样的......
var num = 3.17 * 0.175;
var dec = 2;
Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
Run Code Online (Sandbox Code Playgroud)
不,这也不起作用.它将返回0.56.
如何number_format在JavaScript中获得一个不能给出错误答案的函数?
实际上我确实为js找到了number_format的实现,http://phpjs.org/functions/number_format ,但它遇到了同样的问题.
这里有什么用JavaScript四舍五入?我错过了什么?
最近在我正在开发的项目中,我需要将回调存储在静态成员数组中,如下所示:
class Example {
private static $_callbacks = array(
'foo'=>array('Example','do_foo'),
'bar'=>array('Example','do_bar')
);
private static function do_foo() { }
private static function do_bar() { }
}
Run Code Online (Sandbox Code Playgroud)
为了调用它们,我尝试了明显的(甚至是天真的)语法(在Example类中):
public static function do_callbacks() {
self::$_callbacks['foo']();
self::$_callbacks['bar']();
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这不起作用,导致我正在访问一个未定义的变量的通知,以及一个致命错误,指出self::$_callbacks['foo']需要可调用.
然后,我试过call_user_func:
public static function do_callbacks() {
call_user_func(self::$_callbacks['foo']);
call_user_func(self::$_callbacks['bar']);
}
Run Code Online (Sandbox Code Playgroud)
它奏效了!
我的问题是:
为什么我需要call_user_func用作中间人,而不是直接打电话给他们?
在Java中,我有一个创建按钮的对象.在该按钮的onclicklistener中,我想引用创建按钮的对象.
有什么简单的方法可以做到这一点吗?
我试图提供从管理者的角度对问题的回答:如果我们写在IronPython的,而不是C#应用程序,我们将承担什么整体性能损失?
这个问题针对那些可能已经进行过一些测试,基准测试或已经完成从C#迁移到IronPython的人,以量化惩罚.