public static bool UnityEngineVector3MCall(object objSelf, string functionName, List <CQ_Value> param, out CQ_Value returnValue, bool mustEqual) { UnityEngine.Vector3 obj = (UnityEngine.Vector3)objSelf; if (param.Count == 3 && functionName == "Set" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual)) { returnValue = null; obj.Set((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float))); return(true); } if (param.Count == 1 && functionName == "Scale" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual)) { returnValue = null; obj.Scale((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3))); return(true); } if (param.Count == 0 && functionName == "GetHashCode") { returnValue = new CQ_Value(); returnValue.type = typeof(int); returnValue.value = obj.GetHashCode(); return(true); } if (param.Count == 1 && functionName == "Equals" && MatchType(param, new Type[] { typeof(object) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(bool); returnValue.value = obj.Equals((object)param[0].ConvertTo(typeof(object))); return(true); } if (param.Count == 0 && functionName == "Normalize") { returnValue = null; obj.Normalize(); return(true); } if (param.Count == 0 && functionName == "ToString") { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString(); return(true); } if (param.Count == 1 && functionName == "ToString" && MatchType(param, new Type[] { typeof(string) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString((string)param[0].ConvertTo(typeof(string))); return(true); } if (param.Count == 0 && functionName == "GetType") { returnValue = new CQ_Value(); returnValue.type = typeof(System.Type); returnValue.value = obj.GetType(); return(true); } returnValue = null; return(false); }
void Update() { _myPosition = transform.position; if (Input.GetButton("Horizontal")) { _horizontalInput = Input.GetAxis("Horizontal"); if (_horizontalInput < 0) { transform.rotation = Quaternion.LookRotation(-Vector3.right); if (transform.position.x <= minXMarker.position.x) { _horizontalInput = 0; } } else if (_horizontalInput > 0) { transform.rotation = Quaternion.LookRotation(Vector3.right); if (transform.position.x >= maxXMarker.position.x) { _horizontalInput = 0; } } } if (Input.GetButtonUp("Horizontal")) { transform.rotation = Quaternion.LookRotation(Vector3.forward); _horizontalInput = 0; } _movement.Set(_horizontalInput * movementSpeed, gravity, 0); _myAnimator.SetFloat("Speed_f", Mathf.Abs(_horizontalInput * movementSpeed)); _myCharacterController.Move(_movement * Time.deltaTime); if (Input.GetButtonDown("Jump")) { _myAnimator.SetInteger("Animation_int", 10); for (int i = 0; i < 50; i++) { _foodIndex = Random.Range(0, foodObjectPool.Length); if (!foodObjectPool[_foodIndex].activeSelf) { foodObjectPool[_foodIndex].transform.position = playerFirePosition.position; foodObjectPool[_foodIndex].SetActive(true); break; } } } if (Input.GetButtonUp("Jump")) { _myAnimator.SetInteger("Animation_int", 0); } _myPosition.Set(transform.position.x, _myPosition.y, _myPosition.z); transform.position = _myPosition; }
public UnityEngine.Vector3 GetRequestCenter() { if (_requestObject != null) { UnityEngine.Vector3 v = new UnityEngine.Vector3(); v.Set(_requestObject.transform.position.x, _requestObject.transform.position.y, _requestObject.transform.position.z); return(v); } return(new UnityEngine.Vector3()); }
// Update is called once per frame void Update() { _sim.DoStep(); UnityEngine.Vector3 newPos = new UnityEngine.Vector3(); for (int i = 0; i < _sim.AgentCount; ++i) { MengeCS.Vector3 pos3d = _sim.GetAgent(i).Position; newPos.Set(pos3d.X, pos3d.Y, pos3d.Z); _objects [i].transform.position = newPos; } }
/// <summary> /// Get the node position of input device identified by handle. /// </summary> public static TrackingResult GetSmoothPosition(int node, ref UnityEngine.Vector3 position) { lock (GetSmoothPosition_floats){ int ret = NativeMethods.XHawkGetSmoothPosition(node, GetSmoothPosition_floats); if (ret > 0) { position.Set( GetSmoothPosition_floats[0], GetSmoothPosition_floats[1], -GetSmoothPosition_floats[2] ); } else { position.Set(0, 0, 0); return(TrackingResult.NotTracked); } return((TrackingResult)ret); } }
/// <summary> /// Get the node position of input device identified by handle. /// </summary> public static TrackingResult GetNodePosition(int which, int history, int node, ref UnityEngine.Vector3 position) { lock (GetNodePosition_floats){ int ret = NativeMethods.XDeviceGetNodePosition(which, history, node, GetNodePosition_floats); if (ret > 0) { position.Set( GetNodePosition_floats[0], GetNodePosition_floats[1], -GetNodePosition_floats[2] ); } else { position.Set(0, 0, 0); return(TrackingResult.NotTracked); } return((TrackingResult)ret); } }
public override List <UnityEngine.Vector3> GetVector3List(OutputSocket s, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float seed) { List <UnityEngine.Vector3> vectors = GetInputVector3List(_inputSocketVectors, x, y, z, sizeX, sizeY, sizeZ, seed); if (vectors != null) { for (var i = 0; i < vectors.Count; i++) { UnityEngine.Vector3 v = vectors[i]; float valueX = AbstractNumberNode.GetInputNumber(_inputSocketX, v.x, v.y, v.z, seed); float valueY = AbstractNumberNode.GetInputNumber(_inputSocketY, v.x, v.y, v.z, seed); float valueZ = AbstractNumberNode.GetInputNumber(_inputSocketZ, v.x, v.y, v.z, seed); //Debug.Log("valueX " + valueX + " valueY " + valueY + " valueZ " + valueZ); if (_selectedMode == 0) { v.Set(v.x + valueX, v.y + valueY, v.z + valueZ); } if (_selectedMode == 1) { v.Set(v.x - valueX, v.y - valueY, v.z - valueZ); } if (_selectedMode == 2) { v.Set(v.x * valueX, v.y * valueY, v.z * valueZ); } if (_selectedMode == 3) { v.Set(valueX != 0 ? v.x / valueX : v.x, valueY != 0 ? v.y / valueY : v.y, valueZ != 0 ? v.z / valueZ : valueZ); } vectors[i] = v; //Debug.Log("x " + vectors[i].x + " y " + vectors[i].y + " z " + vectors[i].z + " valueY " + valueY); } } return(vectors); }
public override List <UnityEngine.Vector3> GetVector3List(OutputSocket s, Request request) { Request r = new Request(); List <UnityEngine.Vector3> vectors = GetInputVector3List(_inputSocketVectors, request); if (vectors != null) { for (var i = 0; i < vectors.Count; i++) { UnityEngine.Vector3 v = vectors[i]; r.X = v.x; r.Y = v.y; r.Z = v.z; r.Seed = request.Seed; float valueX = AbstractNumberNode.GetInputNumber(_inputSocketX, r); float valueY = AbstractNumberNode.GetInputNumber(_inputSocketY, r); float valueZ = AbstractNumberNode.GetInputNumber(_inputSocketZ, r); if (_selectedMode == 0) { v.Set(v.x + valueX, v.y + valueY, v.z + valueZ); } if (_selectedMode == 1) { v.Set(v.x - valueX, v.y - valueY, v.z - valueZ); } if (_selectedMode == 2) { v.Set(v.x * valueX, v.y * valueY, v.z * valueZ); } if (_selectedMode == 3) { v.Set(valueX != 0 ? v.x / valueX : v.x, valueY != 0 ? v.y / valueY : v.y, valueZ != 0 ? v.z / valueZ : valueZ); } vectors[i] = v; } } return(vectors); }
private void PlayParticle(UnityEngine.Vector3 nguiPos) { if (effect != null) { UnityEngine.GameObject ef = ResourceSystem.NewObject(effect) as GameObject; if (ef != null) { nguiPos.Set(-0.17f, nguiPos.y, nguiPos.z); ef.transform.position = nguiPos; Destroy(ef, duration); } } }
public static void AvieToEuclid(Vector3 position, ref Vector3 outVector) { //fast version, writes the output to outVector float angle = position.x; float length = position.z; //in meters already. The length is the hypotenuse angle = angle % 1.0F; //get angle in range 0.0->1.0 angle *= TWO_PI; // degrees to radians float euclidx = Mathf.Sin(angle) * length; float euclidz = Mathf.Cos(angle) * length; outVector.Set (euclidx,position.y,euclidz); }
public static void EuclidToAvie(Vector3 position, ref Vector3 outVector) { float xlength = position.x; float zlength = position.z; float hypotenuse = Mathf.Sqrt(xlength * xlength + zlength * zlength); float angle = Mathf.Atan2(zlength,xlength); angle += Mathf.PI; //range of angle is -pi to pi... angle /= TWO_PI; angle = 0.75F - angle; angle %= 1.0F; outVector.Set(angle,position.y,hypotenuse); }
public void AddPoint(Vector3 _position, float _angle) { _position.Set(_position.x, _position.y, 0); if (vertexCount >= vertices.Count) { vertices.Add(new VLSPoint(_position, _angle)); } else { vertices[vertexCount].position = _position; vertices[vertexCount].angle = _angle; } vertexCount++; }
private void DrawLine() { DrawLimitAreas(); float segments = _panelWidth / 5f; float start = _spline.LowestX; float end = _spline.HighestX; float step = (end - start) / segments; Handles.color = _pointColor; for (var i = start; i <= Mathf.Ceil(end - step); i += step) { float x0 = i; float x1 = Mathf.Min(i + step, end); float y0 = GetValueAt(x0); float y1 = GetValueAt(x1); _tmpVec0.Set(x0, y0, 0); _tmpVec1.Set(x1, y1, 0); UnityEngine.Vector3 v0 = ToNodePotision(_tmpVec0); UnityEngine.Vector3 v1 = ToNodePotision(_tmpVec1); Handles.DrawLine(v0, v1); } }
static bool Vector3_Set__Single__Single__Single(JSVCall vc, int argc) { int len = argc; if (len == 3) { System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); System.Single arg1 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); System.Single arg2 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); UnityEngine.Vector3 argThis = (UnityEngine.Vector3)vc.csObj; argThis.Set(arg0, arg1, arg2); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
void updateReceived(Nugget nugget) { TrackedPosition.Set( nugget.Flakes(0).Value.Vector3s(0).Value.X, nugget.Flakes(0).Value.Vector3s(0).Value.Y, nugget.Flakes(0).Value.Vector3s(0).Value.Z); TrackedRotation.Set( nugget.Flakes(0).Value.Vector4s(0).Value.X, nugget.Flakes(0).Value.Vector4s(0).Value.Y, nugget.Flakes(0).Value.Vector4s(0).Value.Z, nugget.Flakes(0).Value.Vector4s(0).Value.W); UpdatedThisFrame = true; //deltaTime = Time.time - lastUpdateTime; //lastUpdateTime = Time.time; //Debug.Log (deltaTime); }
void UpdateTracking() { if (UpdatedThisFrame) { viconPos = TrackedPosition; viconRot = TrackedRotation; viconPos.Set(viconPos.x, viconPos.y, -viconPos.z); viconRot.Set(viconRot.x, viconRot.y, -viconRot.z, -viconRot.w); if (!rotCorrected) { correctRotation(); } // transform.position = rotDiff*viconPos; transform.position = viconPos; // transform.rotation = viconRot; UpdatedThisFrame = false; } }
// Update is called once per frame void FixedUpdate() { if (_sim_is_valid) { _sim.DoStep(); UnityEngine.Vector3 newPos = new UnityEngine.Vector3(); for (int i = 0; i < _sim.AgentCount; ++i) { MengeCS.Vector3 pos3d = _sim.GetAgent(i).Position; // var orient = new UnityEngine.Vector2(_sim.GetAgent(i).Orientation.X, _sim.GetAgent(i).Orientation.Y); //Debug.Log(orient); newPos.Set(pos3d.X, pos3d.Y, pos3d.Z); DrawLine(_objects[i].transform.position, newPos, colors[i], 200); _objects[i].transform.position = newPos; } } }
static int Set(IntPtr L) { try { ToLua.CheckArgsCount(L, 4); UnityEngine.Vector3 obj = (UnityEngine.Vector3)ToLua.CheckObject(L, 1, typeof(UnityEngine.Vector3)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); float arg1 = (float)LuaDLL.luaL_checknumber(L, 3); float arg2 = (float)LuaDLL.luaL_checknumber(L, 4); obj.Set(arg0, arg1, arg2); ToLua.SetBack(L, 1, obj); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static public int Set(IntPtr l) { try{ UnityEngine.Vector3 self = (UnityEngine.Vector3)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); System.Single a3; checkType(l, 4, out a3); self.Set(a1, a2, a3); setBack(l, self); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
private void Update() { var moveSpeedInput = moveSpeed * Input.GetAxis("Horizontal"); moveDirection.Set(moveSpeedInput, yDirection, 0); yDirection += gravity * Time.deltaTime; if (controller.isGrounded && moveDirection.y < 0) { yDirection = -1f; } if (Input.GetButtonDown("Jump")) { yDirection = jumpForce; } var movement = moveDirection * Time.deltaTime; controller.Move(movement); }
public void Shoot() { if ((Input.mousePosition.x > Screen.width / 5 || Input.mousePosition.y > Screen.height / 2.5)&&(Input.mousePosition.x > 60 || Input.mousePosition.y < Screen.height - 60)) { Vector3 target = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); target = Camera.main.ScreenToWorldPoint(target); target.Set(target.x, target.y, gameObject.transform.position.z); GameObject obj = bullets.FirstOrDefault(x => !x.activeInHierarchy); if (obj == null) { obj = (GameObject)Instantiate(bullet); bullets.Add(obj); } obj.SetActive (true); obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.GetComponent<Rigidbody2D>().velocity = (target - transform.position).normalized * speed; shoot = false; Invoke ("CanShootAgain",1f); } }
/// <summary> /// Generates a sphere within the polygon boundaries /// </summary> public void InitSphere() { Voxel.VoxelSize = Voxel.STANDARD_VOXEL_SIZE; Vector3 center = transform.position + Vector3.one * Chunks.GetLength(0) * Chunk.CHUNK_SIZE * Voxel.STANDARD_VOXEL_SIZE / 2f; Vector3 vect = Vector3.zero; for (int x = 0; x < Chunks.GetLength(0); x++) { for (int y = 0; y < Chunks.GetLength(1); y++) { for (int z = 0; z < Chunks.GetLength(2); z++) { for (int c_x = 0; c_x < Chunk.CHUNK_SIZE; c_x++) { for (int c_y = 0; c_y < Chunk.CHUNK_SIZE; c_y++) { for (int c_z = 0; c_z < Chunk.CHUNK_SIZE; c_z++) { vect.Set( Chunks[x, y, z].transform.position.x + (c_x * Voxel.VoxelSize), Chunks[x, y, z].transform.position.y + (c_y * Voxel.VoxelSize), Chunks[x, y, z].transform.position.z + (c_z * Voxel.VoxelSize) ); Chunks[x, y, z].Voxels[c_x][c_y][c_z] = (vect - center).magnitude < 0.4f ? (byte)8 : (byte)0; } } } } } } RecomputeChunks(); }
protected override bool DoRayCast(Ray ray, out RaycastHit hitInfo, float distance) { hitInfo = new RaycastHit(); var tr = gameObject.transform; Vector3 dir = ray.direction; Vector3 org = ray.origin; Vector3 aabbHalfExtent = size * 0.5f; Vector3 aabbCenter = center; Vector3 rayFrom = org; if (distance > 100000) { distance = 100000; } Vector3 rayTo = org + dir * distance; rayFrom = tr.InverseTransformPoint(org.x, org.y, org.z); rayTo = tr.InverseTransformPoint(rayTo.x, rayTo.y, rayTo.z); distance = (rayTo - rayFrom).magnitude; Vector3 source = rayFrom - aabbCenter; Vector3 target = rayTo - aabbCenter; float param = 100; int sourceOutcode = Outcode(source, aabbHalfExtent); int targetOutcode = Outcode(target, aabbHalfExtent); if ((sourceOutcode & targetOutcode) == 0x0) { float lambda_enter = 0.0f; float lambda_exit = param; Vector3 r = target - source; int i; float normSign = 1; Vector3 hitNormal = Vector3.zero; int bit = 1; for (int j = 0; j < 2; j++) { for (i = 0; i != 3; ++i) { if ((sourceOutcode & bit) != 0) { float lambda = (-source[i] - aabbHalfExtent[i] * normSign) / r[i]; if (lambda_enter <= lambda) { lambda_enter = lambda; hitNormal.Set(0, 0, 0); hitNormal[i] = normSign; } } else if ((targetOutcode & bit) != 0) { float lambda = (-source[i] - aabbHalfExtent[i] * normSign) / r[i]; if (lambda < lambda_exit) { lambda_exit = lambda; } } bit <<= 1; } normSign = -1.0f; } if (lambda_enter <= lambda_exit) { param = lambda_enter; hitInfo = new RaycastHit(); hitInfo.collider = this; hitInfo.distance = param * distance; hitInfo.point = rayFrom + (rayTo - rayFrom) * param; hitInfo.point = tr.TransformPoint(hitInfo.point.x, hitInfo.point.y, hitInfo.point.z); return(true); } } return(false); }
private Vector3 GetMoveToPosition() { var moveTo = new Vector3(MoveToActionData.x, MoveToActionData.y, MoveToActionData.z); if (isFixed) { // If new position is 0, we use the current one moveTo.Set( MoveToActionData.x == 0 ? ActionObject.transform.localPosition.x : MoveToActionData.x, MoveToActionData.y == 0 ? ActionObject.transform.localPosition.y : MoveToActionData.y, MoveToActionData.z == 0 ? ActionObject.transform.localPosition.z : MoveToActionData.z); } return moveTo; }
public static bool LineIntersects(Vector3 _a1, Vector3 _a2, Vector3 _b1, Vector3 _b2, ref Vector3 _out) { li_a = _a2 - _a1; li_c = _b2 - _b1; li_dp = li_a.x * li_c.y - li_a.y * li_c.x; if (li_dp <= 0) return false; li_b = _b1 - _a1; li_t = (li_b.x * li_c.y - li_b.y * li_c.x) / li_dp; if (li_t < 0 || li_t > 1) return false; li_u = (li_b.x * li_a.y - li_b.y * li_a.x) / li_dp; if (li_u < 0 || li_u > 1) return false; _out.Set(_a1.x + li_t * li_a.x, _a1.y + li_t * li_a.y, 0); return true; }
/*! \cond PRIVATE */ void getScaleInternal(float f, Vector3 baseScale, ref Vector3 scale) { if (ScaleMode == ScaleModeEnum.Advanced) { float scf = DTMath.Repeat(f - ScaleOffset, 1); float scx = baseScale.x * m_ScaleCurveX.Evaluate(scf); scale.Set(scx, (m_ScaleUniform) ? scx : baseScale.y * m_ScaleCurveY.Evaluate(scf), 1); } else scale = baseScale; }
public void CalculateShadowGeometry() { //UnityEngine.Vector3 proj; if (shadowMaterial == null) { return; } //if (useLightSource && lightSource == null){ // useLightSource = false; // Debug.LogWarning("No light source object given using light direction vector."); //} //if (useLightSource){ // UnityEngine.Vector3 ls = transform.position - lightSource.transform.position; // float mag = ls.magnitude; // if (mag != 0f){ // lightDirection = ls / mag; // } else { // return; //object is on top of light source // } //} else if (lightDirection != _lightDirection || lightDirection == UnityEngine.Vector3.zero){ //light direction is dirty // if (lightDirection == UnityEngine.Vector3.zero){ // Debug.LogWarning("Light Direction vector cannot be zero. assuming -y."); // lightDirection = -UnityEngine.Vector3.up; // } // lightDirection.Normalize(); // _lightDirection = lightDirection; //} if (shadowCaster == null || girth != _girth) { if (shadowCaster == null) { shadowCaster = new UnityEngine.GameObject("shadowSimple"); cornerGOs = new UnityEngine.GameObject[4]; for (int i = 0; i < 4; i++) { UnityEngine.GameObject c = cornerGOs[i] = new UnityEngine.GameObject("c" + i); c.transform.parent = shadowCaster.transform; } shadowCaster.transform.parent = transform; shadowCaster.transform.localPosition = shadowpostion; shadowCaster.transform.localRotation = UnityEngine.Quaternion.identity; shadowCaster.transform.localScale = UnityEngine.Vector3.one; } //if (UnityEngine.Mathf.Abs(UnityEngine.Vector3.Dot(transform.forward, lightDirection)) < .9f){ // proj = transform.forward - UnityEngine.Vector3.Dot(transform.forward, lightDirection) * lightDirection; //} else { // proj = transform.up - UnityEngine.Vector3.Dot(transform.up, lightDirection) * lightDirection; //} //shadowCaster.transform.rotation = UnityEngine.Quaternion.LookRotation(proj, -lightDirection); cornerGOs[0].transform.position = shadowCaster.transform.position + girth * (shadowCaster.transform.forward - shadowCaster.transform.right); cornerGOs[1].transform.position = shadowCaster.transform.position + girth * (shadowCaster.transform.forward + shadowCaster.transform.right); cornerGOs[2].transform.position = shadowCaster.transform.position + girth * (-shadowCaster.transform.forward + shadowCaster.transform.right); cornerGOs[3].transform.position = shadowCaster.transform.position + girth * (-shadowCaster.transform.forward - shadowCaster.transform.right); _girth = girth; } UnityEngine.Transform t = shadowCaster.transform; r.origin = t.position; r.direction = lightDirection; while (count == 0) { if (oldPosition == this.transform.position) { break; } oldPosition.Set(this.transform.position.x, this.transform.position.y, this.transform.position.z); if (maxProjectionDistance > 0f && Physics.Raycast(r, out rh, maxProjectionDistance, layerMask)) { //if (doVisibilityCulling && !isPerspectiveProjection){ // Plane[] camPlanes = FS_ShadowManager.Manager().getCameraFustrumPlanes(); // bounds.center = rh.point; // bounds.size = new UnityEngine.Vector3(2f*girth,2f*girth,2f*girth); // if (!GeometryUtility.TestPlanesAABB(camPlanes,bounds)){ // return; // } //} //// Rotate Shadowcaster ////project forward or up vector onto a plane whos normal is lightDirection //if (UnityEngine.Mathf.Abs(UnityEngine.Vector3.Dot(transform.forward, lightDirection)) < .9f){ // proj = transform.forward - UnityEngine.Vector3.Dot(transform.forward, lightDirection) * lightDirection; //} else { // proj = transform.up - UnityEngine.Vector3.Dot(transform.up, lightDirection) * lightDirection; //} //shadowCaster.transform.rotation = UnityEngine.Quaternion.Lerp(shadowCaster.transform.rotation, UnityEngine.Quaternion.LookRotation(proj, -lightDirection), .01f); //float alpha; //float dist = rh.distance - shadowHoverHeight; //alpha = 1.0f - dist / maxProjectionDistance; //if (alpha < 0f) // return; //alpha = UnityEngine.Mathf.Clamp01(alpha); //_color.a = alpha; //UnityEngine.Profiler.BeginSample("11111111111"); _color.a = 1; _normal = rh.normal; UnityEngine.Vector3 hitPoint = rh.point - shadowHoverHeight * lightDirection; shadowPlane.SetNormalAndPosition(_normal, hitPoint); isGoodPlaneIntersect = true; float rayDist = 0f; //UnityEngine.Profiler.EndSample(); //float mag = 0f; //if (useLightSource && isPerspectiveProjection){ // r.origin = lightSource.transform.position; // UnityEngine.Vector3 lightSource2Corner = cornerGOs[0].transform.position - lightSource.transform.position; // mag = lightSource2Corner.magnitude; // r.direction = lightSource2Corner / mag; // isGoodPlaneIntersect = isGoodPlaneIntersect && shadowPlane.Raycast(r, out rayDist); // _corners[0] = r.origin + r.direction * rayDist; // lightSource2Corner = cornerGOs[1].transform.position - lightSource.transform.position; // r.direction = lightSource2Corner / mag; // isGoodPlaneIntersect = isGoodPlaneIntersect && shadowPlane.Raycast(r, out rayDist); // _corners[1] = r.origin + r.direction * rayDist; // lightSource2Corner = cornerGOs[2].transform.position - lightSource.transform.position; // r.direction = lightSource2Corner / mag; // isGoodPlaneIntersect = isGoodPlaneIntersect && shadowPlane.Raycast(r, out rayDist); // _corners[2] = r.origin + r.direction * rayDist; // lightSource2Corner = cornerGOs[3].transform.position - lightSource.transform.position; // r.direction = lightSource2Corner / mag; // isGoodPlaneIntersect = isGoodPlaneIntersect && shadowPlane.Raycast(r, out rayDist); // _corners[3] = r.origin + r.direction * rayDist; // if (doVisibilityCulling){ // Plane[] camPlanes = FS_ShadowManager.Manager().getCameraFustrumPlanes(); // bounds.center = rh.point; // bounds.size = UnityEngine.Vector3.zero; // bounds.Encapsulate(_corners[0]); // bounds.Encapsulate(_corners[1]); // bounds.Encapsulate(_corners[2]); // bounds.Encapsulate(_corners[3]); // if (!GeometryUtility.TestPlanesAABB(camPlanes,bounds)){ // return; // } // } //} else { //UnityEngine.Profiler.BeginSample("222222"); r.origin = cornerGOs[0].transform.position; isGoodPlaneIntersect = shadowPlane.Raycast(r, out rayDist); if (isGoodPlaneIntersect == false && rayDist == 0f) { return; } else { isGoodPlaneIntersect = true; } _corners[0] = r.origin + r.direction * rayDist; r.origin = cornerGOs[1].transform.position; isGoodPlaneIntersect = shadowPlane.Raycast(r, out rayDist); if (isGoodPlaneIntersect == false && rayDist == 0f) { return; } else { isGoodPlaneIntersect = true; } _corners[1] = r.origin + r.direction * rayDist; r.origin = cornerGOs[2].transform.position; isGoodPlaneIntersect = shadowPlane.Raycast(r, out rayDist); if (isGoodPlaneIntersect == false && rayDist == 0f) { return; } else { isGoodPlaneIntersect = true; } _corners[2] = r.origin + r.direction * rayDist; r.origin = cornerGOs[3].transform.position; isGoodPlaneIntersect = shadowPlane.Raycast(r, out rayDist); if (isGoodPlaneIntersect == false && rayDist == 0f) { return; } else { isGoodPlaneIntersect = true; } _corners[3] = r.origin + r.direction * rayDist; //} //UnityEngine.Profiler.EndSample(); //UnityEngine.Profiler.BeginSample("333"); //if (isGoodPlaneIntersect) //{ // if (meshKey == null || meshKey.mat != shadowMaterial || meshKey.isStatic != isStatic) meshKey = new FS_MeshKey(shadowMaterial, isStatic); // FS_ShadowManager.Manager().registerGeometry(this, meshKey); // gizmoColor = UnityEngine.Color.white; //} //else //{ // gizmoColor = UnityEngine.Color.magenta; //} //UnityEngine.Profiler.EndSample(); } else { isGoodPlaneIntersect = false; gizmoColor = UnityEngine.Color.red; } break; } //count++; //count = count > 1 ? 0 : count; //UnityEngine.Profiler.BeginSample("333"); if (isGoodPlaneIntersect) { if (meshKey == null || meshKey.mat != shadowMaterial || meshKey.isStatic != isStatic) { meshKey = new FS_MeshKey(shadowMaterial, isStatic); } FS_ShadowManager.Manager().registerGeometry(this, meshKey); gizmoColor = UnityEngine.Color.white; } else { gizmoColor = UnityEngine.Color.magenta; } //UnityEngine.Profiler.EndSample(); }
public void SetTest() { Vector3 target = new Vector3(3f, 1f, 28.2f); float newX = 50f; float newY = 20f; float newZ = 49.553f; target.Set(newX, newY, newZ); var expect = new Vector3(newX, newY, newZ); Assert.AreEqual(expect, target); }
private void FixedUpdate() { cam.Yaw = yaw; cam.Height = pitch; var vel = rig.velocity + direction; if (vel.sqrMagnitude > maxSpeed * maxSpeed) { vel = vel.normalized * maxSpeed; } if (jump && !hasJumped) { rig.velocity = vel * 0.5f; rig.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); hasJumped = true; _limitSpeed = Mathf.Clamp(vel.magnitude, 2f, maxSpeed); } else { if (jump) { rig.velocity = Vector3.Lerp(rig.velocity, vel.normalized * (_limitSpeed * .9f), Time.deltaTime * 1.25f); } else { rig.velocity = Vector3.Lerp(rig.velocity, vel, Time.deltaTime * 2); } } if (rig.velocity.y < -.2f) { rig.velocity = Vector3.Lerp(rig.velocity, vel.normalized * (maxSpeed * .2f) + Vector3.up * -fallSpeed, Time.deltaTime); } // Velocity decay in _direction for fast stopping if (direction == Vector3.zero) { var velocity = rig.velocity; vel = new Vector3(velocity.x * .2f, velocity.y, velocity.z * .2f); rig.velocity = Vector3.Lerp(velocity, vel, Time.deltaTime * 3); playerAnime.SetFloat(Move, 0f); } else { var velocity = rig.velocity; facingRot.Set(velocity.x, 0f, velocity.z); playerAnime.SetFloat(Move, rig.velocity.magnitude); } if (facingRot != Vector3.zero) { playerMesh.localRotation = Quaternion.Slerp( playerMesh.localRotation, Quaternion.LookRotation(facingRot), Time.deltaTime * 10); } }
void SetPosition(Transform t, Vector3 p) { if(t) { if(pixelSnap) p.Set(Mathf.Round(p.x*pixelPerUnit)/pixelPerUnit, Mathf.Round(p.y*pixelPerUnit)/pixelPerUnit, Mathf.Round(p.z*pixelPerUnit)/pixelPerUnit); t.localPosition = p; } }
void WhileInRange(Collider other) { GameObject egoGO = transform.parent.gameObject; GameObject parent = other.transform.parent.gameObject; if (parent == egoGO) { return; } if (!(other.gameObject.layer == LayerMask.NameToLayer("GroundTruth")) || !parent.activeInHierarchy) { return; } if (!Detected.ContainsKey(other)) { uint id; string label; float linear_vel; float angular_vel; if (parent.layer == LayerMask.NameToLayer("NPC")) { var npcC = parent.GetComponent <NPCController>(); id = npcC.GTID; label = npcC.NPCType; linear_vel = UnityEngine.Vector3.Dot(npcC.GetVelocity(), parent.transform.forward); angular_vel = -npcC.GetAngularVelocity().y; } else { return; } //Bounding Box Size UnityEngine.Vector3 size = ((BoxCollider)other).size; if (size.magnitude == 0) { return; } // Convert from (Right/Up/Forward) to (Forward/Left/Up) size.Set(size.z, size.x, size.y); //Bounding Box Orientation //var Rot = Quaternion.Euler(parent.transform.rotation.eulerAngles); var rot_euler = parent.transform.rotation.eulerAngles; //90 degree phase shift to match with localization rot_euler.y = 90 - rot_euler.y; var Rot = UnityEngine.Quaternion.Euler(rot_euler); //Bounding Box Position if (MapOrigin == null) { return; } UnityEngine.Vector3 bounding_box_center = parent.transform.TransformPoint(((BoxCollider)other).center); var location = MapOrigin.GetGpsLocation(bounding_box_center /*parent.transform.position*/); Detected.Add(other, new Detected3DObjectAdhoc() { Id = id, Label = label, Score = 1.0f, easting = location.Easting, northing = location.Northing, Rotation = Rot, Scale = size, LinearVelocity = new UnityEngine.Vector3(linear_vel, 0, 0), // Linear velocity in forward direction of objects, in meters/sec AngularVelocity = new UnityEngine.Vector3(0, 0, angular_vel), // Angular velocity around up axis of objects, in radians/sec }); } }
//Create a crater type effect in the landscape //This works best on horizontal land. It will primarily reduce the density of the terrain // except around the edges it will increase it slightly to provide the illusion of terrain being pushed out. private void Crater(Vector3 center, float radius, float modAmt) { Vector3 currentPosition = new Vector3(); for (int i = Mathf.FloorToInt(center.x - radius); i < Mathf.CeilToInt(center.x + radius); i++) { for (int j = Mathf.FloorToInt(center.y - radius); j < Mathf.CeilToInt(center.y + radius); j++) { for (int k = Mathf.FloorToInt(center.z - radius); k < Mathf.CeilToInt(center.z + radius); k++) { currentPosition.Set(i, j, k); float distance = Vector3.Distance(center, currentPosition); if (j < center.y) { if (distance < radius) { ModDensityAt(i, j, k, modAmt * Mathf.Log((distance / radius) + .2f)); } } else { if (distance < radius) { ModDensityAt(i, j, k, modAmt * Mathf.Log((distance / radius))); } } } } } }
void WhileInRange(Collider other) { GameObject egoGO = transform.parent.gameObject; GameObject parent = other.transform.parent.gameObject; if (parent == egoGO) { return; } if (!(other.gameObject.layer == LayerMask.NameToLayer("GroundTruth")) || !parent.activeInHierarchy) { return; } if (!Detected.ContainsKey(other)) { uint id; string label = null; float linear_vel; float angular_vel; float egoPosY = egoGO.GetComponent <VehicleActions>().Bounds.center.y; float score = 0.0f; if (parent.layer == LayerMask.NameToLayer("Agent")) { var egoC = parent.GetComponent <VehicleController>(); var egoA = parent.GetComponent <VehicleActions>(); var rb = parent.GetComponent <Rigidbody>(); id = egoC.GTID; label = "Sedan"; linear_vel = UnityEngine.Vector3.Dot(rb.velocity, parent.transform.forward); angular_vel = -rb.angularVelocity.y; } else if (parent.layer == LayerMask.NameToLayer("NPC")) { var npcC = parent.GetComponent <NPCController>(); id = npcC.GTID; label = npcC.NPCType; linear_vel = UnityEngine.Vector3.Dot(npcC.GetVelocity(), parent.transform.forward); angular_vel = -npcC.GetAngularVelocity().y; } else if (parent.layer == LayerMask.NameToLayer("Pedestrian")) { var pedC = parent.GetComponent <PedestrianController>(); id = pedC.GTID; label = "Pedestrian"; linear_vel = UnityEngine.Vector3.Dot(pedC.CurrentVelocity, parent.transform.forward); angular_vel = -pedC.CurrentAngularVelocity.y; } else { return; } UnityEngine.Vector3 size = ((BoxCollider)other).size; // Convert from (Right/Up/Forward) to (Forward/Left/Up) size.Set(size.z, size.x, size.y); if (size.magnitude == 0) { return; } //Bounding Box Orientation //var Rot = Quaternion.Euler(parent.transform.rotation.eulerAngles); var rot_euler = parent.transform.rotation.eulerAngles; var Rot = UnityEngine.Quaternion.Euler(rot_euler); //Bounding Box Position if (MapOrigin == null) { return; } UnityEngine.Vector3 bounding_box_center = parent.transform.TransformPoint(((BoxCollider)other).center); var location = MapOrigin.GetGpsLocation(bounding_box_center /*parent.transform.position*/); if (!string.IsNullOrEmpty(label)) { score = 1.0f; } Detected.Add(other, new Detected3DObjectPerc() { Id = id, Label = label, Score = score, easting = location.Easting, northing = location.Northing, Rotation = Rot, Scale = size, LinearVelocity = new UnityEngine.Vector3(linear_vel, 0, 0), // Linear velocity in forward direction of objects, in meters/sec AngularVelocity = new UnityEngine.Vector3(0, 0, angular_vel), // Angular velocity around up axis of objects, in radians/sec }); } }
//Gradually makes terrain flat. Uses the height of the center as the divide between ground and air. private void MakeFlat(Vector3 center, float radius, float modAmt) { Vector3 currentPosition = new Vector3(); for (int i = Mathf.FloorToInt(center.x - radius); i < Mathf.CeilToInt(center.x + radius); i++) { for (int j = Mathf.FloorToInt(center.y - radius); j < Mathf.CeilToInt(center.y + radius); j++) { for (int k = Mathf.FloorToInt(center.z - radius); k < Mathf.CeilToInt(center.z + radius); k++) { currentPosition.Set(i, j, k); //Everything above the center loses density //Everything below gains density if (j < center.y) { ModDensityAt(i, j, k, .01f); } else { ModDensityAt(i, j, k, -.01f); } } } } }
//-------------------------------------------------------------------------------------------------------------------- // for Finger. public static bool _LimitFingerNotThumb( bool isRight, ref Vector3 dir, // dirX ref FastAngle limitYPlus, ref FastAngle limitYMinus, ref FastAngle limitZ ) { bool isLimited = false; // Yaw if( limitZ.cos > IKEpsilon ) { // Memo: Unstable when dir.z near 1. if( dir.z < -limitZ.sin || dir.z > limitZ.sin ) { isLimited = true; bool isPlus = (dir.z >= 0.0f); float lenXY = SAFBIKSqrt( dir.x * dir.x + dir.y * dir.y ); if( limitZ.sin <= IKEpsilon ) { // Optimized. if( lenXY > IKEpsilon ) { dir.z = 0.0f; dir = dir * (1.0f / lenXY); } else { // Failsafe. dir.Set( isRight ? limitZ.cos : -limitZ.cos, 0.0f, isPlus ? limitZ.sin : -limitZ.sin ); } } else { float lenZ = limitZ.sin * lenXY / limitZ.cos; dir.z = isPlus ? lenZ : -lenZ; float len = dir.magnitude; if( len > IKEpsilon ) { dir *= (1.0f / len); } else { // Failsafe. dir.Set( isRight ? limitZ.cos : -limitZ.cos, 0.0f, isPlus ? limitZ.sin : -limitZ.sin ); } } } } // Pitch { // Memo: Not use z.( For yaw limit. ) bool isPlus = (dir.y >= 0.0f); float cosPitchLimit = isPlus ? limitYPlus.cos : limitYMinus.cos; if( (isRight && dir.x < cosPitchLimit) || (!isRight && dir.x > -cosPitchLimit) ) { float lenY = SAFBIKSqrt( 1.0f - (cosPitchLimit * cosPitchLimit + dir.z * dir.z) ); dir.x = (isRight ? cosPitchLimit : -cosPitchLimit); dir.y = (isPlus ? lenY : -lenY); } } return isLimited; }
//A generic function for modifying the density of the terrain within a radius private void ModifyDensityFunction(Vector3 center, float radius, float modAmt) { Vector3 currentPosition = new Vector3(); ///ModDensityAt(Mathf.FloorToInt(center.x), Mathf.FloorToInt(center.y), Mathf.FloorToInt(center.z), modAmt); for (int i = Mathf.FloorToInt(center.x - radius); i < Mathf.CeilToInt(center.x + radius); i++) { for (int j = Mathf.FloorToInt(center.y - radius); j < Mathf.CeilToInt(center.y + radius); j++) { for (int k = Mathf.FloorToInt(center.z - radius); k < Mathf.CeilToInt(center.z + radius); k++) { currentPosition.Set(i, j, k); var distance = Vector3.Distance(center, currentPosition); if (distance <= radius) { ModDensityAt(i, j, k, modAmt); } } } } }