本文整理汇总了C#中System.Vector3.Normalise方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Normalise方法的具体用法?C# Vector3.Normalise怎么用?C# Vector3.Normalise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector3
的用法示例。
在下文中一共展示了Vector3.Normalise方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateScene
public override void CreateScene()
{
sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;
sceneMgr.ShadowFarDistance = 1000;
MovableObject.DefaultVisibilityFlags = 0x00000001;
// Set ambient light
sceneMgr.AmbientLight = new ColourValue(0.3f, 0.3f, 0.2f);
Light l = sceneMgr.CreateLight("Light2");
Vector3 dir = new Vector3(-1, -1, 0);
dir.Normalise();
l.Type = Light.LightTypes.LT_DIRECTIONAL;
l.Direction = dir;
l.SetDiffuseColour(1, 1, 0.8f);
l.SetSpecularColour(1, 1, 1);
Entity pEnt;
// House
pEnt = sceneMgr.CreateEntity("1", "tudorhouse.mesh");
SceneNode n1 = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(350, 450, -200));
n1.AttachObject(pEnt);
pEnt = sceneMgr.CreateEntity("2", "tudorhouse.mesh");
SceneNode n2 = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(-350, 450, -200));
n2.AttachObject(pEnt);
pEnt = sceneMgr.CreateEntity("3", "knot.mesh");
mSpinny = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(0, 0, 300));
mSpinny.AttachObject(pEnt);
pEnt.SetMaterialName("Examples/MorningCubeMap");
sceneMgr.SetSkyBox(true, "Examples/MorningSkyBox");
Plane plane;
plane.normal = Vector3.UNIT_Y;
plane.d = 100;
MeshManager.Singleton.CreatePlane("Myplane",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane,
1500, 1500, 10, 10, true, 1, 5, 5, Vector3.UNIT_Z);
Entity pPlaneEnt = sceneMgr.CreateEntity("plane", "Myplane");
pPlaneEnt.SetMaterialName("Examples/Rockwall");
pPlaneEnt.CastShadows = false;
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(pPlaneEnt);
camera.SetPosition(-400, 50, 900);
camera.LookAt(0, 80, 0);
AddCompositors();
}
示例2: Missile2
/// <summary>
/// Creates instance at given position and traveling to given target (position).
/// </summary>
/// <param name="position">The bullet start position.</param>
/// <param name="solSystem">The bullet SolarSystem.</param>
/// <param name="targetPosition">The taget position.</param>
/// <param name="rec">The bullet't hit reciever.</param>
public Missile2(Vector3 position, SolarSystem solSystem, Vector3 targetPosition, IBulletStopReciever rec)
{
this.position = position;
this.name = Game.IGameObjectCreator.GetUnusedName(typeof(Missile2).ToString());
this.solarSystem = solSystem;
this.reciever = rec;
// Calucalates a distance and a direction.
direction = targetPosition - position;
distance = direction.Normalise();
// Registers IBullet and SolarSystem set visibility.
solarSystem.AddIBullet(this);
// Caluculate constants for hidden collision.
a = -(targetPosition.z - position.z);
b = (targetPosition.x - position.x);
c = -a * targetPosition.x - b * targetPosition.z;
destinationDevider = (float)System.Math.Sqrt(a * a + b * b);
}
示例3: process
// *
// Run image manipulation
// \return Pointer to image buffer which has been set in the constructor.
//
public override TextureBuffer process() {
int w = (int)mBuffer.getWidth();
int h = (int)mBuffer.getHeight();
if (mParam != null && (mParam.getWidth() < w || mParam.getHeight() < h))
return mBuffer;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (mParam != null) {
if (mColourMask) {
ColourValue pixelA = mBuffer.getPixel(x, y);
ColourValue pixelB = mParam.getPixel(x, y);
Vector3 c1 = new Vector3(pixelA.r * 255.0f, pixelA.g * 255.0f, pixelA.b * 255.0f);
Vector3 c2 = new Vector3(pixelB.r * 255.0f, pixelB.g * 255.0f, pixelB.b * 255.0f);
float c1norm = c1.Normalise();
float c2norm = c2.Normalise();
float correctness = 0;
if (c1norm > 0.0f && c2norm > 0.0f)
correctness = c1.x * c2.x + c1.y * c2.y + c1.z * c2.z;
mBuffer.setAlpha(x, y, (byte)(pixelA.a * correctness));
}
else {
ColourValue pixel = mParam.getPixel(x, y);
float alpha = (pixel.r + pixel.g + pixel.b) / 3.0f;
mBuffer.setAlpha(x, y, mBuffer.getPixelAlphaReal(x, y) * alpha);
}
}
else {
byte a = mBuffer.getPixelAlphaByte(x, y);
mBuffer.setPixel(x, y, a, a, a, 255);
}
}
}
Utils.log("Modify texture with alphamask filter");
return mBuffer;
}
示例4: button1_Click_1
private void button1_Click_1(object sender, EventArgs e)
{
ParticleEmitter pe = App.Singleton.xGetCurrentEmitter();
if (pe == null) return;
const float EPS = 1e-3f;
// update values based on settings
try
{
Vector3 pos = new Vector3(float.Parse(posx.Text),
float.Parse(posy.Text), float.Parse(posz.Text));
Vector3 dir = new Vector3(float.Parse(dirx.Text),
float.Parse(diry.Text), float.Parse(dirz.Text));
if (dir.Length <= EPS) throw new Exception("Direction length is zero");
dir.Normalise();
ColourValue colorStart = new ColourValue(
color0.BackColor.R/255.0f,
color0.BackColor.G/255.0f,
color0.BackColor.B/255.0f,
(float)color0a.Value/255.0f);
ColourValue colorEnd = new ColourValue(
color1.BackColor.R / 255.0f,
color1.BackColor.G / 255.0f,
color1.BackColor.B / 255.0f,
(float)color1a.Value / 255.0f);
uint emission = uint.Parse(emissBox.Text);
if (emission == 0) throw new Exception("Emission cannot be 0");
float angle = float.Parse(angleBox.Text);
if (angle < -EPS) throw new Exception("Angle cannot be negative");
Vector2 vel = new Vector2(float.Parse(velMin.Text), float.Parse(velMax.Text));
if (vel.x > vel.y + EPS) throw new Exception("Invalid velocity range");
Vector2 life = new Vector2(float.Parse(lifetimeMin.Text), float.Parse(lifetimeMax.Text));
if (life.x > life.y + EPS) throw new Exception("Invalid lifetime range");
Vector2 dur = new Vector2(float.Parse(durMin.Text), float.Parse(durMax.Text));
if (dur.x > dur.y + EPS) throw new Exception("Invalid duration range");
Vector2 delay = new Vector2(float.Parse(delayMin.Text), float.Parse(delayMax.Text));
if (delay.x > delay.y + EPS) throw new Exception("Invalid delay range");
pe.SetColour(colorStart, colorEnd);
pe.SetDuration(dur.x, dur.y);
pe.SetParticleVelocity(vel.x, vel.y);
pe.SetRepeatDelay(delay.x, delay.y);
pe.SetTimeToLive(life.x, life.y);
pe.Angle = (new Degree(angle)).ValueRadians;
pe.EmissionRate = emission;
pe.Direction = dir;
pe.Position = pos;
App.Singleton.xUpdateEmitter(pe);
}
catch (Exception err)
{
MessageBox.Show("Error: " + err);
}
UpdateEmitterValues(pe);
}
示例5: SetupTrailLights
void SetupTrailLights()
{
sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);
Vector3 dir = new Vector3(-1, -1, 0.5f);
dir.Normalise();
Light l = sceneMgr.CreateLight("light1");
l.Type = Light.LightTypes.LT_DIRECTIONAL;
l.Direction = dir;
NameValuePairList pairList = new NameValuePairList();
pairList["numberOfChains"] = "2";
pairList["maxElements"] = "80";
RibbonTrail trail = (RibbonTrail)(
sceneMgr.CreateMovableObject("1", "RibbonTrail", pairList));
trail.MaterialName = "Examples/LightRibbonTrail";
trail.TrailLength = 400;
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(trail);
// Create 3 nodes for trail to follow
SceneNode animNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
animNode.Position = new Vector3(50,30,0);
Animation anim = sceneMgr.CreateAnimation("an1", 14);
anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode);
TransformKeyFrame kf = track.CreateNodeKeyFrame(0);
kf.Translate = new Vector3(50,30,0);
kf = track.CreateNodeKeyFrame(2);
kf.Translate = new Vector3(100, -30, 0);
kf = track.CreateNodeKeyFrame(4);
kf.Translate = new Vector3(120, -100, 150);
kf = track.CreateNodeKeyFrame(6);
kf.Translate = new Vector3(30, -100, 50);
kf = track.CreateNodeKeyFrame(8);
kf.Translate = new Vector3(-50, 30, -50);
kf = track.CreateNodeKeyFrame(10);
kf.Translate = new Vector3(-150, -20, -100);
kf = track.CreateNodeKeyFrame(12);
kf.Translate = new Vector3(-50, -30, 0);
kf = track.CreateNodeKeyFrame(14);
kf.Translate = new Vector3(50,30,0);
AnimationState animState = sceneMgr.CreateAnimationState("an1");
animState.Enabled = true;
mAnimStateList.Add(animState);
trail.SetInitialColour(0, 1.0f, 0.8f, 0);
trail.SetColourChange(0, 0.5f, 0.5f, 0.5f, 0.5f);
trail.SetInitialWidth(0, 5);
trail.AddNode(animNode);
// Add light
Light l2 = sceneMgr.CreateLight("l2");
l2.DiffuseColour = (trail.GetInitialColour(0));
animNode.AttachObject(l2);
// Add billboard
BillboardSet bbs = sceneMgr.CreateBillboardSet("bb", 1);
bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(0));
bbs.MaterialName = "Examples/Flare";
animNode.AttachObject(bbs);
animNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
animNode.Position = new Vector3(-50,100,0);
anim = sceneMgr.CreateAnimation("an2", 10);
anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
track = anim.CreateNodeTrack(1, animNode);
kf = track.CreateNodeKeyFrame(0);
kf.Translate = new Vector3(-50,100,0);
kf = track.CreateNodeKeyFrame(2);
kf.Translate = new Vector3(-100, 150, -30);
kf = track.CreateNodeKeyFrame(4);
kf.Translate = new Vector3(-200, 0, 40);
kf = track.CreateNodeKeyFrame(6);
kf.Translate = new Vector3(0, -150, 70);
kf = track.CreateNodeKeyFrame(8);
kf.Translate = new Vector3(50, 0, 30);
kf = track.CreateNodeKeyFrame(10);
kf.Translate = new Vector3(-50,100,0);
animState = sceneMgr.CreateAnimationState("an2");
animState.Enabled = true;
mAnimStateList.Add(animState);
trail.SetInitialColour(1, 0.0f, 1.0f, 0.4f);
trail.SetColourChange(1, 0.5f, 0.5f, 0.5f, 0.5f);
trail.SetInitialWidth(1, 5);
trail.AddNode(animNode);
// Add light
l2 = sceneMgr.CreateLight("l3");
l2.DiffuseColour = trail.GetInitialColour(1);
animNode.AttachObject(l2);
// Add billboard
bbs = sceneMgr.CreateBillboardSet("bb2", 1);
bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(1));
bbs.MaterialName = "Examples/Flare";
animNode.AttachObject(bbs);
}
示例6: CreateScene
// Just override the mandatory create scene method
public override void CreateScene()
{
// Set ambient light
sceneMgr.AmbientLight = new ColourValue(0.2f, 0.2f, 0.2f);
// Skybox
sceneMgr.SetSkyBox(true, "Examples/MorningSkyBox");
// Create a light
Light l = sceneMgr.CreateLight("MainLight");
l.Type = Light.LightTypes.LT_DIRECTIONAL;
Vector3 dir = new Vector3(0.5f, -1, 0);
dir.Normalise();
l.Direction = dir;
l.DiffuseColour = new ColourValue(1.0f, 1.0f, 0.8f);
l.SpecularColour= new ColourValue(1.0f, 1.0f, 1.0f);
// Create a prefab plane
mPlane = new MovablePlane(Vector3.UNIT_Y, 0);
MeshManager.Singleton.CreatePlane("ReflectionPlane",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
mPlane._getDerivedPlane(), 2000, 2000,
1, 1, true, 1, 1, 1, Vector3.UNIT_Z);
mPlaneEnt = sceneMgr.CreateEntity( "Plane", "ReflectionPlane" );
// Create an entity from a model (will be loaded automatically)
Entity knotEnt = sceneMgr.CreateEntity("Knot", "knot.mesh");
// Create an entity from a model (will be loaded automatically)
Entity ogreHead = sceneMgr.CreateEntity("Head", "ogrehead.mesh");
knotEnt.SetMaterialName("Examples/TextureEffect2");
// Attach the rtt entity to the root of the scene
SceneNode rootNode = sceneMgr.RootSceneNode;
mPlaneNode = rootNode.CreateChildSceneNode();
// Attach both the plane entity, and the plane definition
mPlaneNode.AttachObject(mPlaneEnt);
mPlaneNode.AttachObject(mPlane);
mPlaneNode.Translate(0, -10, 0);
// Tilt it a little to make it interesting
mPlaneNode.Roll(new Degree(5));
rootNode.CreateChildSceneNode( "Head" ).AttachObject( ogreHead );
TexturePtr texture = TextureManager.Singleton.CreateManual( "RttTex",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D,
512, 512, 0,
PixelFormat.PF_R8G8B8,
(int) TextureUsage.TU_RENDERTARGET );
RenderTarget rttTex = texture.GetBuffer().GetRenderTarget();
mReflectCam = sceneMgr.CreateCamera("ReflectCam");
mReflectCam.NearClipDistance = camera.NearClipDistance;
mReflectCam.FarClipDistance = camera.FarClipDistance;
mReflectCam.AspectRatio =
(float)window.GetViewport(0).ActualWidth /
(float)window.GetViewport(0).ActualHeight;
mReflectCam.FOVy = camera.FOVy;
Viewport v = rttTex.AddViewport( mReflectCam );
v.SetClearEveryFrame(true);
v.BackgroundColour = ColourValue.Black;
MaterialPtr mat = MaterialManager.Singleton.Create("RttMat",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RustedMetal.jpg");
t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RttTex");
// Blend with base texture
t.SetColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL,
LayerBlendSource.LBS_TEXTURE,
LayerBlendSource.LBS_CURRENT,
ColourValue.White,
ColourValue.White, 0.25f);
t.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP);
t.SetProjectiveTexturing(true, mReflectCam);
rttTex.PostRenderTargetUpdate += postRenderTargetUpdate;
rttTex.PreRenderTargetUpdate += preRenderTargetUpdate;
// set up linked reflection
mReflectCam.EnableReflection(mPlane);
// Also clip
mReflectCam.EnableCustomNearClipPlane(mPlane);
// Give the plane a texture
mPlaneEnt.SetMaterialName("RttMat");
// Add a whole bunch of extra transparent entities
Entity cloneEnt;
for (int n = 0; n < 10; ++n)
{
// Create a new node under the root
SceneNode node = sceneMgr.CreateSceneNode();
// Random translate
Vector3 nodePos;
nodePos.x = Mogre.Math.SymmetricRandom() * 750.0f;
nodePos.y = Mogre.Math.SymmetricRandom() * 100.0f + 25;
//.........这里部分代码省略.........
示例7: Vector3IsNormaliseTest
public void Vector3IsNormaliseTest()
{
var a = new Vector3(3.0f, 4.0f, 1.0f);
var expectedResult = true;
a.Normalise();
var r = a.IsNormalised;
Assert.Equal<bool>(expectedResult, r);
}
示例8: Vector3NormaliseTest
public void Vector3NormaliseTest()
{
var a = new Vector3(3.0f, 4.0f, 1.0f);
var expectedResult = new Vector3(0.5883484f, 0.784464538f, 0.196116135f);
a.Normalise();
Assert.True(a.Equals(expectedResult, 1e-3f));
}
示例9: CreateScene
protected static void CreateScene()
{
sceneMgr = _root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);
//Image combined = new Image();
//combined.LoadTwoImagesAsRGBA("terra_DIFFUSE.png", "terra_SPECULAR.png", "General", PixelFormat.PF_BYTE_RGBA);
//combined.Save("terra_diffusespecular.png");
//combined.LoadTwoImagesAsRGBA("terra_NORMAL.png", "terra_DISP.png", "General", PixelFormat.PF_BYTE_RGBA);
//combined.Save("terra_normalheight.png");
_cam = sceneMgr.CreateCamera("Camera");
_cam.Pitch(-0.78f);
_cam.NearClipDistance = 5f;
_cam.FarClipDistance = 99999 * 6;
_cam.Move(new Vector3(1084, 346, 1317));
viewport = _window.AddViewport(_cam);
_cam.AspectRatio = (float)viewport.ActualWidth / (float)viewport.ActualHeight;
sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;
sceneMgr.ShadowTextureCount = 8;
sceneMgr.SetShadowTextureSize(8192);
CreateNewDude("1");
CreateNewDude("2");
Vector3 lightDir = new Vector3(0.55f, -0.3f, 0.75f);
lightDir.Normalise();
Light light = sceneMgr.CreateLight("tstLight");
light.Type = Light.LightTypes.LT_DIRECTIONAL;
light.Direction = lightDir;
light.DiffuseColour = ColourValue.White;
light.SpecularColour = ColourValue.White;
light.CastShadows = false;
light.Visible = true;
sceneMgr.AmbientLight = ColourValue.White;
tgo = new TerrainGlobalOptions();
tg = new TerrainGroup(sceneMgr, Terrain.Alignment.ALIGN_X_Z, 513, 12000.0f);
tg.SetFilenameConvention("Asd", "dat");
tg.Origin = new Vector3(0, -250, 0);
ConfigureTerrainDefaults(light);
for (int x = 0; x <= 0; ++x)
{
for (int y = 0; y <= 0; ++y)
{
DefineTerrain(x, y);
}
}
tg.LoadAllTerrains(true);
if (mTerrainImported)
{
foreach (TerrainGroup.TerrainSlot t in tg.GetTerrainIterator())
{
InitBlendMaps(t.instance);
}
}
tg.FreeTemporaryResources();
// tg.SaveAllTerrains(true);
hydrax = new MHydrax.MHydrax(sceneMgr, _cam, viewport);
hydrax.Components = MHydraxComponent.HYDRAX_COMPONENTS_ALL;
Plane p = new Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
MHydrax.MProjectedGrid m = new MProjectedGrid(hydrax,
new MPerlin(new MPerlin.MOptions(8, 0.085f, 0.49f, 1.4f, 1.27f, 2, new Vector3(0.5f, 50, 150000))),
p,
MMaterialManager.MNormalMode.NM_VERTEX,
new MHydrax.MProjectedGrid.MOptions(56, 35, 50, false, false, false, 3.75f));
hydrax.SetModule(m);
hydrax.CfgFileManager.Load("TestiPeli.hdx");
hydrax.Create();
// sceneMgr.SetSkyDome(true, "Examples/CloudySky", 5, 8);
mRect = new SelectionRectangle("Selection SelectionRectangle");
sceneMgr.RootSceneNode.CreateChildSceneNode("debug_object").AttachObject(mRect);
mRect._camera = _cam;
ct = new CollisionTools(sceneMgr);
SetupCaelum(viewport, _window);
}