简体   繁体   English

是什么导致Uncaught TypeError:number不是函数?

[英]What is causing Uncaught TypeError: number is not a function?

As you can tell I'm trying to put together a very simple 3d engine. 你可以告诉我,我正在尝试组建一个非常简单的3D引擎。 I'm writing it in javascript. 我是用javascript写的。 I think it's likely that there is an error in the formula, but for the life of me I can't find it. 我认为公式中可能存在错误,但对于我的生活,我找不到它。 So now I'm thinking there might be something else I haven't considered yet. 所以现在我想可能还有其他我尚未考虑的事情。 The error occurs on line 21 (dx = Math.cos.....) 错误发生在第21行(dx = Math.cos .....)

Here is the relevant part of my code: 这是我的代码的相关部分:

// Camera Position in x,y,z
var c = [ 0,0,0 ];

// Viewer position [x,y,z]
var v = [ 0,0,0 ];

// Angle of view [x, y, z]
var a = [ 0.01, 0.01, 0.01 ];

var point =  [ 0,0, 50 ];

dx = Math.cos(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0])) - Math.sin(a[1])(point[2] - c[2]);
dy = Math.sin(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) + Math.cos(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));
dz = Math.cos(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) - Math.sin(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));

bx = (dx - v[0])(v[2]/dz);
by = (dy - v[1])(v[2]/dz);

你需要使用*来乘以:

dx = Math.cos(a[1])*(Math.sin(a[2])*(point[1] - c[1]) ... etc

I'm no Javascript expert, but I'm guessing Math.cos(a[1]) returns a number, and doing Math.cos(a[1])(5) is trying to use a number as a function. 我不是Javascript专家,但我猜Math.cos(a [1])返回一个数字,并且做Math.cos(a [1])(5)试图使用数字作为函数。 If you want to multiply two numbers you should use the '*' multiplication operator. 如果要将两个数相乘,则应使用'*'乘法运算符。

You cannot multiply by writing (a)(b)(c) like you do in math. 你不能像在数学中那样写(a)(b)(c)
This is parsed as two function calls, so you get an error that the (a) isn't a function. 这被解析为两个函数调用,因此您会收到(a)不是函数的错误。

Instead, write a * b * c . 相反,写a * b * c

You are leaving out multiplication operator, eg: 你要省略乘法运算符,例如:

x = Math.cos(a[1]) * (Math.sin(a[2]) * (...
-------------------^-----------------^

-- Rob - 罗布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM