- 浏览: 99601 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
蜗居之家:
akka2.0的如何实现1.2的功能 onReceive中接收 ...
Akka2使用探索1(Remoting) -
chenyehui:
这有点像nio, read和write的动作不需要user进程 ...
使用Akka的Actor和Future简单地实现并发处理 -
chenyehui:
hi 请问下 你这种方式 看不出来和Java 多线程的区别在哪 ...
使用Akka的Actor和Future简单地实现并发处理 -
henry_wu001:
这种调用是不是同步的,会不会阻塞?
Akka2使用探索5(Typed Actors) -
ZZX19880809:
啥ji巴玩意,copy也不看下,这啥样子了
Akka2使用探索7——“云计算”示例(Actor、Future、Remoting、Router、Deploy、异步、并发使用Demo)
隐藏行号 复制代码 ? 源代码
-
/*
-
* Copyright (c) 2003-2009 jMonkeyEngine
-
* All rights reserved.
-
*
-
* Redistribution and use in source and binary forms, with or without
-
* modification, are permitted provided that the following conditions are
-
* met:
-
*
-
* * Redistributions of source code must retain the above copyright
-
* notice, this list of conditions and the following disclaimer.
-
*
-
* * Redistributions in binary form must reproduce the above copyright
-
* notice, this list of conditions and the following disclaimer in the
-
* documentation and/or other materials provided with the distribution.
-
*
-
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
-
* may be used to endorse or promote products derived from this software
-
* without specific prior written permission.
-
*
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
*/
-
-
package com.jme.math;
-
import java.io.Externalizable;
-
import java.io.IOException;
-
import java.io.ObjectInput;
-
import java.io.ObjectOutput;
-
import java.util.logging.Logger;
-
import com.jme.util.export.InputCapsule;
-
import com.jme.util.export.JMEExporter;
-
import com.jme.util.export.JMEImporter;
-
import com.jme.util.export.OutputCapsule;
-
import com.jme.util.export.Savable;
-
/*
-
* -- Added *Local methods to cut down on object creation - JS
-
*/
-
-
/**
-
* <code>Vector3f</code> defines a Vector for a three float value tuple.
-
* <code>Vector3f</code> can represent any three dimensional value, such as a
-
* vertex, a normal, etc. Utility methods are also included to aid in
-
* mathematical calculations.<br/>
-
* 3维向量类
-
*
-
* @author Mark Powell
-
* @author Joshua Slack
-
*/
-
public class Vector3f implements Externalizable, Savable, Cloneable {
-
private static final Logger logger = Logger.getLogger(Vector3f.class
-
.getName());
-
private static final long serialVersionUID = 1L;
-
public final static Vector3f ZERO = new Vector3f(0, 0, 0);
-
public final static Vector3f UNIT_X = new Vector3f(1, 0, 0);
-
public final static Vector3f UNIT_Y = new Vector3f(0, 1, 0);
-
public final static Vector3f UNIT_Z = new Vector3f(0, 0, 1);
-
public final static Vector3f UNIT_XYZ = new Vector3f(1, 1, 1);
-
/**
-
* the x value of the vector.
-
*/
-
public float x;
-
/**
-
* the y value of the vector.
-
*/
-
public float y;
-
/**
-
* the z value of the vector.
-
*/
-
public float z;
-
/**
-
* Constructor instantiates a new <code>Vector3f</code> with default values
-
* of (0,0,0).
-
*
-
*/
-
public Vector3f() {
-
x = y = z = 0;
-
}
-
/**
-
* Constructor instantiates a new <code>Vector3f</code> with provides
-
* values.
-
*
-
* @param x
-
* the x value of the vector.
-
* @param y
-
* the y value of the vector.
-
* @param z
-
* the z value of the vector.
-
*/
-
public Vector3f(float x, float y, float z) {
-
this.x = x;
-
this.y = y;
-
this.z = z;
-
}
-
/**
-
* Constructor instantiates a new <code>Vector3f</code> that is a copy of
-
* the provided vector
-
*
-
* @param copy
-
* The Vector3f to copy
-
*/
-
public Vector3f(Vector3f copy) {
-
this.set(copy);
-
}
-
/**
-
* <code>set</code> sets the x,y,z values of the vector based on passed
-
* parameters.
-
*
-
* @param x
-
* the x value of the vector.
-
* @param y
-
* the y value of the vector.
-
* @param z
-
* the z value of the vector.
-
* @return this vector
-
*/
-
public Vector3f set(float x, float y, float z) {
-
this.x = x;
-
this.y = y;
-
this.z = z;
-
return this;
-
}
-
/**
-
* <code>set</code> sets the x,y,z values of the vector by copying the
-
* supplied vector.
-
*
-
* @param vect
-
* the vector to copy.
-
* @return this vector
-
*/
-
public Vector3f set(Vector3f vect) {
-
this.x = vect.x;
-
this.y = vect.y;
-
this.z = vect.z;
-
return this;
-
}
-
/**
-
*
-
* <code>add</code> adds a provided vector to this vector creating a
-
* resultant vector which is returned. If the provided vector is null, null
-
* is returned.<br/>
-
* 向量加法(不改变自身和参数)
-
*
-
* Neither 'this' nor 'vec' are modified.
-
*
-
* @param vec
-
* the vector to add to this.
-
* @return the resultant vector.
-
*/
-
public Vector3f add(Vector3f vec) {
-
if (null == vec) {
-
logger.warning("Provided vector is null, null returned.");
-
return null;
-
}
-
return new Vector3f(x + vec.x, y + vec.y, z + vec.z);
-
}
-
/**
-
*
-
* <code>add</code> adds the values of a provided vector storing the values
-
* in the supplied vector.<br/>
-
* 向量加法
-
*
-
* @param vec
-
* the vector to add to this
-
* @param result
-
* the vector to store the result in
-
* @return result returns the supplied result vector.
-
*/
-
public Vector3f add(Vector3f vec, Vector3f result) {
-
result.x = x + vec.x;
-
result.y = y + vec.y;
-
result.z = z + vec.z;
-
return result;
-
}
-
/**
-
* <code>addLocal</code> adds a provided vector to this vector internally,
-
* and returns a handle to this vector for easy chaining of calls. If the
-
* provided vector is null, null is returned.<br/>
-
* 向量加法(自加)
-
*
-
* @param vec
-
* the vector to add to this vector.
-
* @return this
-
*/
-
public Vector3f addLocal(Vector3f vec) {
-
if (null == vec) {
-
logger.warning("Provided vector is null, null returned.");
-
return null;
-
}
-
x += vec.x;
-
y += vec.y;
-
z += vec.z;
-
return this;
-
}
-
/**
-
*
-
* <code>add</code> adds the provided values to this vector, creating a new
-
* vector that is then returned.<br/>
-
* 向量加法
-
*
-
* @param addX
-
* the x value to add.
-
* @param addY
-
* the y value to add.
-
* @param addZ
-
* the z value to add.
-
* @return the result vector.
-
*/
-
public Vector3f add(float addX, float addY, float addZ) {
-
return new Vector3f(x + addX, y + addY, z + addZ);
-
}
-
/**
-
* <code>addLocal</code> adds the provided values to this vector internally,
-
* and returns a handle to this vector for easy chaining of calls.<br/>
-
* 向量加法(自加)
-
*
-
* @param addX
-
* value to add to x
-
* @param addY
-
* value to add to y
-
* @param addZ
-
* value to add to z
-
* @return this
-
*/
-
public Vector3f addLocal(float addX, float addY, float addZ) {
-
x += addX;
-
y += addY;
-
z += addZ;
-
return this;
-
}
-
/**
-
*
-
* <code>scaleAdd</code> multiplies this vector by a scalar then adds the
-
* given Vector3f.<br/>
-
* 向量加乘(先乘一个标量,再加一个向量)
-
*
-
* @param scalar
-
* the value to multiply this vector by.
-
* @param add
-
* the value to add
-
*/
-
public void scaleAdd(float scalar, Vector3f add) {
-
x = x * scalar + add.x;
-
y = y * scalar + add.y;
-
z = z * scalar + add.z;
-
}
-
/**
-
*
-
* <code>scaleAdd</code> multiplies the given vector by a scalar then adds
-
* the given vector.<br/>
-
* 向量加乘(将mult乘以标量scalar,再加上向量add,返回this)
-
*
-
* @param scalar
-
* the value to multiply this vector by.
-
* @param mult
-
* the value to multiply the scalar by
-
* @param add
-
* the value to add
-
*/
-
public void scaleAdd(float scalar, Vector3f mult, Vector3f add) {
-
this.x = mult.x * scalar + add.x;
-
this.y = mult.y * scalar + add.y;
-
this.z = mult.z * scalar + add.z;
-
}
-
/**
-
*
-
* <code>dot</code> calculates the dot product of this vector with a
-
* provided vector. If the provided vector is null, 0 is returned.<br/>
-
* 向量点乘
-
*
-
* @param vec
-
* the vector to dot with this vector.
-
* @return the resultant dot product of this vector and a given vector.
-
*/
-
public float dot(Vector3f vec) {
-
if (null == vec) {
-
logger.warning("Provided vector is null, 0 returned.");
-
return 0;
-
}
-
return x * vec.x + y * vec.y + z * vec.z;
-
}
-
/**
-
* Returns a new vector which is the cross product of this vector with the
-
* specified vector.<br/>
-
* 叉乘(不改变自身和参数)
-
* <P>
-
* Neither 'this' nor v are modified. The starting value of 'result'
-
* </P>
-
*
-
* @param v
-
* the vector to take the cross product of with this.
-
* @return the cross product vector.
-
*/
-
public Vector3f cross(Vector3f v) {
-
return cross(v, null);
-
}
-
/**
-
* <code>cross</code> calculates the cross product of this vector with a
-
* parameter vector v. The result is stored in <code>result</code><br/>
-
* 叉乘(this与v叉乘,结果存入result中。不改变自身和参数)
-
* <P>
-
* Neither 'this' nor v are modified. The starting value of 'result' (if
-
* any) is ignored.
-
* </P>
-
*
-
* @param v
-
* the vector to take the cross product of with this.
-
* @param result
-
* the vector to store the cross product result.
-
* @return result, after recieving the cross product vector.
-
*/
-
public Vector3f cross(Vector3f v, Vector3f result) {
-
return cross(v.x, v.y, v.z, result);
-
}
-
/**
-
* <code>cross</code> calculates the cross product of this vector with a
-
* Vector comprised of the specified other* elements. The result is stored
-
* in <code>result</code>, without modifying either 'this' or the 'other*'
-
* values.<br/>
-
* 叉乘(this与参数叉乘,结果存在参数result中)
-
*
-
* @param otherX
-
* x component of the vector to take the cross product of with
-
* this.
-
* @param otherY
-
* y component of the vector to take the cross product of with
-
* this.
-
* @param otherZ
-
* z component of the vector to take the cross product of with
-
* this.
-
* @param result
-
* the vector to store the cross product result.
-
* @return result, after recieving the cross product vector.
-
*/
-
public Vector3f cross(float otherX, float otherY, float otherZ,
-
Vector3f result) {
-
if (result == null)
-
result = new Vector3f();
-
float resX = ((y * otherZ) - (z * otherY));
-
float resY = ((z * otherX) - (x * otherZ));
-
float resZ = ((x * otherY) - (y * otherX));
-
result.set(resX, resY, resZ);
-
return result;
-
}
-
/**
-
* <code>crossLocal</code> calculates the cross product of this vector with
-
* a parameter vector v.<br/>
-
* 自身叉乘(this与参数叉乘,结果存入自身)
-
*
-
* @param v
-
* the vector to take the cross product of with this.
-
* @return this.
-
*/
-
public Vector3f crossLocal(Vector3f v) {
-
return crossLocal(v.x, v.y, v.z);
-
}
-
/**
-
* <code>crossLocal</code> calculates the cross product of this vector with
-
* a parameter vector v.<br/>
-
* 自身叉乘(this与参数叉乘,结果存入自身)
-
*
-
* @param otherX
-
* x component of the vector to take the cross product of with
-
* this.
-
* @param otherY
-
* y component of the vector to take the cross product of with
-
* this.
-
* @param otherZ
-
* z component of the vector to take the cross product of with
-
* this.
-
* @return this.
-
*/
-
public Vector3f crossLocal(float otherX, float otherY, float otherZ) {
-
float tempx = (y * otherZ) - (z * otherY);
-
float tempy = (z * otherX) - (x * otherZ);
-
z = (x * otherY) - (y * otherX);
-
x = tempx;
-
y = tempy;
-
return this;
-
}
-
/**
-
* <code>length</code> calculates the magnitude of this vector.<br/>
-
* 向量长度
-
*
-
* @return the length or magnitude of the vector.
-
*/
-
public float length() {
-
return FastMath.sqrt(lengthSquared());
-
}
-
/**
-
* <code>lengthSquared</code> calculates the squared value of the magnitude
-
* of the vector.<br/>
-
* 向量长度平方
-
*
-
* @return the magnitude squared of the vector.
-
*/
-
public float lengthSquared() {
-
return x * x + y * y + z * z;
-
}
-
/**
-
* <code>distanceSquared</code> calculates the distance squared between this
-
* vector and vector v.<br/>
-
* 向量this与参赛v间的距离平方
-
*
-
* @param v
-
* the second vector to determine the distance squared.
-
* @return the distance squared between the two vectors.
-
*/
-
public float distanceSquared(Vector3f v) {
-
double dx = x - v.x;
-
double dy = y - v.y;
-
double dz = z - v.z;
-
return (float) (dx * dx + dy * dy + dz * dz);
-
}
-
/**
-
* <code>distance</code> calculates the distance between this vector and
-
* vector v.<br/>
-
* 向量this与参赛v间的距离
-
*
-
* @param v
-
* the second vector to determine the distance.
-
* @return the distance between the two vectors.
-
*/
-
public float distance(Vector3f v) {
-
return FastMath.sqrt(distanceSquared(v));
-
}
-
/**
-
* <code>mult</code> multiplies this vector by a scalar. The resultant
-
* vector is returned. "this" is not modified.<br/>
-
* 向量标量乘
-
*
-
* @param scalar
-
* the value to multiply this vector by.
-
* @return the new vector.
-
*/
-
public Vector3f mult(float scalar) {
-
return new Vector3f(x * scalar, y * scalar, z * scalar);
-
}
-
/**
-
*
-
* <code>mult</code> multiplies this vector by a scalar. The resultant
-
* vector is supplied as the second parameter and returned. "this" is not
-
* modified.<br/>
-
* 向量标量乘,结果存入product。
-
*
-
* @param scalar
-
* the scalar to multiply this vector by.
-
* @param product
-
* the product to store the result in.
-
* @return product
-
*/
-
public Vector3f mult(float scalar, Vector3f product) {
-
if (null == product) {
-
product = new Vector3f();
-
}
-
product.x = x * scalar;
-
product.y = y * scalar;
-
product.z = z * scalar;
-
return product;
-
}
-
/**
-
* <code>multLocal</code> multiplies this vector by a scalar internally, and
-
* returns a handle to this vector for easy chaining of calls.<br/>
-
* 向量标量乘this
-
*
-
* @param scalar
-
* the value to multiply this vector by.
-
* @return this
-
*/
-
public Vector3f multLocal(float scalar) {
-
x *= scalar;
-
y *= scalar;
-
z *= scalar;
-
return this;
-
}
-
/**
-
* <code>multLocal</code> multiplies a provided vector to this vector
-
* internally, and returns a handle to this vector for easy chaining of
-
* calls. If the provided vector is null, null is returned. The provided
-
* 'vec' is not modified.<br/>
-
* 向量标量乘一个向量(对应的x、y、z分量分别相乘),结果改变this
-
*
-
* @param vec
-
* the vector to mult to this vector.
-
发表评论
-
Groovy元编程MOP(ExpandoMetaClass:EMC)的应用场景
2012-09-20 16:49 2555使用ExpandoMetaClass和Category可 ... -
用Groovy源编程(MOP)动态拦截(AOP)方法(比如记录String的concat和toUpperCase方法的耗费时间)
2012-09-10 17:36 2993实现AOP的方式有很多种,像Spring的AOP,它只能 ... -
序列化:Serializable和Externalizable
2012-08-29 15:25 957Externalizable是深度定制序列化。如果同时实 ... -
自定义数据类型的数据库映射方案
2012-08-29 14:24 2435基础数据类型,如String、Integer、Date、 ... -
Akka2使用探索7——“云计算”示例(Actor、Future、Remoting、Router、Deploy、异步、并发使用Demo)
2012-08-22 15:39 1854假设有一个很耗时的运算,单台机器已经没法满足需求,这时你 ... -
Akka2使用探索6(Futures)——实现并发和异步
2012-08-14 18:01 4131Future用来获取某个并 ... -
Akka2使用探索5(Typed Actors)
2012-08-10 11:16 2361Akka 中的有类型 Actor 是 Active Ob ... -
Akka2使用探索3(Duration 和 Deadline)
2012-08-09 17:51 1398akka提供了两个关于时长的数据类型:Duration ... -
Akka2使用探索4(Actors)
2012-08-09 09:25 2195Actor模型为编写并发和分布式系统提供了一种更高的抽象 ... -
Akka2使用探索2(Configuration)
2012-08-09 09:21 1520akka2使用Typesafe Config库,可以 ... -
Akka2使用探索1(Remoting)
2012-08-09 09:20 7805akka从1.2升级到现在的2.0.2后有了很大的改变。 ... -
在父类获取子类属性
2010-06-29 11:53 2414在父类中能获取子类的属性吗?一般情况下是不行的,因为孩子尚未出 ... -
3x3矩阵类
2009-11-11 16:03 10131: package com.jme.math; ...
相关推荐
vector3 类,实现的功能 1、重载赋值运算符“=” 2、重载“==”和“!=”操作符 3、置为零向量 4、重载一元运算符“-” 5、重载二元预算法“+”“-” 6、标量的乘除法 7、重载自反运算符 8、向量单位化 9、向量的...
PVectorJS 基于Processing PVector类的具有可链接方法JavaScript 2D / 3D向量类,用于常见的向量操作安装Node.js / Browserify npm install pvectorjs --save const PVector = require ( 'pvectorjs' )const vec = ...
向量类的定义通常包括坐标(如x、y、z)以及各种基本操作,例如加法、减法、标量乘法(点乘)和向量乘法(叉乘)。以下是一个详细的关于C#中向量类定义和向量四则运算的阐述: **向量类定义** 一个简单的向量类...
第6章 3D向量类 …… 第7章 矩阵 第8章 矩阵和线性变换 第9章 矩阵的更多知识 第10章 3D中的方位与角位移 第11章 C++实现 第12章 几何图元 第13章 几何检测 第14章 三角网络 第15章 图形数学 第16章 可见性检测 第17...
在Java 2 Micro Edition (J2ME)平台上,2D和3D向量几何图形学是构建游戏、应用程序和可视化工具的关键技术。向量几何图形学涉及到数学中的向量概念,以及如何在2D和3D空间中使用它们来表示位置、方向、速度和力。...
第6章 3D向量类 …… 第7章 矩阵 第8章 矩阵和线性变换 第9章 矩阵的更多知识 第10章 3D中的方位与角位移 第11章 C++实现 第12章 几何图元 第13章 几何检测 第14章 三角网络 第15章 图形数学 第16章 可见性检测 第17...
在C++编程中,向量类的实现是一个常见的任务,特别是在处理图形学、物理模拟或者游戏开发等场景。向量可以表示空间中的位置、速度、加速度等多种概念,因此理解和自定义向量类是非常重要的。这里我们将深入探讨提供...
4. Tvector.cpp 和 Tvector.h:定义了3D向量类,向量在3D空间中广泛用于表示位置、速度、方向和法线等。碰撞检测中,向量常常用来计算距离、方向和速度差,以判断两个物体是否相交。 5. Tray.cpp 和 Tray.h:可能...
Vector3d 类:简单的3D向量类 RotationMatrix 类:实现了一个简单的3*3矩阵,仅用作旋转;矩阵假设为正交的,在变换时指定方向 Matrix4_3 类:实现4*3转换矩阵,能够表达任何3D仿射变换 EulerAngles 类:该类用于表示...
在VC++ 9.0环境下,向量类的实现是一个重要的编程工具,特别是在3D图形学、物理模拟和游戏开发等领域。向量是数学中一个非常基础且实用的概念,它代表了一个具有大小和方向的量。在编程中,向量类通常用来表示二维或...
这是一个使用指令实现数学 3D 向量类的简单 C++ 库。 它基于。 例子 测试.cpp # include # include " vector3.h " int main () { Vector3 a ( 1 , 1 , 1 ); Vector3 b ( 2 , 0 , - 1 ); std::cout << " a...
Unity3D 中的向量几何 Unity3D 中的向量几何是一种广泛应用于游戏编程中的数学工具。游戏程序员可以使用向量几何来模拟物理现象和基本的 AI。向量几何可以帮助游戏程序员更好地理解游戏中的坐标系和运动物体的轨迹...
点云法向量是3D空间中描述表面方向的关键元素,它表示了点云中每个点表面局部的正向。在计算机视觉、机器人导航、3D建模等领域,理解和计算点云的法向量至关重要。k-近邻点估计法(k-Nearest Neighbors, k-NN)是一...
例如,以下代码创建了一个位于原点上方1单位的3D向量: ```csharp var aPosition : Vector3; aPosition = new Vector3(0, 1, 0); ``` 或者,你可以直接通过成员变量设置各个分量: ```csharp var aPosition : ...
在3D图形编程中,向量函数库是至关重要的组成部分,它提供了处理三维空间中向量的基本操作。向量不仅用于表示位置,还用于描述方向、速度和力等概念。本示例源代码集中展示了几个关键的向量操作,包括向量的加法、...
- `Vector3d.cpp`:可能实现了3D向量类,用于表示顶点和法线。 - `Matrix33.cpp`:可能包含了3x3矩阵类,用于进行3D空间中的变换操作。 - `AxisSystem.cpp`:可能包含了轴系的绘制代码,用于显示坐标轴。 - `...
如果有疏忽或错误的地方...这里一共设计了两个类:Location,Point,分别代表二维和三维坐标(向量)类。 对类的+ - * / >> 都进行了重载。 大部分函数使用及功能都有详细说明,注释内容说明的均是上个函数和语句的功能
在3D图形编程和游戏开发中,向量是至关重要的概念,它们被广泛用于表示位置、速度、方向等。Visual C++ 和 DirectX9 是开发者常用的技术栈,用于创建高性能的3D应用程序。在这个3D教程中,我们将深入探讨向量叉积这...
[Unity游戏开发]向量在游戏开发中的应用(三)博客中的案例源码。 本Demo使用的的开发工具是Unity5.0.1f1和VS2013,建议下载源码后用Unity5.0.1f1或者更高的版本打开。 本源码可以配合Sheh伟伟的博客来学习。
在计算机科学领域,尤其是计算机图形学中,3D数学库是不可或缺的一部分,它涉及到的核心概念主要包括矩阵、向量和四元数。这些概念是构建3D世界、进行几何变换和动画制作的基础。下面将详细解释这三个核心概念及其在...