Skip to content
Snippets Groups Projects
Commit f70a78c8 authored by BlackAngle233's avatar BlackAngle233
Browse files

2021.5.10

parent af571a61
No related merge requests found
Showing
with 806 additions and 686 deletions
This diff is collapsed.
This diff is collapsed.
......@@ -35,40 +35,58 @@ public class Constraint
Object2 = obj2;
constraintType = type;
Line l1 = null;
Line l2 = null;
float length = 0;
switch (type)
{
case ConstraintType.LineLength:
Line l = (Line)obj1;
float length = (float)obj2;
l1 = (Line)obj1;
length = (float)obj2;
l.setConstraint(this);
name = l.name + "=" + length.ToString();
l1.setConstraint(this);
name = l1.name + "=" + length.ToString();
break;
case ConstraintType.LineEqual:
Line l1 = (Line)obj1;
Line l2 = (Line)obj2;
l1 = (Line)obj1;
l2 = (Line)obj2;
l1.setConstraint(this);
l2.setConstraint(this);
name = l1.name + "=" + l2.name;
break;
case ConstraintType.LineNormal:
l1 = (Line)obj1;
l2 = (Line)obj2;
l1.setConstraint(this);
l2.setConstraint(this);
name = l1.name + "⊥" + l2.name;
break;
}
}
public float getConstraintValue()
{
float result = 0;
Line l1 = null;
Line l2 = null;
float length = 0;
switch (constraintType)
{
case ConstraintType.LineLength:
Line l = (Line)Object1;
float length = (float)Object2;
l1 = (Line)Object1;
length = (float)Object2;
result = l.getLength() - length;
result = l1.getLength() - length;
break;
case ConstraintType.LineEqual:
Line l1 = (Line)Object1;
Line l2 = (Line)Object2;
l1 = (Line)Object1;
l2 = (Line)Object2;
if (l1.lineState > l2.lineState)
{
......@@ -79,6 +97,12 @@ public class Constraint
result = l2.getLength() - l1.getLength();
}
break;
case ConstraintType.LineNormal:
l1 = (Line)Object1;
l2 = (Line)Object2;
result = Vector3.Dot(l1.direction, l2.direction);
break;
}
return result;
......@@ -86,16 +110,21 @@ public class Constraint
public Gradient getGradient()
{
Line l1 = null;
Line l2 = null;
float length = 0;
switch (constraintType)
{
case ConstraintType.LineLength:
Line l = (Line)Object1;
float length = (float)Object2;
l1 = (Line)Object1;
length = (float)Object2;
return l.getGradient();
return l1.getGradient();
case ConstraintType.LineEqual:
Line l1 = (Line)Object1;
Line l2 = (Line)Object2;
l1 = (Line)Object1;
l2 = (Line)Object2;
if(l1.lineState > l2.lineState)
{
return l1.getGradient();
......@@ -104,6 +133,17 @@ public class Constraint
{
return l2.getGradient();
}
case ConstraintType.LineNormal:
l1 = (Line)Object1;
l2 = (Line)Object2;
if(l1.lineState > l2.lineState)
{
return new Gradient(l2.getUnknownPoint() ,l1.direction);
}
else
{
return new Gradient(l1.getUnknownPoint() ,l2.direction);
}
}
return null;
}
......@@ -120,17 +160,23 @@ public class Constraint
public void checkState()
{
Line l1 = null;
Line l2 = null;
float length = 0;
switch (constraintType)
{
case ConstraintType.LineLength:
Line l = (Line)Object1;
float length = (float)Object2;
l1 = (Line)Object1;
length = (float)Object2;
setState(l.lineState);
setState(l1.lineState);
break;
case ConstraintType.LineEqual:
Line l1 = (Line)Object1;
Line l2 = (Line)Object2;
case ConstraintType.LineNormal:
l1 = (Line)Object1;
l2 = (Line)Object2;
if(l1.lineState == State.confirm && l2.lineState == State.confirm)
{
......@@ -150,25 +196,33 @@ public class Constraint
public void calculateConstraint(Point target)
{
Vector3 normal;
Vector3 direction;
Point tmp;
Line l1 = null;
Line l2 = null;
float length = 0;
float cos = 0;
float sin = 0;
switch (constraintType)
{
case ConstraintType.LineLength:
Line l = (Line)Object1;
float length = (float)Object2;
l1 = (Line)Object1;
length = (float)Object2;
tmp = l.getAnotherPoint(target);
tmp = l1.getAnotherPoint(target);
direction = l.getDirection(target);
direction = l1.getDirection(target);
target.setPoint(tmp.add(direction * length));
target.setState(State.confirm);
break;
case ConstraintType.LineEqual:
Line l1 = (Line)Object1;
Line l2 = (Line)Object2;
l1 = (Line)Object1;
l2 = (Line)Object2;
if(l1.lineState == State.confirm)
{
......@@ -185,6 +239,41 @@ public class Constraint
target.setPoint(tmp.add(direction * l2.getLength()));
}
target.setState(State.confirm);
break;
case ConstraintType.LineNormal:
l1 = (Line)Object1;
l2 = (Line)Object2;
if(l1.lineState == State.confirm)
{
normal = l1.direction.normalized;
tmp = l2.getAnotherPoint(target);
direction = new Vector3(target.x - tmp.x, target.y - tmp.y, target.z - tmp.z);
sin = Vector3.Dot(l1.getVector3(), l2.getVector3()) / l1.getLength() / l2.getLength();
cos = Mathf.Sqrt(1 - cos * cos);
direction = direction * cos + Vector3.Cross(normal, direction) * sin + normal * Vector3.Dot(normal, direction) * (1 - cos);
target.setPoint(direction.x - tmp.x, direction.y - tmp.y, direction.z - tmp.z);
}
else if(l2.lineState == State.confirm)
{
normal = l2.direction.normalized;
tmp = l1.getAnotherPoint(target);
direction = new Vector3(target.x - tmp.x, target.y - tmp.y, target.z - tmp.z);
sin = Vector3.Dot(l2.getVector3(), l1.getVector3()) / l2.getLength() / l1.getLength();
cos = Mathf.Sqrt(1 - cos * cos);
direction = direction * cos + Vector3.Cross(normal, direction) * sin + normal * Vector3.Dot(normal, direction) * (1 - cos);
target.setPoint(direction.x - tmp.x, direction.y - tmp.y, direction.z - tmp.z);
}
target.setState(State.confirm);
break;
}
......@@ -195,11 +284,16 @@ public class Constraint
Gradient tmp;
float value = 0;
Line l1 = null;
Line l2 = null;
float length = 0;
switch (constraintType)
{
case ConstraintType.LineLength:
Line l = (Line)Object1;
float length = (float)Object2;
l1 = (Line)Object1;
length = (float)Object2;
tmp = getGradient();
value = getConstraintValue();
......@@ -208,8 +302,8 @@ public class Constraint
break;
case ConstraintType.LineEqual:
Line l1 = (Line)Object1;
Line l2 = (Line)Object2;
l1 = (Line)Object1;
l2 = (Line)Object2;
tmp = getGradient();
value = getConstraintValue();
......@@ -217,6 +311,17 @@ public class Constraint
target += tmp.calculateGradient(value);
break;
case ConstraintType.LineNormal:
l1 = (Line)Object1;
l2 = (Line)Object2;
tmp = getGradient();
value = getConstraintValue();
target += tmp.calculateGradient(value);
break;
}
}
}
......@@ -58,6 +58,12 @@ public class Line
return null;
}
public Point getUnknownPoint(){
if(point2.getState() > point1.getState())
return point2;
return point1;
}
public Gradient getGradient()
{
if(point2.getState() > point1.getState())
......@@ -78,4 +84,8 @@ public class Line
point2.constraints.Add(c);
}
public Vector3 getVector3(){
return new Vector3(point1.x - point2.x, point1.y - point2.y, point1.z - point2.z);
}
}
......@@ -30,7 +30,8 @@ public class UIManager : MonoBehaviour
none,
createLine,
linelength,
lineEqual
lineEqual,
lineNormal
}
UIState state = UIState.none;
......@@ -68,6 +69,12 @@ public class UIManager : MonoBehaviour
createConstraint();
}
break;
case UIState.lineNormal:
if (!chosen1.Equals("") && !chosen2.Equals(""))
{
createConstraint();
}
break;
}
}
......@@ -103,13 +110,13 @@ public class UIManager : MonoBehaviour
public void chooseObject(string obj)
{
if(state != UIState.none)
{
if(state != UIState.none)
{
if (chosen1.Equals(""))
chosen1 = obj;
if (!chosen1.Equals("") && !chosen1.Equals(obj) && chosen2.Equals(""))
chosen2 = obj;
Debug.Log(obj);
chosen2 = obj;
Debug.Log(obj);
}
}
......@@ -122,43 +129,57 @@ public class UIManager : MonoBehaviour
}
}
public void createConstraintButton()
{
constraintDropdown.SetActive(true);
public void createConstraintButton()
{
constraintDropdown.SetActive(true);
}
public void constraintDropdownChange()
{
string text = constraintDropdown.GetComponent<Dropdown>().captionText.text;
ConstraintType type = (ConstraintType)System.Enum.Parse(typeof(ConstraintType), text);
switch (type)
{
case ConstraintType.LineLength:
state = UIState.linelength;
constraintInput.SetActive(true);
break;
case ConstraintType.LineEqual:
state = UIState.lineEqual;
break;
}
public void constraintDropdownChange()
{
string text = constraintDropdown.GetComponent<Dropdown>().captionText.text;
ConstraintType type = (ConstraintType)System.Enum.Parse(typeof(ConstraintType), text);
switch (type)
{
case ConstraintType.LineLength:
state = UIState.linelength;
constraintInput.SetActive(true);
break;
case ConstraintType.LineEqual:
state = UIState.lineEqual;
break;
case ConstraintType.LineNormal:
state = UIState.lineNormal;
break;
}
}
void createConstraint()
{
string n = "";
switch (state)
{
case UIState.linelength:
Line l = CM.GetLine(chosen1);
float length = float.Parse(constraintInput.GetComponent<InputField>().text);
n = CM.createConstraint(l, length, ConstraintType.LineLength);
constraintInput.SetActive(false);
break;
case UIState.lineEqual:
Line l1 = CM.GetLine(chosen1);
Line l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineEqual);
break;
void createConstraint()
{
Line l1 = null;
Line l2 = null;
float length;
string n = "";
switch (state)
{
case UIState.linelength:
l1 = CM.GetLine(chosen1);
length = float.Parse(constraintInput.GetComponent<InputField>().text);
n = CM.createConstraint(l1, length, ConstraintType.LineLength);
constraintInput.SetActive(false);
break;
case UIState.lineEqual:
l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineEqual);
break;
case UIState.lineNormal:
l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineNormal);
break;
}
chosen1 = "";
chosen2 = "";
......@@ -167,8 +188,8 @@ public class UIManager : MonoBehaviour
constraints.Add(tmp);
tmp.transform.localPosition = new Vector3(100 + 70 * (constraints.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n;
state = UIState.none;
constraintDropdown.GetComponent<Dropdown>().captionText.text = "None";
constraintDropdown.SetActive(false);
state = UIState.none;
constraintDropdown.GetComponent<Dropdown>().captionText.text = "None";
constraintDropdown.SetActive(false);
}
}
No preview for this file type
No preview for this file type
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment