public static Quatf RotAxisAngleToQuatf(Vec3f axis, float theta) { float c = FMath.Cos(theta * 0.5f); axis *= FMath.Sin(theta * 0.5f); return((new Quatf(c, axis)).Normalize()); }
private void SetSpritePrimitive( out SpritePrim spritePrim, SpriteB spriteB ) { spritePrim.V0.Color = _color; spritePrim.V1.Color = _color; spritePrim.V2.Color = _color; spritePrim.V3.Color = _color; spritePrim.V0.UV = spriteB._uv[0]; spritePrim.V1.UV = spriteB._uv[1]; spritePrim.V2.UV = spriteB._uv[2]; spritePrim.V3.UV = spriteB._uv[3]; if (spriteB.Rotation == 0.0f) { spritePrim.V0.Position.X = (short)(spriteB.Position.X - spriteB.Width * spriteB.Center.X); //0.0f; // x0 spritePrim.V0.Position.Y = (short)(spriteB.Position.Y - spriteB.Height * spriteB.Center.Y); //0.0f; // y0 spritePrim.V1.Position.X = (short)(spriteB.Position.X - spriteB.Width * spriteB.Center.X); //0.0f; // x1 spritePrim.V1.Position.Y = (short)(spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y)); //1.0f; // y1 spritePrim.V2.Position.X = (short)(spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X)); //1.0f; // x2 spritePrim.V2.Position.Y = (short)(spriteB.Position.Y - spriteB.Height * spriteB.Center.Y); //0.0f; // y2 spritePrim.V3.Position.X = (short)(spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X)); //1.0f; // x3 spritePrim.V3.Position.Y = (short)(spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y)); //1.0f; // y3 } else { float x, y, rc, rs; rc = FMath.Cos(spriteB.Rotation); rs = FMath.Sin(spriteB.Rotation); x = -spriteB.Width * spriteB.Center.X; y = -spriteB.Height * spriteB.Center.Y; spritePrim.V0.Position.X = (short)(spriteB.Position.X + (float)(x * rc - y * rs)); // x0 spritePrim.V0.Position.Y = (short)(spriteB.Position.Y + (float)(x * rs + y * rc)); // y0 x = -spriteB.Width * spriteB.Center.X; y = spriteB.Height * (1.0f - spriteB.Center.Y); spritePrim.V1.Position.X = (short)(spriteB.Position.X + (float)(x * rc - y * rs)); // x1 spritePrim.V1.Position.Y = (short)(spriteB.Position.Y + (float)(x * rs + y * rc)); // y1 x = spriteB.Width * (1.0f - spriteB.Center.X); y = -spriteB.Height * spriteB.Center.Y; spritePrim.V2.Position.X = (short)(spriteB.Position.X + (float)(x * rc - y * rs)); // x2 spritePrim.V2.Position.Y = (short)(spriteB.Position.Y + (float)(x * rs + y * rc)); // y2 x = spriteB.Width * (1.0f - spriteB.Center.X); y = spriteB.Height * (1.0f - spriteB.Center.Y); spritePrim.V3.Position.X = (short)(spriteB.Position.X + (float)(x * rc - y * rs)); // x3 spritePrim.V3.Position.Y = (short)(spriteB.Position.Y + (float)(x * rs + y * rc)); // y3 } }
public override void Tick(float dt) { base.Tick(dt); GamePadData data = GamePad.GetData(0); float analogX = 0.0f; float analogY = 0.0f; //d-pad movement,emulating analog movement of the sticks if (Input2.GamePad0.Right.Down) { analogX = 1.0f; } else if (Input2.GamePad0.Left.Down) { analogX = -1.0f; } if (Input2.GamePad0.Up.Down) { analogY = -1.0f; } else if (Input2.GamePad0.Down.Down) { analogY = 1.0f; } //if the left stick is moving,then use values read from the stick if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f) { analogX = data.AnalogLeftX; analogY = data.AnalogLeftY; } //calculate the position Position = new Vector2(Position.X + analogX / 10f, Position.Y - analogY / 10f); //rotate according to the right analog stick, or if it's not moving, then according the the left stick // so basically if you are not pointing the player in any direction with the right stick he is going to point in the walking direction //or if both sticks are not moving,then use the analogX and analogY values(d-pad movement) if (data.AnalogRightX > 0.2f || data.AnalogRightX < -0.2f || data.AnalogRightY > 0.2f || data.AnalogRightY < -0.2f) { var angleInRadians = FMath.Atan2(-data.AnalogRightX, -data.AnalogRightY); Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f) { var angleInRadians = FMath.Atan2(-data.AnalogLeftX, -data.AnalogLeftY); Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else if (analogX != 0.0f || analogY != 0.0f) { var angleInRadians = FMath.Atan2(-analogX, -analogY); Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } }
static public bool createPipeVertex( MeshData mesh, float radius, float height, int div ) { int a_pos_cnt = 0; float a_st_now = 0; float a_stack_step = (float)(Math.PI / div); for (int j = 0; j < div * 2; j++) { float px = FMath.Cos(a_st_now) * radius; float py = FMath.Sin(a_st_now) * radius; mesh.Positions[a_pos_cnt + 0] = px; mesh.Positions[a_pos_cnt + 1] = py; mesh.Positions[a_pos_cnt + 2] = height; mesh.Positions[a_pos_cnt + 3] = px; mesh.Positions[a_pos_cnt + 4] = py; mesh.Positions[a_pos_cnt + 5] = 0; a_pos_cnt += 6; a_st_now += a_stack_step; } return(true); }
public static bool Init(GraphicsContext graphicsContext) { graphics = graphicsContext; textureShaderProgram = createSimpleTextureShader(); colorShaderProgram = createSimpleColorShader(); projectionMatrix = Matrix4.Ortho(0, Width, 0, Height, 0.0f, 32768.0f); viewMatrix = Matrix4.LookAt(new Vector3(0, Height, 0), new Vector3(0, Height, 1), new Vector3(0, -1, 0)); rectVertices = new VertexBuffer(4, VertexFormat.Float3); rectVertices.SetVertices(0, new float[] { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0 }); circleVertices = new VertexBuffer(36, VertexFormat.Float3); float[] circleVertex = new float[3 * 36]; for (int i = 0; i < 36; i++) { float radian = ((i * 10) / 180.0f * FMath.PI); circleVertex[3 * i + 0] = FMath.Cos(radian); circleVertex[3 * i + 1] = FMath.Sin(radian); circleVertex[3 * i + 2] = 0.0f; } circleVertices.SetVertices(0, circleVertex); defaultFont = new Font(FontAlias.System, 24, FontStyle.Regular); SetDefaultFont(); spriteDict = new Dictionary <string, SampleSprite>(); spriteNamelessCount = 0; #if true __testShaderProgram1 = new ShaderProgram("/Application/Sample/Lib/SampleLib/shaders/Test.cgx"); __testVertices1 = new VertexBuffer(3, VertexFormat.Float3); __testShaderProgram1.SetAttributeBinding(0, "vPosition"); __testVertices1.SetVertices(0, new float[] { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }); __testShaderProgram2 = new ShaderProgram("/Application/Sample/Lib/SampleLib/shaders/Test.cgx"); __testVertices2 = new VertexBuffer(3, VertexFormat.Float3); __testShaderProgram2.SetAttributeBinding(0, "vPosition"); __testVertices2.SetVertices(0, new float[] { 0.0f, 0.5f - 0.5f, 0.0f, -0.5f, -0.5f - 0.5f, 0.0f, 0.5f, -0.5f - 0.5f, 0.0f }); #endif return(true); }
//Get the player Y position for walking on the Seasaw public float GetNewPlayerYPos(Vector2 position) { float distanceBetween = FMath.Sqrt(FMath.Pow((position.X - _sprite.Position.X), 2) + FMath.Pow((position.Y - _sprite.Position.Y), 2)); if (distanceBetween < 0) { distanceBetween = -distanceBetween; } if (distanceBetween < (_textureInfo.TextureSizef.X / 2) + 40 && _onObstacle) { float adjacent, opposite, hypotenuse; adjacent = _sprite.Position.X - position.X; hypotenuse = adjacent / (FMath.Sin(_angle2)); opposite = (FMath.Cos(_angle2)) * hypotenuse; _tempScale = ((_angle * 10) * _scalerValue); if (_tempScale < 0) { _tempScale = -_tempScale; } float tempScale = (_scaleLimiter * _tempScale); return(((_sprite.Position.Y + ((_textureInfo.TextureSizef.Y * _scale) * tempScale)) - opposite) + (115 / 2)); } else { _onObstacle = false; } return(position.Y); }
public static Vec3f Quat_RotPt(Vec3f pt, Vec3f rotaxis, float theta) { Quatf qrot = new Quatf(FMath.Cos(theta * 0.5f), rotaxis * FMath.Sin(theta * 0.5f)); Quatf qpt = new Quatf(0.0f, pt); Quatf qconj = qrot.Conjugate(); return(Quat_PointMult(qrot * qpt, qconj)); }
public static float ShockWave(float d, float time, float wave_half_width, float wave_speed, float wave_fade, float d_scale) { d *= d_scale; float num = time * wave_speed; float num2 = FMath.Clamp(d - num, -wave_half_width, wave_half_width) / wave_half_width; float num3 = (1f + FMath.Cos(Math.Pi * num2)) * 0.5f; return(num3 * FMath.Exp(-d * wave_fade)); }
private void UpdateFighterAndCamera(float x) { _fighter.Offset = new Vec3(0f, Math.Max(_terrainScene.Height(_fighter.Offset) + 20f, _fighter.Offset.Y), x - 5000f); var angle = x * 0.03f; _fighter.Orientation = new Vec3(0f, 0f, FMath.Cos(angle)); _camera.Position = _fighter.Offset + LookVec(); _camera.Target = _fighter.Offset; }
static private bool createTorusVertex(MeshData mesh, float M, float N, int divM, int divN) { float s = 0.0f; float sStep = (float)(FMath.PI * 2 / divM); float tStep = (float)(FMath.PI * 2 / divN); for (int m = 0; m < (divM + 1); m++) { float t = 0.0f; for (int n = 0; n < (divN + 1); n++) { float x = (M + N * (float)FMath.Cos(FMath.PI * 2 - t)) * (float)FMath.Cos(s); float y = (M + N * (float)FMath.Cos(FMath.PI * 2 - t)) * (float)FMath.Sin(s); float z = N * (float)FMath.Sin(FMath.PI * 2 - t); float nx = (float)(FMath.Cos(s) * FMath.Cos(FMath.PI * 2 - t)); float ny = (float)(FMath.Sin(s) * FMath.Cos(FMath.PI * 2 - t)); float nz = (float)(FMath.Sin(FMath.PI * 2 - t)); float len = (float)FMath.Sqrt(x * x + y * y); float tx = -y / len; float ty = x / len; float tz = 0.0f; int idx = (m * (divN + 1)) + n; mesh.Positions[(idx * 3) + 0] = x; mesh.Positions[(idx * 3) + 1] = y; mesh.Positions[(idx * 3) + 2] = z; mesh.Normals[(idx * 3) + 0] = nx; mesh.Normals[(idx * 3) + 1] = ny; mesh.Normals[(idx * 3) + 2] = nz; mesh.Tangents[(idx * 3) + 0] = tx; mesh.Tangents[(idx * 3) + 1] = ty; mesh.Tangents[(idx * 3) + 2] = tz; mesh.TexCoords[(idx * 2) + 0] = m / (float)divM; mesh.TexCoords[(idx * 2) + 1] = n / (float)divN; t += tStep; } s += sStep; } return(true); }
internal static AnimationInterpolator GetDampedWaveInterpolator(int strength) { strength = (int)FMath.Clamp((float)strength, 0f, 100f); return(AnimationUtility.GetAnimationInterpolator(delegate(float ratio) { if (strength == 0) { return ratio; } return -FMath.Cos(ratio * 3.14159274f * (float)strength * 2f) * FMath.Exp(-ratio * (float)strength) / 2f; })); }
private void get_rotation(ref float x, ref float y, float cx, float cy, float deg) { float dx = x - cx; // 中心からの距離(X) float dy = y - cy; // 中心からの距離(Y) float rad = FMath.Radians(deg); float tmpX = (dx * FMath.Cos(rad)) - (dy * FMath.Sin(rad)); // 回転 float tmpY = (dx * FMath.Sin(rad)) + (dy * FMath.Cos(rad)); x = (cx + tmpX); // 元の座標にオフセットする y = (cy + tmpY); }
public void TestCos() { var deg2Rad = Fixed.FromFloat((float)(Math.PI / 180)); var a = Fixed.FromInt(90) * deg2Rad; var r = Fixed.FromInt(0); AssertApproximately(r, FMath.Cos(a)); a = Fixed.FromInt(0) * deg2Rad; r = Fixed.FromInt(1); AssertApproximately(r, FMath.Cos(a)); a = Fixed.FromInt(37) * deg2Rad; r = Fixed.Parse("0.79863551"); AssertApproximately(r, FMath.Cos(a)); }
public static Quatf EulerToQuatf(float alpha, float beta, float gamma) { float c1 = FMath.Cos(alpha / 2.0f); float s1 = FMath.Sin(alpha / 2.0f); float c2 = FMath.Cos(beta / 2.0f); float s2 = FMath.Sin(beta / 2.0f); float c3 = FMath.Cos(gamma / 2.0f); float s3 = FMath.Sin(gamma / 2.0f); return(new Quatf() { w = c1 * c2 * c3 - s1 * s2 * s3, x = c1 * c2 * s3 + s1 * s2 * c3, y = s1 * c2 * c3 + c1 * s2 * s3, z = c1 * s2 * c3 - s1 * c2 * s3 }); }
/// LookAtの指定からビュー行列の生成 /** * trgRotの回転値は1周を360.0fとする */ public void SetLookAt(Vector3 trgRot, Vector3 trgPos, float trgDis) { float a_Cal1, a_Cal2, a_Cal3; float a_Cal = (float)(pi / 180.0); float angleX = trgRot.X * a_Cal; float angleY = trgRot.Y * a_Cal; float angleZ = trgRot.Z * a_Cal; float a_sinx = FMath.Sin(angleX); float a_cosx = FMath.Cos(angleX); float a_siny = FMath.Sin(angleY); float a_cosy = FMath.Cos(angleY); float a_sinz = FMath.Sin(angleZ); float a_cosz = FMath.Cos(angleZ); /* * float a_sinx = FMath.Sin( trgRot.X ); * float a_cosx = FMath.Cos( trgRot.X ); * float a_siny = FMath.Sin( trgRot.Y ); * float a_cosy = FMath.Cos( trgRot.Y ); * float a_sinz = FMath.Sin( trgRot.Z ); * float a_cosz = FMath.Cos( trgRot.Z ); */ a_Cal1 = trgDis * a_cosx; a_Cal2 = trgDis * a_sinx; a_Cal3 = trgDis * a_cosx; camPos.X = trgPos.X + (a_Cal1 * a_siny); camPos.Y = trgPos.Y + a_Cal2; camPos.Z = trgPos.Z + (a_Cal3 * a_cosy); camUp.X = (a_sinz * a_cosy); camUp.Y = a_cosz; camUp.Z = -(a_sinz * a_siny); this.View = Matrix4.LookAt(camPos, trgPos, camUp); ViewProjection = Projection * View; camLookVec = trgPos - camPos; camLookVec = camLookVec.Normalize(); }
/// 行列にXYZ回転をかける static public void SetMtxRotateEulerXYZ(ref Matrix4 mtx, Vector3 rot) { float sinx = FMath.Sin(rot.X); float cosx = FMath.Cos(rot.X); float siny = FMath.Sin(rot.Y); float cosy = FMath.Cos(rot.Y); float sinz = FMath.Sin(rot.Z); float cosz = FMath.Cos(rot.Z); mtx = Matrix4.Identity; mtx.M11 = (cosz * cosy); mtx.M21 = (-sinz * cosx) + (cosz * siny * sinx); mtx.M31 = (sinz * sinx) + (cosz * siny * cosx); mtx.M12 = (sinz * cosy); mtx.M22 = (cosz * cosx) + (sinz * siny * sinx); mtx.M32 = (-cosz * sinx) + (sinz * siny * cosx); mtx.M13 = -siny; mtx.M23 = (cosy * sinx); mtx.M33 = (cosy * cosx); }
public static bool Init(GraphicsContext graphicsContext, Stopwatch swInit = null) { graphics = graphicsContext; textureShaderProgram = createSimpleTextureShader(); colorShaderProgram = createSimpleColorShader(); projectionMatrix = Matrix4.Ortho(0, Width, 0, Height, 0.0f, 32768.0f); viewMatrix = Matrix4.LookAt(new Vector3(0, Height, 0), new Vector3(0, Height, 1), new Vector3(0, -1, 0)); rectVertices = new VertexBuffer(4, VertexFormat.Float3); rectVertices.SetVertices(0, new float[] { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0 }); circleVertices = new VertexBuffer(36, VertexFormat.Float3); float[] circleVertex = new float[3 * 36]; for (int i = 0; i < 36; i++) { float radian = ((i * 10) / 180.0f * FMath.PI); circleVertex[3 * i + 0] = FMath.Cos(radian); circleVertex[3 * i + 1] = FMath.Sin(radian); circleVertex[3 * i + 2] = 0.0f; } circleVertices.SetVertices(0, circleVertex); defaultFont = new Font(FontAlias.System, 24, FontStyle.Regular); SetDefaultFont(); spriteDict = new Dictionary <string, SampleSprite>(); spriteNamelessCount = 0; return(true); }
public Seasaw(Scene scene, float xPos, float floorHeight) { //Initialise Variables rand = new Random(); _scale = 1.00f; _rotationSpeed = 0.01f; _scaleLimiter = 0.3f; _tempScale = 1.0f; _rotateLeft = false; _onObstacle = false; _floorHeight = floorHeight; _defaultYPos = floorHeight + 45.0f; //SpriteSheet Info _textureInfo = new TextureInfo("/Application/textures/Seasaw.png"); //Create Sprite _sprite = new SpriteUV(); _sprite = new SpriteUV(_textureInfo); _sprite.Quad.S = _textureInfo.TextureSizef; _sprite.Scale = new Vector2(_scale, _scale); _sprite.CenterSprite(); _sprite.Position = new Vector2(xPos + 180, _defaultYPos); _hypotenuse = (_textureInfo.TextureSizef.X * _scale); _angle = -0.32f; _angle2 = (FMath.PI / 2) - _angle; _opposite = FMath.Cos(_angle2) * _hypotenuse; _adjacent = FMath.Tan(_angle) * _opposite; _sprite.Angle = _angle; _scalerValue = _tempScale / (_angle * 10); _trap = new Trap(scene, new Vector2(xPos, 60.0f)); _pit = new Pit(scene, new Vector2(xPos, 60)); //Add to the current scene. scene.AddChild(_sprite); }
public void Update() { parent.Velocity.X = fint.zero; parent.Velocity.Y = fint.zero; radiusNear = false; radiusTouch = false; //------------------------------------------------------------------------------------ unitsNearBy.Clear(); parent.proximityToken.FindNeighbors(new Point3D(parent.Position.X.ToInt(), 0, parent.Position.Y.ToInt()), NeighborCheckRadius, unitsNearBy); DisperseUpdate(); var dist = (parent.Position - dest).sqrMagnitude; int reachDist = 1; if (parent.Orders.Count != 0 && parent.Orders.Peek().type == OrderType.MOVE) { reachDist = 10; } if (active) { fint xxx = fint.zero, yyy = fint.zero; //------------------------------------------------------------------------------------ FVector2 cur2D = BackgroundGame.MapSpace.WorldToSpace(parent.Position); int id = cur2D.X.ToInt() + cur2D.Y.ToInt() * BackgroundGame.MapSpace.Width; byte direction = flowfield == null ? (byte)255 : ((id >= 0 && id < flowfield.Length) ? flowfield.Get(id) : (byte)0); //if (direction == 255 || dist<(fint)((reachDist+1) * (reachDist+1))) { parent.Rotation = FVector2.Angle(dest, parent.Position); /*} else { * if (direction != 0 && direction != 1) { * if (direction >= 100) direction -= 100; * * int x = -MapSpace.Direction[direction - 2, 0]; * int y = -MapSpace.Direction[direction - 2, 1]; * parent.Rotation = FMath.Atan2((fint)y, (fint)x); * } * }*/ xxx = FMath.Cos(parent.Rotation) * (fint)Speed; yyy = FMath.Sin(parent.Rotation) * (fint)Speed; //------------------------------------------------------------------------------------ if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X + xxx, parent.Position.Y + parent.Velocity.Y)) { xxx = fint.zero; } if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X, parent.Position.Y + parent.Velocity.Y + yyy)) { yyy = fint.zero; } if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X + xxx, parent.Position.Y + parent.Velocity.Y + yyy)) { xxx = fint.zero; yyy = fint.zero; } parent.Velocity.X += xxx; parent.Velocity.Y += yyy; } parent.Velocity.X = GameUtils.Clamp(parent.Velocity.X, -Speed, Speed); parent.Velocity.Y = GameUtils.Clamp(parent.Velocity.Y, -Speed, Speed); parent.Position += parent.Velocity; //if (!active) if (active) { dist = (parent.Position - dest).sqrMagnitude; if (dist <= (fint)(reachDist * reachDist)) { //parent.Position = dest; active = false; reached = true; parent.Moving = false; } } }
public void Render() { // =============== BEGINNING OF NEW STUFF ======================= float x, y; float cosRot = FMath.Cos(Rotation); float sinRot = FMath.Sin(Rotation); // Point 1 - top left x = -Width * Center.X; y = -Height * Center.Y; vertices[0] = Position.X + (float)(x * cosRot - y * sinRot); // x0 vertices[1] = Position.Y + (float)(x * sinRot + y * cosRot); // y0 vertices[2] = Position.Z; // z0 // Point 2 - bottom left x = -Width * Center.X; y = Height * (1.0f - Center.Y); vertices[3] = Position.X + (float)(x * cosRot - y * sinRot); // x1 vertices[4] = Position.Y + (float)(x * sinRot + y * cosRot); // y1 vertices[5] = Position.Z; // z1 // Point 3 - top right x = Width * (1.0f - Center.X); y = -Height * Center.Y; vertices[6] = Position.X + (float)(x * cosRot - y * sinRot); // x2 vertices[7] = Position.Y + (float)(x * sinRot + y * cosRot); // y2 vertices[8] = Position.Z; // z2 // Point 4 - bottom right x = Width * (1.0f - Center.X); y = Height * (1.0f - Center.Y); vertices[9] = Position.X + (float)(x * cosRot - y * sinRot); // x3 vertices[10] = Position.Y + (float)(x * sinRot + y * cosRot); // y3 vertices[11] = Position.Z; // z3 graphics.Enable(EnableMode.Blend); // "Original" graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha); // Something Cool //graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.DstAlpha); // Additive blending // graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.One); // =============== END OF NEW STUFF ================================ graphics.SetShaderProgram(shaderProgram); vertexBuffer.SetVertices(0, vertices); vertexBuffer.SetVertices(1, texcoords); vertexBuffer.SetVertices(2, colors); vertexBuffer.SetIndices(indices); graphics.SetVertexBuffer(0, vertexBuffer); graphics.SetTexture(0, texture); Matrix4 screenMatrix = new Matrix4( 2.0f / graphics.Screen.Rectangle.Width, 0.0f, 0.0f, 0.0f, 0.0f, -2.0f / graphics.Screen.Rectangle.Height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f ); shaderProgram.SetUniformValue(0, ref screenMatrix); graphics.DrawArrays(DrawMode.TriangleStrip, 0, indexSize); graphics.Disable(EnableMode.Blend); }
public void SetLookSelf(Vector3 trgRot, Vector3 trgPos, float trgDis, float trgDisX, float lookselfRate) { float a_Cal1, a_Cal2, a_Cal3; float a_Cal = (float)(pi / 180.0); float angleX = trgRot.X * a_Cal; float angleY = trgRot.Y * a_Cal; float angleZ = trgRot.Z * a_Cal; float a_sinx = FMath.Sin(angleX); float a_cosx = FMath.Cos(angleX); float a_siny = FMath.Sin(angleY); float a_cosy = FMath.Cos(angleY); float a_sinz = FMath.Sin(angleZ); float a_cosz = FMath.Cos(angleZ); /* * float a_sinx = FMath.Sin( trgRot.X ); * float a_cosx = FMath.Cos( trgRot.X ); * float a_siny = FMath.Sin( trgRot.Y ); * float a_cosy = FMath.Cos( trgRot.Y ); * float a_sinz = FMath.Sin( trgRot.Z ); * float a_cosz = FMath.Cos( trgRot.Z ); */ // a_Cal1 = trgDis * a_cosx; // a_Cal2 = trgDis * a_sinx; // a_Cal3 = trgDis * a_cosx; if (lookselfRate == 1.0f) { a_Cal1 = -trgDis; a_Cal2 = -trgDis * a_sinx; a_Cal3 = -trgDis; camPos.X = trgPos.X + (a_Cal1 * a_siny); camPos.Y = trgPos.Y; camPos.Z = trgPos.Z + (a_Cal3 * a_cosy); lookPosition.X = camPos.X + (camPos.X - trgPos.X) * a_cosx; lookPosition.Y = camPos.Y + trgDisX * a_sinx; lookPosition.Z = camPos.Z + (camPos.Z - trgPos.Z) * a_cosx; lookedPos.X = trgPos.X + (camPos.X - trgPos.X) * 3.5f; lookedPos.Y = camPos.Y + trgDisX * a_sinx; lookedPos.Z = trgPos.Z + (camPos.Z - trgPos.Z) * 3.5f; } else if (lookselfRate == 0.0f) { a_Cal1 = -trgDis * a_cosx; a_Cal2 = -trgDis * a_sinx; a_Cal3 = -trgDis * a_cosx; camPos.X = trgPos.X + (a_Cal1 * a_siny); camPos.Y = trgPos.Y + a_Cal2; camPos.Z = trgPos.Z + (a_Cal3 * a_cosy); lookPosition.X = trgPos.X; lookPosition.Y = trgPos.Y; lookPosition.Z = trgPos.Z; } else { a_Cal1 = -trgDis * ((a_cosx - 1) * (1 - lookselfRate / 2) + 1); a_Cal2 = -trgDis * a_sinx; a_Cal3 = -trgDis * ((a_cosx - 1) * (1 - lookselfRate / 2) + 1);; camPos.X = trgPos.X + (a_Cal1 * a_siny); camPos.Y = trgPos.Y + (a_Cal2 * (1 - lookselfRate / 2)); // camPos.Y = trgPos.Y + a_Cal2; camPos.Z = trgPos.Z + (a_Cal3 * a_cosy); lookPosition.X = trgPos.X; lookPosition.Z = trgPos.Z; lookPosition.Y = trgPos.Y; /* * lookPosition.X = trgPos.X * (1-lookselfRate) + lookedPos.X * lookselfRate; * lookPosition.Z = trgPos.Z * (1-lookselfRate) + lookedPos.Z * lookselfRate; * lookPosition.Y = trgPos.Y * (1-lookselfRate) + lookedPos.Y * lookselfRate; */ } camUp.X = (a_sinz * a_cosy); camUp.Y = a_cosz; camUp.Z = -(a_sinz * a_siny); this.View = Matrix4.LookAt(camPos, lookPosition, camUp); ViewProjection = Projection * View; camLookVec = camPos - lookPosition; camLookVec = camLookVec.Normalize(); }
static private bool createSphereVertex( MeshData mesh, float radius, int div ) { if (div <= 0 || radius <= 0) { return(false); } int i_stacks = div; int i_slices = div; float i_radius = radius; float a_st_now = 0; float a_stack_step = (float)(FMath.PI / (i_stacks - 1)); int idx = 0; for (int i = 0; i < i_stacks; i++) { float a_s = (float)FMath.Sin(a_st_now); float ny = (float)FMath.Cos(a_st_now); float py = i_radius * ny; float a_sl_now = 0; float a_slice_step = (float)((FMath.PI * 2) / (i_slices - 1)); for (int j = 0; j < i_slices; j++) { float nx = (float)FMath.Cos(FMath.PI * 2 - a_sl_now) * a_s; float nz = (float)FMath.Sin(FMath.PI * 2 - a_sl_now) * a_s; float px = i_radius * nx; float pz = i_radius * nz; mesh.Positions[(idx * 3) + 0] = px; mesh.Positions[(idx * 3) + 1] = py; mesh.Positions[(idx * 3) + 2] = pz; // Normals mesh.Normals[(idx * 3) + 0] = nx; mesh.Normals[(idx * 3) + 1] = ny; mesh.Normals[(idx * 3) + 2] = nz; // Tangents float len = (float)FMath.Sqrt(nx * nx + nz * nz); mesh.Tangents[(idx * 3) + 0] = nz / len; mesh.Tangents[(idx * 3) + 1] = 0; mesh.Tangents[(idx * 3) + 2] = -nx / len; // Singularities if (nz == 0.0f && nx == 0.0f) { mesh.Tangents[(idx * 3) + 0] = (float)FMath.Cos(a_sl_now); mesh.Tangents[(idx * 3) + 1] = 0; mesh.Tangents[(idx * 3) + 2] = (float)FMath.Sin(a_sl_now); } float u = 1.0f / (i_slices - 1) * j; float v = 1.0f / (i_stacks - 1) * i; mesh.TexCoords[(idx * 2) + 0] = u; mesh.TexCoords[(idx * 2) + 1] = v; a_sl_now += a_slice_step; idx++; } a_st_now += a_stack_step; } return(true); }
public override void Tick(float dt) { base.Tick(dt); GamePadData data = GamePad.GetData(0); float analogX = 0.0f; float analogY = 0.0f; //d-pad movement,emulating analog movement of the sticks if (Input2.GamePad0.Right.Down) { analogX = 1.0f; } else if (Input2.GamePad0.Left.Down) { analogX = -1.0f; } if (Input2.GamePad0.Up.Down) { analogY = -1.0f; } else if (Input2.GamePad0.Down.Down) { analogY = 1.0f; } //if the left stick is moving,then use values read from the stick if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f) { analogX = data.AnalogLeftX; analogY = data.AnalogLeftY; } //calculate the position /*if(analogX>0) * { * Position = new Vector2 (Position.X + 0.1f, Position.Y); * }else if(analogX<0) * { * Position = new Vector2 (Position.X - 0.1f, Position.Y); * } * * if(analogY>0) * { * Position = new Vector2 (Position.X + Position.Y- 0.1f); * }else if(analogY<0) * { * Position = new Vector2 (Position.X, Position.Y + 0.1f); * }*/ Vector2 proposedChange; if (analogX != 0.0f) { proposedChange = new Vector2(analogX / 10f, 0.0f); if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange)) { Position += proposedChange; } } if (analogY != 0.0f) { proposedChange = new Vector2(0.0f, -analogY / 10f); if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange)) { Position += proposedChange; } } //rotate according to the right analog stick, or if it's not moving, then according the the left stick // so basically if you are not pointing the player in any direction with the right stick he is going to point in the walking direction //or if both sticks are not moving,then use the analogX and analogY values(d-pad movement) // OR do autoaim if enabled if (data.AnalogRightX > 0.2f || data.AnalogRightX < -0.2f || data.AnalogRightY > 0.2f || data.AnalogRightY < -0.2f) { var angleInRadians = FMath.Atan2(-data.AnalogRightX, -data.AnalogRightY); playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else if (!Game.autoAim && (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f)) { var angleInRadians = FMath.Atan2(-data.AnalogLeftX, -data.AnalogLeftY); playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else if (!Game.autoAim && (analogX != 0.0f || analogY != 0.0f)) { var angleInRadians = FMath.Atan2(-analogX, -analogY); playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else if (Game.autoAim) { GameEntity e; if (Collisions.findNearestEnemy(Player.Instance, 8.0f, out e)) { Vector2 distance = (Player.Instance.Position - e.Position).Normalize(); var angleInRadians = FMath.Atan2(distance.X, -distance.Y); playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } else { var angleInRadians = FMath.Atan2(-analogX, -analogY); playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); } } }
// Recreated the test scene there: // http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html public void CreateRPGTestScene() { // layer y=0 SetBlock(new Vector3i(0, 0, 0), DirtBlock); SetBlock(new Vector3i(1, 0, 0), DirtBlock); SetBlock(new Vector3i(2, 0, 0), DirtBlock); SetBlock(new Vector3i(3, 0, 0), DirtBlock); SetBlock(new Vector3i(4, 0, 0), DirtBlock); SetBlock(new Vector3i(5, 0, 0), DirtBlock); SetBlock(new Vector3i(6, 0, 0), DirtBlock); SetBlock(new Vector3i(0, 0, 1), GrassBlock); SetBlock(new Vector3i(1, 0, 1), GrassBlock); SetBlock(new Vector3i(2, 0, 1), GrassBlock); SetBlock(new Vector3i(3, 0, 1), StoneBlock); SetBlock(new Vector3i(4, 0, 1), StoneBlock); SetBlock(new Vector3i(5, 0, 1), DirtBlock); SetBlock(new Vector3i(6, 0, 1), DirtBlock); SetBlock(new Vector3i(0, 0, 2), GrassBlock); SetBlock(new Vector3i(1, 0, 2), WaterBlock); SetBlock(new Vector3i(2, 0, 2), WaterBlock); SetBlock(new Vector3i(3, 0, 2), GrassBlock); // layer y=1 SetBlock(new Vector3i(4, 1, 1), StoneBlock); SetBlock(new Vector3i(5, 1, 1), DirtBlock); SetBlock(new Vector3i(6, 1, 1), DirtBlock); SetBlock(new Vector3i(0, 1, 2), GrassBlock); SetBlock(new Vector3i(1, 1, 2), WaterBlock); SetBlock(new Vector3i(2, 1, 2), WaterBlock); SetBlock(new Vector3i(3, 1, 2), GrassBlock); // layer y=2 SetBlock(new Vector3i(0, 2, 2), StoneBlock); SetBlock(new Vector3i(1, 2, 2), WaterBlock); SetBlock(new Vector3i(2, 2, 2), WaterBlock); SetBlock(new Vector3i(3, 2, 2), StoneBlock); SetBlock(new Vector3i(4, 2, 2), StoneBlock); SetBlock(new Vector3i(5, 2, 2), StoneBlock); SetBlock(new Vector3i(6, 2, 2), RampSouth); // layer y=3 SetBlock(new Vector3i(0, 3, 3), RampWest); SetBlock(new Vector3i(1, 3, 3), StoneBlock); SetBlock(new Vector3i(2, 3, 3), StoneBlock); SetBlock(new Vector3i(3, 3, 3), StoneBlock); SetBlock(new Vector3i(4, 3, 3), RampEast); SetBlock(new Vector3i(5, 3, 2), StoneBlock); SetBlock(new Vector3i(6, 3, 2), StoneBlock); // layer y=4 SetBlock(new Vector3i(0, 4, 2), StoneBlock); SetBlock(new Vector3i(1, 4, 2), WaterBlock); SetBlock(new Vector3i(2, 4, 2), WaterBlock); SetBlock(new Vector3i(3, 4, 2), PlainBlock); SetBlock(new Vector3i(4, 4, 3), WallBlock); SetBlock(new Vector3i(4, 4, 4), WallBlock); SetBlock(new Vector3i(4, 4, 5), WallBlock); SetBlock(new Vector3i(5, 4, 2), StoneBlock); SetBlock(new Vector3i(5, 4, 3), DoorTallClosed); SetBlock(new Vector3i(6, 4, 3), WallBlock); SetBlock(new Vector3i(6, 4, 4), WallBlock); SetBlock(new Vector3i(6, 4, 5), WallBlock); // try put as many sprites in SpriteList for performance SpriteList sprite_list = new SpriteList(ObjectsMap); sprite_list.AddChild(NewCharater(CharacterBoy, new Vector3(3, 1.5f, 3))); sprite_list.AddChild(NewCharater(CharacterHornGirl, new Vector3(5, 2.6f, 3))); sprite_list.AddChild(NewCharater(CharacterPrincessGirl, new Vector3(6, 1, 2))); sprite_list.AddChild(NewObject(Rock, new Vector3(3, 0, 3))); sprite_list.AddChild(NewObject(Rock, new Vector3(6, 0, 2))); sprite_list.AddChild(NewObject(Key, new Vector3(5, 0, 2))); sprite_list.AddChild(NewTree(TreeShort, new Vector3(0.5f, 1, 3))); AddChild(sprite_list); { var bug = NewObject(EnemyBug, new Vector3(2, 3, 4)); bug.Schedule((dt) => { float p = 1.0f; bug.Position = this.GetCellPos(Math.Lerp(new Vector3(1, 3, 4), new Vector3(3, 3, 4) , (1.0f + FMath.Sin((float)Director.Instance.DirectorTime * p)) * 0.5f)); // we just care about the sign of the derivative bug.FlipU = (FMath.Cos((float)Director.Instance.DirectorTime * p) < 0.0f); }); AddChild(bug); } }
public void Copy2Buffer(SpriteB spriteB, int index) { if (spriteB.Rotation == 0.0f) { bufferVerties[index * VERTEX_SIZE_PER_SPRITE] = spriteB.Position.X - spriteB.Width * spriteB.Center.X; //0.0f; // x0 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 1] = spriteB.Position.Y - spriteB.Height * spriteB.Center.Y; //0.0f; // y0 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 2] = spriteB.Position.Z; // z0 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 3] = spriteB.Position.X - spriteB.Width * spriteB.Center.X; //0.0f; // x1 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 4] = spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y); //1.0f; // y1 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 5] = spriteB.Position.Z; // z1 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 6] = spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X); //1.0f; // x2 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 7] = spriteB.Position.Y - spriteB.Height * spriteB.Center.Y; //0.0f; // y2 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 8] = spriteB.Position.Z; // z2 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 9] = spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X); //1.0f; // x3 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 10] = spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y); //1.0f; // y3 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 11] = spriteB.Position.Z; // z3 } else { float x, y, rc, rs; rc = FMath.Cos(spriteB.Rotation); rs = FMath.Sin(spriteB.Rotation); x = -spriteB.Width * spriteB.Center.X; y = -spriteB.Height * spriteB.Center.Y; bufferVerties[index * VERTEX_SIZE_PER_SPRITE] = spriteB.Position.X + (float)(x * rc - y * rs); // x0 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 1] = spriteB.Position.Y + (float)(x * rs + y * rc); // y0 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 2] = spriteB.Position.Z; // z0 x = -spriteB.Width * spriteB.Center.X; y = spriteB.Height * (1.0f - spriteB.Center.Y); bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 3] = spriteB.Position.X + (float)(x * rc - y * rs); // x1 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 4] = spriteB.Position.Y + (float)(x * rs + y * rc); // y1 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 5] = spriteB.Position.Z; // z1 x = spriteB.Width * (1.0f - spriteB.Center.X); y = -spriteB.Height * spriteB.Center.Y; bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 6] = spriteB.Position.X + (float)(x * rc - y * rs); // x2 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 7] = spriteB.Position.Y + (float)(x * rs + y * rc); // y2 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 8] = spriteB.Position.Z; // z2 x = spriteB.Width * (1.0f - spriteB.Center.X); y = spriteB.Height * (1.0f - spriteB.Center.Y); bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 9] = spriteB.Position.X + (float)(x * rc - y * rs); // x3 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 10] = spriteB.Position.Y + (float)(x * rs + y * rc); // y3 bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 11] = spriteB.Position.Z; // z3 } #if false bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE] = texcoords[0]; // left top u bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 1] = texcoords[1]; // left top v bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 2] = texcoords[2]; // left bottom u bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 3] = texcoords[3]; // left bottom v bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 4] = texcoords[4]; // right top u bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 5] = texcoords[5]; // right top v bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 6] = texcoords[6]; // right bottom u bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 7] = texcoords[7]; // right bottom v #else Buffer.BlockCopy(spriteB.Texcoords, 0, bufferTexcoords, index * TEXCOORD_SIZE_PER_SPRITE * sizeof(float), 8 * sizeof(float)); #endif // color #if false bufferColors[index * COLOR_SIZE_PER_SPRITE] = colors[0]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 1] = colors[1]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 2] = colors[2]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 3] = colors[3]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 4] = colors[4]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 5] = colors[5]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 6] = colors[6]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 7] = colors[7]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 8] = colors[8]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 9] = colors[9]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 10] = colors[10]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 11] = colors[11]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 12] = colors[12]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 13] = colors[13]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 14] = colors[14]; bufferColors[index * COLOR_SIZE_PER_SPRITE + 15] = colors[15]; #else Buffer.BlockCopy(spriteB.Colors, 0, bufferColors, index * COLOR_SIZE_PER_SPRITE * sizeof(float), 16 * sizeof(float)); #endif bufferIndices[index * INDEX_SIZE_PER_SPRITE] = (ushort)(index * VERTEX_NUM_PER_SPRITE); bufferIndices[index * INDEX_SIZE_PER_SPRITE + 1] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 1); bufferIndices[index * INDEX_SIZE_PER_SPRITE + 2] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 2); bufferIndices[index * INDEX_SIZE_PER_SPRITE + 3] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 1); bufferIndices[index * INDEX_SIZE_PER_SPRITE + 4] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 2); bufferIndices[index * INDEX_SIZE_PER_SPRITE + 5] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 3); }
public BasicEnemy(Vector2 pos, TextureInfo tex) { Position = pos; sprite = new SpriteTile(); sprite.TextureInfo = tex; sprite.Position = pos; sprite.TileIndex2D = new Vector2i(0, 0); sprite.CenterSprite(new Vector2(0.4f, 0.5f)); sprite.Scale = new Vector2(2.0f, 2.0f); //set up the random vector randomMovement = Support.rand.NextVector2(-0.01f, 0.01f); //update the animation frames sprite.Schedule((dt) => { if (FrameCount % 2 == 0) { //if attacking,use all animation frames if (attacking) { //deal damage to the player if (FrameCount % damageDelay == 0) { Player.Instance.Health -= damage; } animationFrame = (animationFrame + 1) % 25; } else { //if not,then use first three animation frames animationFrame = (animationFrame + 1) % 4; } //assign the correct tileindex sprite.TileIndex1D = animationFrame; //if close to the player,then follow,otherwise move randomly if (Player.Instance.Position.Distance(sprite.Position) < 6.0f && Collisions.checkLineOfSight(this, Player.Instance)) { isMovingRandomly = false; step = (Player.Instance.Position - sprite.Position).Normalize() / 15.0f; //check if should be attacking if (Collisions.checkCollisionBetweenEntities(this, Player.Instance)) { //check if is not attacking already if (attacking == false) { attacking = true; //manualy skip the frames animationFrame = 4; } } else { //make sure that attacking is set to false attacking = false; } } else { //player is not within range, move randomly isMovingRandomly = true; step = randomMovement; } } //advance the position by the given Vector2 step sprite.Position += step; //only move when not attacking if (!attacking) { //collision detection on the X axis //create a vector 2 containing a proposed change to the position Vector2 proposedChange = new Vector2(step.X, 0.0f) * speedModifier; //temporary game entity to contain the entity the enemy might have collided with GameEntity tempEntity; //check wall collisions and then collisions with other enemies if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity)) { //no collision, so we can change the position Position += proposedChange / speedModifier; } else if (isMovingRandomly) { //collided with something,but if the enemy should be moving randomly, then let it move randomMovement.X = -randomMovement.X; } //collision detection on the Y axis proposedChange = new Vector2(0.0f, step.Y) * speedModifier; if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity)) { Position += proposedChange / speedModifier; } else if (isMovingRandomly) { randomMovement.Y = -randomMovement.Y; } //position changed, so we need to remove the entity from the QuadTree and add again //this is because the entity might be in the wrong place in the QuadTree and removing and re-adding is the only way to fix that Game.Instance.quadTree.removeEntity(this); Game.Instance.quadTree.insert(this); } //rotate the sprite to face the direction of walking var angleInRadians = -FMath.Atan2(step.X, step.Y); sprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); //correct for the fact that the sprite is rotated in the texture file sprite.Rotation = sprite.Rotation.Rotate(90.0f); }, -1); //create a shadow texture - temporarily disabled //SpriteUV shadow = new SpriteUV(new TextureInfo(Bullet.fireTexture)); //shadow.CenterSprite(new Vector2(0.5f,0.5f)); //shadow.Color = Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.SetAlpha(Colors.Black,0.5f); //calculate the bounds for the entire sprite bounds = new Bounds2(); sprite.GetlContentLocalBounds(ref bounds); bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f); }
internal static AnimationInterpolator GetSpringInterpolator(int strength) { if (strength > 0) { strength = Math.Min(100, strength); float startupTime = 0.4f / (float)strength; float cycleTime = (1f - startupTime) / (float)strength; float angularFrequency = 6.28318548f / cycleTime; Func <float, float> ratioConverter = delegate(float t) { if (t >= startupTime) { return(0.7f + 0.3f * FMath.Exp(-(t - startupTime) / cycleTime) * FMath.Cos(angularFrequency * (t - startupTime))); } return(FMath.Sin(t * 3.14159274f / 2f / startupTime)); }; return(AnimationUtility.GetAnimationInterpolator(ratioConverter)); } return(new AnimationInterpolator(AnimationUtility.LinearInterpolator)); }
public static Quatf AxisAngleToQuatf(Vec3f axis, float angle) { return(new Quatf(FMath.Cos(angle), axis * FMath.Sin(angle))); }
/// 食べられる private bool statePlayEat() { if (objCh.texId != (int)Data.Tex2dResId.Necromancer1) { if (ctrlResMgr.CtrlCam.camModeId == CtrlCamera.ModeId.CloseLook || ctrlResMgr.CtrlCam.camModeId == CtrlCamera.ModeId.CloseLookToNormal || ctrlResMgr.CtrlCam.camModeId == CtrlCamera.ModeId.NormalToCloseLook) { switch (statePlayTask) { case 0: statePlayTask++; break; /// 終了待ち case 1: ActiveDis = 0.001f; statePlayTask++; //食われる動作 break; /// エフェクト余韻 case 2: EatAngle = new Vector3(ctrlResMgr.CtrlCam.GetCamPos().X, ctrlResMgr.CtrlCam.GetCamPos().Y - 1.0f, ctrlResMgr.CtrlCam.GetCamPos().Z) - BasePos; BasePos += EatAngle.Normalize() * (int)(Data.SetupValue.EatingSpeed) / 10.0f; float dis = Common.VectorUtil.DistanceY(BasePos, ctrlResMgr.CtrlCam.GetCamPos()); if (dis < (int)Data.SetupValue.EatingDeadArea / 10.0f) { statePlayTask++; } break; case 3: // EventCntr.Add( ActorEventId.Effect, (int)Data.EffTypeId.Eff05, BasePos ); AppSound.GetInstance().PlaySeCamDis(AppSound.SeId.Eat, BasePos); ctrlResMgr.EatingFlag = true; ctrlResMgr.EatCharNumber = objCh.texId; Enable = false; break; } } else { ctrlResMgr.EatCharNumber = objCh.texId; Enable = false; } } else { switch (statePlayTask) { case 0: statePlayTask++; break; /// 終了待ち case 1: ctrlResMgr.changePlAni = true; ctrlResMgr.eatingBoss = true; ctrlResMgr.CtrlCam.SetCamMode(CtrlCamera.ModeId.NormalToLookMyself); EatAngle = new Vector3(ctrlResMgr.CtrlCam.GetCamPos().X, ctrlResMgr.CtrlCam.GetCamPos().Y - 1.0f, ctrlResMgr.CtrlCam.GetCamPos().Z) - BasePos; //BasePos.X = ctrlResMgr.CtrlPl.GetPos().X + FMath.Sin( ctrlResMgr.CtrlCam.GetCamRot().Y / 180 *FMath.PI)*5; //BasePos.Y = 2; //BasePos.Z = ctrlResMgr.CtrlPl.GetPos().Z + FMath.Cos( ctrlResMgr.CtrlCam.GetCamRot().Y / 180 *FMath.PI)*5;; float angleY = ctrlResMgr.CtrlPl.GetRotY() - 30; if (angleY < -360.0f) { angleY += 360.0f; } else if (angleY > 360.0f) { angleY -= 360.0f; } BasePos.X = ctrlResMgr.CtrlPl.GetPos().X + FMath.Sin(angleY * FMath.PI / 180.0f) * 19; BasePos.Z = ctrlResMgr.CtrlPl.GetPos().Z + FMath.Cos(angleY * FMath.PI / 180.0f) * 19; BasePos.Y = ctrlResMgr.CtrlPl.GetPos().Y; eatingTime = 0; moveAngle = false; statePlayTask++; //食われる動作 break; /// エフェクト余韻 case 2: float angleY2 = ctrlResMgr.CtrlPl.GetRotY() - 30; if (angleY2 < -360.0f) { angleY2 += 360.0f; } else if (angleY2 > 360.0f) { angleY2 -= 360.0f; } // BasePos.X = ctrlResMgr.CtrlPl.GetPos().X + FMath.Sin ( angleY2 * FMath.PI / 180.0f ) * (19 - 12* FMath.Cos ( (1-eatingTime / 40.0f) * FMath.PI/2 )); // BasePos.Z = ctrlResMgr.CtrlPl.GetPos().Z + FMath.Cos ( angleY2 * FMath.PI / 180.0f ) * (19 - 12* FMath.Cos ( (1-eatingTime / 40.0f) * FMath.PI/2 )); BasePos.X = ctrlResMgr.CtrlPl.GetPos().X + FMath.Sin(angleY2 * FMath.PI / 180.0f) * 19; BasePos.Z = ctrlResMgr.CtrlPl.GetPos().Z + FMath.Cos(angleY2 * FMath.PI / 180.0f) * 19; BasePos.Y = ctrlResMgr.CtrlPl.GetPos().Y + FMath.Sin(eatingTime / 80.0f * FMath.PI) * 13.0f; eatingTime++; if (eatingTime > 30) { statePlayTask++; } float dis = Common.VectorUtil.DistanceY(BasePos, ctrlResMgr.CtrlCam.GetCamPos()); /* * if(dis < (int)Data.SetupValue.EatingDeadArea){ * statePlayTask ++; * }*/ break; case 3: float angleY3 = ctrlResMgr.CtrlPl.GetRotY() - 30; if (angleY3 < -360.0f) { angleY3 += 360.0f; } else if (angleY3 > 360.0f) { angleY3 -= 360.0f; } BasePos.X = ctrlResMgr.CtrlPl.GetPos().X + FMath.Sin(angleY3 * FMath.PI / 180.0f) * 19 * (1 - (eatingTime - 30) / 40.0f) + FMath.Sin(ctrlResMgr.CtrlPl.GetRotY() * FMath.PI / 180.0f) * 3 * (eatingTime - 30) / 40.0f; BasePos.Z = ctrlResMgr.CtrlPl.GetPos().Z + FMath.Cos(angleY3 * FMath.PI / 180.0f) * 19 * (1 - (eatingTime - 30) / 40.0f) + FMath.Cos(ctrlResMgr.CtrlPl.GetRotY() * FMath.PI / 180.0f) * 3 * (eatingTime - 30) / 40.0f; if (eatingTime < 40) { BasePos.Y = ctrlResMgr.CtrlPl.GetPos().Y + FMath.Sin(eatingTime / 80.0f * FMath.PI) * 13.0f; } eatingTime++; if (eatingTime > 55) { statePlayTask++; eatingTime = 0; } break; case 4: // EventCntr.Add( ActorEventId.Effect, (int)Data.EffTypeId.Eff05, BasePos ); ctrlResMgr.CtrlPl.Addeffect(BasePos); statePlayTask++; break; case 5: eatingTime++; if (eatingTime == 15) { ctrlResMgr.CtrlPl.Addeffect(new Vector3(BasePos.X + 1.0f, BasePos.Y + 0.3f, BasePos.Z + 1.0f)); } if (eatingTime > 30) { statePlayTask++; } break; case 6: // EventCntr.Add( ActorEventId.Effect, (int)Data.EffTypeId.Eff05, BasePos ); ctrlResMgr.CtrlCam.SetCamMode(CtrlCamera.ModeId.LookMyselfToNormal); ctrlResMgr.changePlAni = true; ctrlResMgr.eatingBoss = false; AppSound.GetInstance().PlaySeCamDis(AppSound.SeId.Eat, BasePos); ctrlResMgr.CtrlPl.Addeffect(BasePos); ctrlResMgr.CtrlStg.MonumentSetFlag = true; ctrlResMgr.EatCharNumber = objCh.texId; eatingTime++; if (eatingTime > 20) { statePlayTask++; } // ctrlResMgr.CtrlPl.Addeffect(BasePos); Enable = false; break; } } return(true); }
public ChainedLabel(ChainedLabel target, Scene scene, Plane3D parent, float alpha, int order) : base() { if (alpha != 0.0f) { alpha = Math.Lerp(0.2f, 1.0f, alpha); } FontMap = LargeFontMap; HeightScale = scene.Camera.GetPixelSize(); Color = Math.Lerp(Colors.White, Colors.Grey60, alpha); VertexZ = 1.0f; Text = "Label.VertexZ=" + VertexZ; Shadow = new Label() { FontMap = LargeFontMap, Color = Colors.Grey05 }; Shadow.HeightScale = HeightScale; Shadow.Text = Text; Target = target; Schedule((dt) => { if (Target == null) { // head node this.Position = m_center + m_radius * new Vector2(FMath.Cos((float)Director.Instance.DirectorTime * 0.5f * 2.033f), FMath.Cos((float)Director.Instance.DirectorTime * 0.5f * 0.98033f + 0.5f)); Vector2 touch_pos = Director.Instance.CurrentScene.Camera.GetTouchPos(); // you can drag the Label if (Input2.Touch00.Down) { if (Input2.Touch00.Press // not that since we set VertexZ and have used a perspective in this particular test scene, // the picking here won't be very precise && this.IsWorldPointInsideContentLocalBounds(touch_pos)) { m_dragged = true; m_drag_start = touch_pos; m_center = this.Position; // this is our new position, we zero the cosine offset too m_radius = 0.0f; m_drag_start_center = m_center; } if (m_dragged) { m_center = m_drag_start_center + (touch_pos - m_drag_start); m_radius = 0.0f; } } else { m_dragged = false; m_radius += (m_radius_target - m_radius) * 0.001f; } } else { // follower node this.Position += 0.08f * (Target.Position - this.Position); } this.Shadow.Position = this.Position; } ); parent.AddChild(Shadow, -1); parent.AddChild(this, order); }