convert VB to C#

This commit is contained in:
2020-09-24 11:21:53 +02:00
parent 64277916cd
commit fecbeb4659
320 changed files with 17755 additions and 10320 deletions

View File

@@ -0,0 +1,744 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using global::System.Windows.Forms;
using global::OpenTK;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
{
public class Camera
{
public event NeedSelectedObjectEventHandler NeedSelectedObject;
public delegate void NeedSelectedObjectEventHandler(object sender, NeedSelectedObjectEventArgs e);
public event PerspectiveChangedEventHandler PerspectiveChanged;
public delegate void PerspectiveChangedEventHandler(object sender, EventArgs e);
// P R I V A T E F I E L D S
private readonly float TAU = (float)(Math.PI * 2d);
private CameraMode myCamMode = CameraMode.FLY;
private Vector3 pos = new Vector3(-5000.0f, 3000.0f, 4000.0f);
private Vector3 myLookat = new Vector3(0f, 0f, 0f);
private Vector3 myFarPoint = new Vector3(0f, 0f, 0f);
private Vector3 myNearPoint = new Vector3(0f, 0f, 0f);
private int lastMouseX = -1;
private int lastMouseY = -1;
private float CamAngleX = 0f;
private float CamAngleY = (float)-(Math.PI / 2d);
private bool resetMouse = true;
private float orbitDistance = 500.0f;
private float orbitTheta = 0.0f;
private float orbitPhi = 0.0f;
private LookDirection currentLookDirection;
private Vector3[] lookPositions = new Vector3[] { new Vector3(0f, 12500f, 0f), new Vector3(0f, -12500, 0f), new Vector3(-12500, 0f, 0f), new Vector3(12500f, 0f, 0f), new Vector3(0f, 0f, 12500f), new Vector3(0f, 0f, -12500) };
// A U T O M A T I C P R O P E R T I E S
public float CamSpeedMultiplier { get; set; } = 1f;
// P R O P E R T I E S
public CameraMode CamMode
{
get
{
return myCamMode;
}
}
public float Yaw
{
get
{
return CamAngleX;
}
}
public float Pitch
{
get
{
return CamAngleY;
}
}
public float Yaw_Degrees
{
get
{
return CamAngleX * (180.0f / 3.14159274f);
}
}
public float Pitch_Degrees
{
get
{
return CamAngleY * (180.0f / 3.14159274f);
}
}
public Vector3 Position
{
get
{
return pos;
}
set
{
pos = value;
}
}
public Vector3 LookAt
{
get
{
return myLookat;
}
set
{
myLookat = value;
}
}
public Vector3 NearPoint
{
get
{
return myNearPoint;
}
set
{
myNearPoint = value;
}
}
public Vector3 FarPoint
{
get
{
return myFarPoint;
}
set
{
myFarPoint = value;
}
}
// C O N S T R U C T O R
public Camera()
{
SetRotationFromLookAt();
}
// F E A T U R E S
private float Clampf(float value, float min, float max)
{
return value > max ? max : value < min ? min : value;
}
private void OrientateCam(float ang, float ang2)
{
float CamLX = (float)Math.Sin(ang) * (float)Math.Sin(-ang2);
float CamLY = (float)Math.Cos(ang2);
float CamLZ = (float)-Math.Cos(ang) * (float)Math.Sin(-ang2);
myLookat.X = pos.X + -CamLX * 100.0f;
myLookat.Y = pos.Y + -CamLY * 100.0f;
myLookat.Z = pos.Z + -CamLZ * 100.0f;
}
private void OffsetCam(int xAmt, int yAmt, int zAmt)
{
double pitch_Renamed = CamAngleY - Math.PI / 2d;
float CamLX = (float)Math.Sin(CamAngleX) * (float)Math.Cos(-pitch_Renamed);
float CamLY = (float)Math.Sin(pitch_Renamed);
float CamLZ = (float)-Math.Cos(CamAngleX) * (float)Math.Cos(-pitch_Renamed);
pos.X = pos.X + xAmt * CamLX * CamSpeedMultiplier;
pos.Y = pos.Y + yAmt * CamLY * CamSpeedMultiplier;
pos.Z = pos.Z + zAmt * CamLZ * CamSpeedMultiplier;
}
public void Move(float y, ref Matrix4 camMtx)
{
OffsetCam(0, (int)y, 0);
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref camMtx);
}
public void Move(float x, float z, ref Matrix4 camMtx)
{
UpdateCameraOffsetDirectly((int)x, (int)z, ref camMtx);
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref camMtx);
}
public void SetRotationFromLookAt()
{
float x_diff = myLookat.X - pos.X;
float y_diff = myLookat.Y - pos.Y;
float z_diff = myLookat.Z - pos.Z;
float dist = (float)Math.Sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff);
if (z_diff == 0f)
{
z_diff = 0.001f;
}
float nxz_ratio = -x_diff / z_diff;
if (z_diff < 0f)
{
CamAngleX = (float)(Math.Atan(nxz_ratio) + Math.PI);
}
else
{
CamAngleX = (float)Math.Atan(nxz_ratio);
}
CamAngleY = -3.1459f - ((float)Math.Asin(y_diff / dist) - 1.57f);
}
public void ResetOrbitToSelectedObject()
{
var objs = GetSelectedObject();
if (objs?.Length > 0 == true)
{
orbitTheta = -(CalculateCenterYRotationOfObjects(objs) * ((float)Math.PI / 180.0f));
orbitPhi = -0.3f;
orbitDistance = 1200.0f;
}
}
public void UpdateOrbitCamera(ref Matrix4 cameraMatrix)
{
if (myCamMode == CameraMode.ORBIT)
{
var objs = GetSelectedObject();
if (objs?.Length > 0 == true)
{
var centerPos = CalculateCenterPositionOfObjects(objs);
pos.X = centerPos.X + (float)(Math.Cos(orbitPhi) * -Math.Sin(orbitTheta) * orbitDistance);
pos.Y = centerPos.Y + (float)(-Math.Sin(orbitPhi) * orbitDistance);
pos.Z = centerPos.Z + (float)(Math.Cos(orbitPhi) * Math.Cos(orbitTheta) * orbitDistance);
myLookat.X = centerPos.X;
myLookat.Y = centerPos.Y;
myLookat.Z = centerPos.Z;
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
}
}
}
public bool IsOrbitCamera()
{
return myCamMode == CameraMode.ORBIT;
}
public void SetCameraMode(CameraMode mode, ref Matrix4 cameraMatrix)
{
myCamMode = mode;
if (IsOrbitCamera())
{
ResetOrbitToSelectedObject();
UpdateOrbitCamera(ref cameraMatrix);
}
}
public void SetCameraMode_LookDirection(LookDirection dir, ref Matrix4 cameraMatrix)
{
myCamMode = CameraMode.LOOK_DIRECTION;
currentLookDirection = dir;
switch (currentLookDirection)
{
case LookDirection.Top:
{
pos = lookPositions[(int)LookDirection.Top];
myLookat = new Vector3(pos.X, -25000, pos.Z - 1f);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
case LookDirection.Bottom:
{
pos = lookPositions[(int)LookDirection.Bottom];
myLookat = new Vector3(pos.X, 25000f, pos.Z + 1f);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
case LookDirection.Left:
{
pos = lookPositions[(int)LookDirection.Left];
myLookat = new Vector3(25000f, pos.Y, pos.Z);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
case LookDirection.Right:
{
pos = lookPositions[(int)LookDirection.Right];
myLookat = new Vector3(-25000, pos.Y, pos.Z);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
case LookDirection.Front:
{
pos = lookPositions[(int)LookDirection.Front];
myLookat = new Vector3(pos.X, pos.Y, -25000);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
case LookDirection.Back:
{
pos = lookPositions[(int)LookDirection.Back];
myLookat = new Vector3(pos.X, pos.Y, 25000f);
UpdateMatrix(ref cameraMatrix);
SetRotationFromLookAt();
break;
}
}
}
public void UpdateCameraMatrixWithMouse(int mouseX, int mouseY, ref Matrix4 cameraMatrix)
{
if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object)
{
UpdateCameraMatrixWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix);
}
else if (myCamMode == CameraMode.LOOK_DIRECTION)
{
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, ref cameraMatrix);
}
else
{
UpdateCameraMatrixWithMouse_FLY(mouseX, mouseY, ref cameraMatrix);
}
}
public void UpdateCameraOffsetWithMouse(Vector3 orgPos, int mouseX, int mouseY, int w, int h, ref Matrix4 cameraMatrix)
{
if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object)
{
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix);
}
else if (myCamMode == CameraMode.LOOK_DIRECTION)
{
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, ref cameraMatrix);
}
else
{
UpdateCameraOffsetWithMouse_FLY(orgPos, mouseX, mouseY, w, h, ref cameraMatrix);
}
}
public void UpdateCameraMatrixWithScrollWheel(int amt, ref Matrix4 cameraMatrix)
{
if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object)
{
UpdateCameraMatrixWithScrollWheel_ORBIT(amt, ref cameraMatrix);
}
else if (myCamMode == CameraMode.LOOK_DIRECTION)
{
UpdateCameraMatrixWithScrollWheel_LOOK(amt, ref cameraMatrix);
}
else
{
UpdateCameraMatrixWithScrollWheel_FLY(amt, ref cameraMatrix);
}
}
private void UpdateCameraMatrixWithScrollWheel_FLY(int amt, ref Matrix4 cameraMatrix)
{
OffsetCam(amt, amt, amt);
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref cameraMatrix);
}
public void RaisePerspectiveChanged()
{
PerspectiveChanged?.Invoke(this, new EventArgs());
}
public void UpdateMatrix(ref Matrix4 cameraMatrix)
{
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z, 0f, 1f, 0f);
RaisePerspectiveChanged();
}
private void UpdateCameraMatrixWithScrollWheel_LOOK(int amt, ref Matrix4 cameraMatrix)
{
OffsetCam(amt, amt, amt);
OrientateCam(CamAngleX, CamAngleY);
switch (currentLookDirection)
{
case LookDirection.Top:
{
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z - 1f, 0f, 1f, 0f);
RaisePerspectiveChanged();
break;
}
case LookDirection.Bottom:
{
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1f, 0f, 1f, 0f);
RaisePerspectiveChanged();
break;
}
default:
{
UpdateMatrix(ref cameraMatrix);
break;
}
}
}
private void UpdateCameraMatrixWithMouse_LOOK(Vector3 orgPos, int mouseX, int mouseY, ref Matrix4 cameraMatrix)
{
if (resetMouse)
{
lastMouseX = mouseX;
lastMouseY = mouseY;
resetMouse = false;
}
int MousePosX = mouseX - lastMouseX;
int MousePosY = mouseY - lastMouseY;
double pitch_Renamed = CamAngleY - Math.PI / 2d;
double yaw_Renamed = CamAngleX - Math.PI / 2d;
float CamLX = (float)Math.Sin(yaw_Renamed);
float CamLY = (float)Math.Cos(pitch_Renamed);
float CamLZ = (float)-Math.Cos(yaw_Renamed);
float m = 8.0f;
switch (currentLookDirection)
{
case LookDirection.Top:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m - MousePosY * CamSpeedMultiplier * CamLZ * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m - MousePosY * CamSpeedMultiplier * CamLX * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y - 1000f, pos.Z - 1f, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
case LookDirection.Bottom:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m + MousePosY * CamSpeedMultiplier * CamLZ * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m + MousePosY * CamSpeedMultiplier * CamLX * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y + 1000f, pos.Z + 1f, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
case LookDirection.Left:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m;
pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X + 12500f, pos.Y, pos.Z, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
case LookDirection.Right:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m;
pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X - 12500f, pos.Y, pos.Z, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
case LookDirection.Front:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m;
pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z - 12500f, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
case LookDirection.Back:
{
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m;
pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m;
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z + 12500f, 0f, 1f, 0f);
lookPositions[(int)currentLookDirection] = pos;
break;
}
}
RaisePerspectiveChanged();
lastMouseX = mouseX;
lastMouseY = mouseY;
// Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
// setRotationFromLookAt();
}
private void UpdateCameraMatrixWithMouse_FLY(int mouseX, int mouseY, ref Matrix4 cameraMatrix)
{
if (resetMouse)
{
lastMouseX = mouseX;
lastMouseY = mouseY;
resetMouse = false;
}
int MousePosX = mouseX - lastMouseX;
int MousePosY = mouseY - lastMouseY;
CamAngleX = CamAngleX + 0.01f * MousePosX;
// This next part isn't neccessary, but it keeps the Yaw rotation value within [0, 2*pi] which makes debugging simpler.
if (CamAngleX > TAU)
{
CamAngleX -= TAU;
}
else if (CamAngleX < 0f)
{
CamAngleX += TAU;
}
// Lock pitch rotation within the bounds of [-3.1399.0, -0.0001], otherwise the LookAt function will snap to the
// opposite side and reverse mouse looking controls.
CamAngleY = Clampf(CamAngleY + 0.01f * MousePosY, -3.1399f, -0.0001f);
lastMouseX = mouseX;
lastMouseY = mouseY;
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref cameraMatrix);
// Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
// setRotationFromLookAt();
}
private void UpdateCameraOffsetWithMouse_FLY(Vector3 orgPos, int mouseX, int mouseY, int w, int h, ref Matrix4 cameraMatrix)
{
if (resetMouse)
{
lastMouseX = mouseX;
lastMouseY = mouseY;
resetMouse = false;
}
int MousePosX = -mouseX + lastMouseX;
int MousePosY = -mouseY + lastMouseY;
double pitch_Renamed = CamAngleY - Math.PI / 2d;
double yaw_Renamed = CamAngleX - Math.PI / 2d;
float CamLX = (float)Math.Sin(yaw_Renamed);
float CamLZ = (float)-Math.Cos(yaw_Renamed);
pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * 6.0f;
pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * 6.0f;
pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * 6.0f;
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref cameraMatrix);
}
public void UpdateCameraOffsetDirectly(int horz_amount, int vert_amount, ref Matrix4 cameraMatrix)
{
if (myCamMode == CameraMode.ORBIT)
{
UpdateCameraOffsetDirectly_ORBIT((int)(horz_amount / 5d), (int)(vert_amount / 5d), ref cameraMatrix);
}
else
{
// Console.WriteLine(MousePosX+","+ MousePosY);
double pitch_Renamed = CamAngleY - Math.PI / 2d;
double yaw_Renamed = CamAngleX - Math.PI / 2d;
float CamLX = (float)Math.Sin(yaw_Renamed);
// float CamLY = (float)Math.Cos(pitch);
float CamLZ = (float)-Math.Cos(yaw_Renamed);
pos.X += horz_amount * CamSpeedMultiplier * CamLX;
pos.Y += vert_amount * CamSpeedMultiplier * -1.0f;
pos.Z += horz_amount * CamSpeedMultiplier * CamLZ;
OrientateCam(CamAngleX, CamAngleY);
UpdateMatrix(ref cameraMatrix);
}
}
private void UpdateCameraOffsetDirectly_ORBIT(int moveSpeedX, int moveSpeedY, ref Matrix4 cameraMatrix)
{
int MousePosX = moveSpeedX;
int MousePosY = moveSpeedY;
orbitTheta += MousePosX * 0.01f * CamSpeedMultiplier;
orbitPhi -= MousePosY * 0.01f * CamSpeedMultiplier;
orbitPhi = Clampf(orbitPhi, -1.57f, 1.57f);
UpdateOrbitCamera(ref cameraMatrix);
}
private void UpdateCameraMatrixWithMouse_ORBIT(int mouseX, int mouseY, ref Matrix4 cameraMatrix)
{
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix);
}
private void UpdateCameraOffsetWithMouse_ORBIT(int mouseX, int mouseY, ref Matrix4 cameraMatrix)
{
if (resetMouse)
{
lastMouseX = mouseX;
lastMouseY = mouseY;
resetMouse = false;
}
int MousePosX = -mouseX + lastMouseX;
int MousePosY = -mouseY + lastMouseY;
orbitTheta += MousePosX * 0.01f * CamSpeedMultiplier;
orbitPhi -= MousePosY * 0.01f * CamSpeedMultiplier;
orbitPhi = Clampf(orbitPhi, -1.57f, 1.57f);
UpdateOrbitCamera(ref cameraMatrix);
lastMouseX = mouseX;
lastMouseY = mouseY;
}
private void UpdateCameraMatrixWithScrollWheel_ORBIT(int amt, ref Matrix4 cameraMatrix)
{
orbitDistance -= amt;
if (orbitDistance < 300.0f)
{
orbitDistance = 300.0f;
}
UpdateOrbitCamera(ref cameraMatrix);
}
public void ResetMouseStuff()
{
resetMouse = true;
}
private System.Numerics.Vector3 CalculateCenterPositionOfObjects(ICameraPoint[] objs)
{
if (objs.Length <= 1)
{
var obj = objs.FirstOrDefault();
if (obj is null)
{
return System.Numerics.Vector3.Zero;
}
else
{
return new System.Numerics.Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z);
}
}
float? maxX = default;
float? maxY = default;
float? maxZ = default;
float? minX = default;
float? minY = default;
float? minZ = default;
foreach (ICameraPoint obj in objs)
{
var pos = obj.Position;
if (maxX is null || pos.X > maxX)
maxX = pos.X;
if (maxY is null || pos.Y > maxY)
maxY = pos.Y;
if (maxZ is null || pos.Z > maxZ)
maxZ = pos.Z;
if (minX is null || pos.X < minX)
minX = pos.X;
if (minY is null || pos.Y < minY)
minY = pos.Y;
if (minZ is null || pos.Z < minZ)
minZ = pos.Z;
}
if (maxX is null)
maxX = 0;
if (maxY is null)
maxY = 0;
if (maxZ is null)
maxZ = 0;
if (minX is null)
minX = 0;
if (minY is null)
minY = 0;
if (minZ is null)
minZ = 0;
var upper = new System.Numerics.Vector3((float)maxX, (float)maxY, (float)maxZ);
var lower = new System.Numerics.Vector3((float)minX, (float)minY, (float)minZ);
var middle = (upper + lower) / 2f;
return middle;
}
private float CalculateCenterYRotationOfObjects(ICameraPoint[] objs)
{
if (objs.Length <= 1)
{
var obj = objs.FirstOrDefault();
if (obj is null)
{
return 0f;
}
else
{
return obj.Rotation.Y;
}
}
var yRot = new List<float>();
foreach (ICameraPoint obj in objs)
yRot.Add(obj.Rotation.Y);
return yRot.Average();
}
private ICameraPoint[] GetSelectedObject()
{
var e = new NeedSelectedObjectEventArgs();
NeedSelectedObject?.Invoke(this, e);
var stopw = new Stopwatch();
stopw.Start();
while (!e.HasObjectSetted && stopw.ElapsedMilliseconds <= 1000L)
Application.DoEvents();
stopw.Stop();
return e.Points;
}
// C A P S E L T C L A S S E S
public class NeedSelectedObjectEventArgs : EventArgs
{
private bool _HasObjectSetted = false;
public bool HasObjectSetted
{
get
{
return _HasObjectSetted;
}
}
private ICameraPoint[] _Points = null;
public ICameraPoint[] Points
{
get
{
return _Points;
}
set
{
_Points = value;
_HasObjectSetted = true;
}
}
}
}
}

View File

@@ -1,580 +0,0 @@
Imports System.Windows.Forms
Imports OpenTK
Namespace CameraN
Public Class Camera
Public Event NeedSelectedObject(sender As Object, e As NeedSelectedObjectEventArgs)
Public Event PerspectiveChanged(sender As Object, e As EventArgs)
'P R I V A T E F I E L D S
Private ReadOnly TAU As Single = Math.PI * 2
Private myCamMode As CameraMode = CameraMode.FLY
Private pos As New Vector3(-5000.0F, 3000.0F, 4000.0F)
Private myLookat As New Vector3(0F, 0F, 0F)
Private myFarPoint As New Vector3(0F, 0F, 0F)
Private myNearPoint As New Vector3(0F, 0F, 0F)
Private lastMouseX As Integer = -1, lastMouseY As Integer = -1
Private CamAngleX As Single = 0F, CamAngleY As Single = -(Math.PI / 2)
Private resetMouse As Boolean = True
Private orbitDistance As Single = 500.0F
Private orbitTheta As Single = 0.0F, orbitPhi As Single = 0.0F
Private currentLookDirection As LookDirection
Private lookPositions() As Vector3 = {
New Vector3(0, 12500, 0),
New Vector3(0, -12500, 0),
New Vector3(-12500, 0, 0),
New Vector3(12500, 0, 0),
New Vector3(0, 0, 12500),
New Vector3(0, 0, -12500)
}
'A U T O M A T I C P R O P E R T I E S
Public Property CamSpeedMultiplier As Single = 1
'P R O P E R T I E S
Public ReadOnly Property CamMode As CameraMode
Get
Return myCamMode
End Get
End Property
Public ReadOnly Property Yaw As Single
Get
Return CamAngleX
End Get
End Property
Public ReadOnly Property Pitch As Single
Get
Return CamAngleY
End Get
End Property
Public ReadOnly Property Yaw_Degrees As Single
Get
Return CamAngleX * (180.0F / 3.14159274F)
End Get
End Property
Public ReadOnly Property Pitch_Degrees As Single
Get
Return CamAngleY * (180.0F / 3.14159274F)
End Get
End Property
Public Property Position As Vector3
Get
Return pos
End Get
Set(value As Vector3)
pos = value
End Set
End Property
Public Property LookAt As Vector3
Get
Return myLookat
End Get
Set(value As Vector3)
myLookat = value
End Set
End Property
Public Property NearPoint As Vector3
Get
Return myNearPoint
End Get
Set(value As Vector3)
myNearPoint = value
End Set
End Property
Public Property FarPoint As Vector3
Get
Return myFarPoint
End Get
Set(value As Vector3)
myFarPoint = value
End Set
End Property
'C O N S T R U C T O R
Public Sub New()
SetRotationFromLookAt()
End Sub
'F E A T U R E S
Private Function Clampf(value As Single, min As Single, max As Single) As Single
Return If(value > max, max, If(value < min, min, value))
End Function
Private Sub OrientateCam(ang As Single, ang2 As Single)
Dim CamLX As Single = CSng(Math.Sin(ang)) * CSng(Math.Sin(-ang2))
Dim CamLY As Single = CSng(Math.Cos(ang2))
Dim CamLZ As Single = CSng(-Math.Cos(ang)) * CSng(Math.Sin(-ang2))
myLookat.X = pos.X + (-CamLX) * 100.0F
myLookat.Y = pos.Y + (-CamLY) * 100.0F
myLookat.Z = pos.Z + (-CamLZ) * 100.0F
End Sub
Private Sub OffsetCam(xAmt As Integer, yAmt As Integer, zAmt As Integer)
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed))
Dim CamLY As Single = CSng(Math.Sin(pitch_Renamed))
Dim CamLZ As Single = CSng(-Math.Cos(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed))
pos.X = pos.X + xAmt * (CamLX) * CamSpeedMultiplier
pos.Y = pos.Y + yAmt * (CamLY) * CamSpeedMultiplier
pos.Z = pos.Z + zAmt * (CamLZ) * CamSpeedMultiplier
End Sub
Public Sub Move(y As Single, ByRef camMtx As Matrix4)
OffsetCam(0, y, 0)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(camMtx)
End Sub
Public Sub Move(x As Single, z As Single, ByRef camMtx As Matrix4)
UpdateCameraOffsetDirectly(x, z, camMtx)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(camMtx)
End Sub
Public Sub SetRotationFromLookAt()
Dim x_diff As Single = myLookat.X - pos.X
Dim y_diff As Single = myLookat.Y - pos.Y
Dim z_diff As Single = myLookat.Z - pos.Z
Dim dist As Single = CSng(Math.Sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff))
If z_diff = 0 Then
z_diff = 0.001F
End If
Dim nxz_ratio As Single = -x_diff / z_diff
If z_diff < 0 Then
CamAngleX = CSng(Math.Atan(nxz_ratio) + Math.PI)
Else
CamAngleX = CSng(Math.Atan(nxz_ratio))
End If
CamAngleY = -3.1459F - (CSng(Math.Asin(y_diff / dist)) - 1.57F)
End Sub
Public Sub ResetOrbitToSelectedObject()
Dim objs As ICameraPoint() = GetSelectedObject()
If objs?.Length > 0 Then
orbitTheta = -(CalculateCenterYRotationOfObjects(objs) * (CSng(Math.PI) / 180.0F))
orbitPhi = -0.3F
orbitDistance = 1200.0F
End If
End Sub
Public Sub UpdateOrbitCamera(ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT Then
Dim objs As ICameraPoint() = GetSelectedObject()
If objs?.Length > 0 Then
Dim centerPos As Numerics.Vector3 = CalculateCenterPositionOfObjects(objs)
pos.X = centerPos.X + CSng(Math.Cos(orbitPhi) * -Math.Sin(orbitTheta) * orbitDistance)
pos.Y = centerPos.Y + CSng(-Math.Sin(orbitPhi) * orbitDistance)
pos.Z = centerPos.Z + CSng(Math.Cos(orbitPhi) * Math.Cos(orbitTheta) * orbitDistance)
myLookat.X = centerPos.X
myLookat.Y = centerPos.Y
myLookat.Z = centerPos.Z
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
End If
End If
End Sub
Public Function IsOrbitCamera() As Boolean
Return myCamMode = CameraMode.ORBIT
End Function
Public Sub SetCameraMode(mode As CameraMode, ByRef cameraMatrix As Matrix4)
myCamMode = mode
If IsOrbitCamera() Then
ResetOrbitToSelectedObject()
UpdateOrbitCamera(cameraMatrix)
End If
End Sub
Public Sub SetCameraMode_LookDirection(dir As LookDirection, ByRef cameraMatrix As Matrix4)
myCamMode = CameraMode.LOOK_DIRECTION
currentLookDirection = dir
Select Case currentLookDirection
Case LookDirection.Top
pos = lookPositions(CInt(LookDirection.Top))
myLookat = New Vector3(pos.X, -25000, pos.Z - 1)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Bottom
pos = lookPositions(CInt(LookDirection.Bottom))
myLookat = New Vector3(pos.X, 25000, pos.Z + 1)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Left
pos = lookPositions(CInt(LookDirection.Left))
myLookat = New Vector3(25000, pos.Y, pos.Z)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Right
pos = lookPositions(CInt(LookDirection.Right))
myLookat = New Vector3(-25000, pos.Y, pos.Z)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Front
pos = lookPositions(CInt(LookDirection.Front))
myLookat = New Vector3(pos.X, pos.Y, -25000)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Back
pos = lookPositions(CInt(LookDirection.Back))
myLookat = New Vector3(pos.X, pos.Y, 25000)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
End Select
End Sub
Public Sub UpdateCameraMatrixWithMouse(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraMatrixWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix)
Else
UpdateCameraMatrixWithMouse_FLY(mouseX, mouseY, cameraMatrix)
End If
End Sub
Public Sub UpdateCameraOffsetWithMouse(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix)
Else
UpdateCameraOffsetWithMouse_FLY(orgPos, mouseX, mouseY, w, h, cameraMatrix)
End If
End Sub
Public Sub UpdateCameraMatrixWithScrollWheel(amt As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraMatrixWithScrollWheel_ORBIT(amt, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithScrollWheel_LOOK(amt, cameraMatrix)
Else
UpdateCameraMatrixWithScrollWheel_FLY(amt, cameraMatrix)
End If
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_FLY(amt As Integer, ByRef cameraMatrix As Matrix4)
OffsetCam(amt, amt, amt)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
End Sub
Public Sub RaisePerspectiveChanged()
RaiseEvent PerspectiveChanged(Me, New EventArgs)
End Sub
Public Sub UpdateMatrix(ByRef cameraMatrix As Matrix4)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z, 0, 1, 0)
RaisePerspectiveChanged()
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_LOOK(amt As Integer, ByRef cameraMatrix As Matrix4)
OffsetCam(amt, amt, amt)
OrientateCam(CamAngleX, CamAngleY)
Select Case currentLookDirection
Case LookDirection.Top
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z - 1, 0, 1, 0)
RaisePerspectiveChanged()
Case LookDirection.Bottom
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1, 0, 1, 0)
RaisePerspectiveChanged()
Case Else
UpdateMatrix(cameraMatrix)
End Select
End Sub
Private Sub UpdateCameraMatrixWithMouse_LOOK(orgPos As Vector3, mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = mouseX - lastMouseX
Dim MousePosY As Integer = mouseY - lastMouseY
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed))
Dim CamLY As Single = CSng(Math.Cos(pitch_Renamed))
Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed))
Dim m As Single = 8.0F
Select Case currentLookDirection
Case LookDirection.Top
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLX) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y - 1000, pos.Z - 1, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Bottom
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLX) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y + 1000, pos.Z + 1, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Left
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X + 12500, pos.Y, pos.Z, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Right
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X - 12500, pos.Y, pos.Z, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Front
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z - 12500, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Back
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z + 12500, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
End Select
RaisePerspectiveChanged()
lastMouseX = mouseX
lastMouseY = mouseY
'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
'setRotationFromLookAt();
End Sub
Private Sub UpdateCameraMatrixWithMouse_FLY(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = mouseX - lastMouseX
Dim MousePosY As Integer = mouseY - lastMouseY
CamAngleX = CamAngleX + (0.01F * MousePosX)
' This next part isn't neccessary, but it keeps the Yaw rotation value within [0, 2*pi] which makes debugging simpler.
If CamAngleX > TAU Then
CamAngleX -= TAU
ElseIf CamAngleX < 0 Then
CamAngleX += TAU
End If
' Lock pitch rotation within the bounds of [-3.1399.0, -0.0001], otherwise the LookAt function will snap to the
' opposite side and reverse mouse looking controls.
CamAngleY = Clampf((CamAngleY + (0.01F * MousePosY)), -3.1399F, -0.0001F)
lastMouseX = mouseX
lastMouseY = mouseY
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
'setRotationFromLookAt();
End Sub
Private Sub UpdateCameraOffsetWithMouse_FLY(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = (-mouseX) + lastMouseX
Dim MousePosY As Integer = (-mouseY) + lastMouseY
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = Math.Sin(yaw_Renamed)
Dim CamLZ As Single = -Math.Cos(yaw_Renamed)
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * 6.0F)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * 6.0F)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * 6.0F)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
End Sub
Public Sub UpdateCameraOffsetDirectly(horz_amount As Integer, vert_amount As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT Then
UpdateCameraOffsetDirectly_ORBIT(horz_amount / 5, vert_amount / 5, cameraMatrix)
Else
'Console.WriteLine(MousePosX+","+ MousePosY);
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed))
' float CamLY = (float)Math.Cos(pitch);
Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed))
pos.X += ((horz_amount * CamSpeedMultiplier) * (CamLX))
pos.Y += ((vert_amount * CamSpeedMultiplier) * (-1.0F))
pos.Z += ((horz_amount * CamSpeedMultiplier) * (CamLZ))
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
End If
End Sub
Private Sub UpdateCameraOffsetDirectly_ORBIT(moveSpeedX As Integer, moveSpeedY As Integer, ByRef cameraMatrix As Matrix4)
Dim MousePosX As Integer = moveSpeedX
Dim MousePosY As Integer = moveSpeedY
orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier
orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier
orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F)
UpdateOrbitCamera(cameraMatrix)
End Sub
Private Sub UpdateCameraMatrixWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
End Sub
Private Sub UpdateCameraOffsetWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = (-mouseX) + lastMouseX
Dim MousePosY As Integer = (-mouseY) + lastMouseY
orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier
orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier
orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F)
UpdateOrbitCamera(cameraMatrix)
lastMouseX = mouseX
lastMouseY = mouseY
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_ORBIT(amt As Integer, ByRef cameraMatrix As Matrix4)
orbitDistance -= amt
If orbitDistance < 300.0F Then
orbitDistance = 300.0F
End If
UpdateOrbitCamera(cameraMatrix)
End Sub
Public Sub ResetMouseStuff()
resetMouse = True
End Sub
Private Function CalculateCenterPositionOfObjects(objs As ICameraPoint()) As Numerics.Vector3
If objs.Length <= 1 Then
Dim obj As ICameraPoint = objs.FirstOrDefault
If obj Is Nothing Then
Return Numerics.Vector3.Zero
Else
Return New Numerics.Vector3(obj.Position.X,
obj.Position.Y,
obj.Position.Z)
End If
End If
Dim maxX As Single? = Nothing
Dim maxY As Single? = Nothing
Dim maxZ As Single? = Nothing
Dim minX As Single? = Nothing
Dim minY As Single? = Nothing
Dim minZ As Single? = Nothing
For Each obj As ICameraPoint In objs
Dim pos As Numerics.Vector3 = obj.Position
If maxX Is Nothing OrElse pos.X > maxX Then maxX = pos.X
If maxY Is Nothing OrElse pos.Y > maxY Then maxY = pos.Y
If maxZ Is Nothing OrElse pos.Z > maxZ Then maxZ = pos.Z
If minX Is Nothing OrElse pos.X < minX Then minX = pos.X
If minY Is Nothing OrElse pos.Y < minY Then minY = pos.Y
If minZ Is Nothing OrElse pos.Z < minZ Then minZ = pos.Z
Next
If maxX Is Nothing Then maxX = 0
If maxY Is Nothing Then maxY = 0
If maxZ Is Nothing Then maxZ = 0
If minX Is Nothing Then minX = 0
If minY Is Nothing Then minY = 0
If minZ Is Nothing Then minZ = 0
Dim upper As New Numerics.Vector3(maxX, maxY, maxZ)
Dim lower As New Numerics.Vector3(minX, minY, minZ)
Dim middle As Numerics.Vector3 = (upper + lower) / 2
Return middle
End Function
Private Function CalculateCenterYRotationOfObjects(objs As ICameraPoint()) As Single
If objs.Length <= 1 Then
Dim obj As ICameraPoint = objs.FirstOrDefault
If obj Is Nothing Then
Return 0
Else
Return obj.Rotation.Y
End If
End If
Dim yRot As New List(Of Single)
For Each obj As ICameraPoint In objs
yRot.Add(obj.Rotation.Y)
Next
Return yRot.Average
End Function
Private Function GetSelectedObject() As ICameraPoint()
Dim e As New NeedSelectedObjectEventArgs
RaiseEvent NeedSelectedObject(Me, e)
Dim stopw As New Stopwatch
stopw.Start()
Do Until e.HasObjectSetted OrElse stopw.ElapsedMilliseconds > 1000
Application.DoEvents()
Loop
stopw.Stop()
Return e.Points
End Function
'C A P S E L T C L A S S E S
Public Class NeedSelectedObjectEventArgs
Inherits EventArgs
Private _HasObjectSetted As Boolean = False
Public ReadOnly Property HasObjectSetted As Boolean
Get
Return _HasObjectSetted
End Get
End Property
Private _Points As ICameraPoint() = Nothing
Public Property Points As ICameraPoint()
Get
Return _Points
End Get
Set(value As ICameraPoint())
_Points = value
_HasObjectSetted = True
End Set
End Property
End Class
End Class
End Namespace

View File

@@ -0,0 +1,10 @@
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
{
public enum CameraMode
{
FLY = 0,
ORBIT = 1,
LOOK_DIRECTION = 2
}
}

View File

@@ -1,9 +0,0 @@
Namespace CameraN
Public Enum CameraMode
FLY = 0
ORBIT = 1
LOOK_DIRECTION = 2
End Enum
End Namespace

View File

@@ -0,0 +1,9 @@
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
{
public interface ICameraPoint
{
System.Numerics.Vector3 Position { get; set; }
System.Numerics.Vector3 Rotation { get; set; }
}
}

View File

@@ -1,10 +0,0 @@
Namespace CameraN
Public Interface ICameraPoint
Property Position As Numerics.Vector3
Property Rotation As Numerics.Vector3
End Interface
End Namespace

View File

@@ -0,0 +1,13 @@
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
{
public enum LookDirection
{
Top,
Bottom,
Left,
Right,
Front,
Back
}
}

View File

@@ -1,12 +0,0 @@
Namespace CameraN
Public Enum LookDirection
Top
Bottom
Left
Right
Front
Back
End Enum
End Namespace

View File

@@ -1,120 +0,0 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ModelPreview
Inherits DevComponents.DotNetBar.OfficeForm
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview))
Me.PanelEx1 = New DevComponents.DotNetBar.PanelEx()
Me.PanelEx2 = New DevComponents.DotNetBar.PanelEx()
Me.DoubleInput1 = New DevComponents.Editors.DoubleInput()
Me.LabelX1 = New DevComponents.DotNetBar.LabelX()
Me.PanelEx2.SuspendLayout()
CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PanelEx1
'
Me.PanelEx1.CanvasColor = System.Drawing.Color.Empty
Me.PanelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
Me.PanelEx1.DisabledBackColor = System.Drawing.Color.Empty
Me.PanelEx1.Dock = System.Windows.Forms.DockStyle.Fill
Me.PanelEx1.Location = New System.Drawing.Point(0, 47)
Me.PanelEx1.Name = "PanelEx1"
Me.PanelEx1.Size = New System.Drawing.Size(880, 491)
Me.PanelEx1.Style.Alignment = System.Drawing.StringAlignment.Center
Me.PanelEx1.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
Me.PanelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
Me.PanelEx1.Style.GradientAngle = 90
Me.PanelEx1.TabIndex = 0
'
'PanelEx2
'
Me.PanelEx2.CanvasColor = System.Drawing.Color.Empty
Me.PanelEx2.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
Me.PanelEx2.Controls.Add(Me.DoubleInput1)
Me.PanelEx2.Controls.Add(Me.LabelX1)
Me.PanelEx2.DisabledBackColor = System.Drawing.Color.Empty
Me.PanelEx2.Dock = System.Windows.Forms.DockStyle.Top
Me.PanelEx2.Location = New System.Drawing.Point(0, 0)
Me.PanelEx2.Name = "PanelEx2"
Me.PanelEx2.Size = New System.Drawing.Size(880, 47)
Me.PanelEx2.Style.Alignment = System.Drawing.StringAlignment.Center
Me.PanelEx2.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
Me.PanelEx2.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
Me.PanelEx2.Style.GradientAngle = 90
Me.PanelEx2.TabIndex = 7
Me.PanelEx2.Visible = False
'
'DoubleInput1
'
'
'
'
Me.DoubleInput1.BackgroundStyle.Class = "DateTimeInputBackground"
Me.DoubleInput1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square
Me.DoubleInput1.ButtonFreeText.Shortcut = DevComponents.DotNetBar.eShortcut.F2
Me.DoubleInput1.Increment = 1.0R
Me.DoubleInput1.Location = New System.Drawing.Point(62, 13)
Me.DoubleInput1.Name = "DoubleInput1"
Me.DoubleInput1.ShowUpDown = True
Me.DoubleInput1.Size = New System.Drawing.Size(80, 20)
Me.DoubleInput1.TabIndex = 0
'
'LabelX1
'
'
'
'
Me.LabelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square
Me.LabelX1.Location = New System.Drawing.Point(12, 12)
Me.LabelX1.Name = "LabelX1"
Me.LabelX1.Size = New System.Drawing.Size(44, 23)
Me.LabelX1.TabIndex = 1
Me.LabelX1.Text = "Scaling:"
'
'ModelPreview
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(880, 538)
Me.Controls.Add(Me.PanelEx1)
Me.Controls.Add(Me.PanelEx2)
Me.DoubleBuffered = True
Me.EnableGlass = False
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.KeyPreview = True
Me.Name = "ModelPreview"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "ModelPreview"
Me.TopLeftCornerSize = 0
Me.TopRightCornerSize = 0
Me.PanelEx2.ResumeLayout(False)
CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents PanelEx1 As DevComponents.DotNetBar.PanelEx
Friend WithEvents PanelEx2 As DevComponents.DotNetBar.PanelEx
Friend WithEvents DoubleInput1 As DevComponents.Editors.DoubleInput
Friend WithEvents LabelX1 As DevComponents.DotNetBar.LabelX
End Class

View File

@@ -0,0 +1,11 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
// ------------------------------------------------------------------------------

View File

@@ -1,13 +0,0 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

View File

@@ -1,35 +0,0 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' Allgemeine Informationen über eine Assembly werden über die folgenden
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
' die einer Assembly zugeordnet sind.
' Werte der Assemblyattribute überprüfen
<Assembly: AssemblyTitle("OpenGLRenderer")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Pilzinsel64")>
<Assembly: AssemblyProduct("OpenGLRenderer")>
<Assembly: AssemblyCopyright("Copyright © Pilzinsel64 2018")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
<Assembly: Guid("03d57392-1aac-468d-b5c9-30d927e685b5")>
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
'
' Hauptversion
' Nebenversion
' Buildnummer
' Revision
'
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@@ -0,0 +1,192 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using Microsoft.VisualBasic;
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */
/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My
{
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */
internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase
{
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
}
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
/* TODO ERROR: Skipped IfDirectiveTrivia */
internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer
{
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
[DebuggerHidden()]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public MyComputer() : base()
{
}
}
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
[HideModuleName()]
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
internal static class MyProject
{
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.ComponentModel.Design.HelpKeyword("My.Computer")]
internal static MyComputer Computer
{
[DebuggerHidden()]
get
{
return m_ComputerObjectProvider.GetInstance;
}
}
private readonly static ThreadSafeObjectProvider<MyComputer> m_ComputerObjectProvider = new ThreadSafeObjectProvider<MyComputer>();
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.ComponentModel.Design.HelpKeyword("My.Application")]
internal static MyApplication Application
{
[DebuggerHidden()]
get
{
return m_AppObjectProvider.GetInstance;
}
}
private readonly static ThreadSafeObjectProvider<MyApplication> m_AppObjectProvider = new ThreadSafeObjectProvider<MyApplication>();
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.ComponentModel.Design.HelpKeyword("My.User")]
internal static Microsoft.VisualBasic.ApplicationServices.User User
{
[DebuggerHidden()]
get
{
return m_UserObjectProvider.GetInstance;
}
}
private readonly static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User> m_UserObjectProvider = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User>();
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
[System.ComponentModel.Design.HelpKeyword("My.WebServices")]
internal static MyWebServices WebServices
{
[DebuggerHidden()]
get
{
return m_MyWebServicesObjectProvider.GetInstance;
}
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")]
internal sealed class MyWebServices
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[DebuggerHidden()]
public override bool Equals(object o)
{
return base.Equals(o);
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[DebuggerHidden()]
public override int GetHashCode()
{
return base.GetHashCode();
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[DebuggerHidden()]
internal new Type GetType()
{
return typeof(MyWebServices);
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[DebuggerHidden()]
public override string ToString()
{
return base.ToString();
}
[DebuggerHidden()]
private static T Create__Instance__<T>(T instance) where T : new()
{
if (instance == null)
{
return new T();
}
else
{
return instance;
}
}
[DebuggerHidden()]
private void Dispose__Instance__<T>(ref T instance)
{
instance = default;
}
[DebuggerHidden()]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public MyWebServices() : base()
{
}
}
private readonly static ThreadSafeObjectProvider<MyWebServices> m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider<MyWebServices>();
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.InteropServices.ComVisible(false)]
internal sealed class ThreadSafeObjectProvider<T> where T : new()
{
internal T GetInstance
{
/* TODO ERROR: Skipped IfDirectiveTrivia */
[DebuggerHidden()]
get
{
var Value = m_Context.Value;
if (Value == null)
{
Value = new T();
m_Context.Value = Value;
}
return Value;
}
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
}
[DebuggerHidden()]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public ThreadSafeObjectProvider() : base()
{
}
/* TODO ERROR: Skipped IfDirectiveTrivia */
private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue<T> m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue<T>();
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
}
}
}
/* TODO ERROR: Skipped EndIfDirectiveTrivia */

View File

@@ -0,0 +1,253 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// See Compiler::LoadXmlSolutionExtension
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My
{
[Embedded()]
[DebuggerNonUserCode()]
[System.Runtime.CompilerServices.CompilerGenerated()]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
internal sealed class InternalXmlHelper
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
private InternalXmlHelper()
{
}
public static string get_Value(IEnumerable<XElement> source)
{
foreach (XElement item in source)
return item.Value;
return null;
}
public static void set_Value(IEnumerable<XElement> source, string value)
{
foreach (XElement item in source)
{
item.Value = value;
break;
}
}
public static string get_AttributeValue(IEnumerable<XElement> source, XName name)
{
foreach (XElement item in source)
return Conversions.ToString(item.Attribute(name));
return null;
}
public static void set_AttributeValue(IEnumerable<XElement> source, XName name, string value)
{
foreach (XElement item in source)
{
item.SetAttributeValue(name, value);
break;
}
}
public static string get_AttributeValue(XElement source, XName name)
{
return Conversions.ToString(source.Attribute(name));
}
public static void set_AttributeValue(XElement source, XName name, string value)
{
source.SetAttributeValue(name, value);
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static XAttribute CreateAttribute(XName name, object value)
{
if (value is null)
{
return null;
}
return new XAttribute(name, value);
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns)
{
var a = new XAttribute(name, ns.NamespaceName);
a.AddAnnotation(ns);
return a;
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, object obj)
{
if (obj is object)
{
XElement elem = obj as XElement;
if (elem is object)
{
return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem);
}
else
{
IEnumerable elems = obj as IEnumerable;
if (elems is object)
{
return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems);
}
}
}
return obj;
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, IEnumerable obj)
{
if (obj is object)
{
IEnumerable<XElement> elems = obj as IEnumerable<XElement>;
if (elems is object)
{
return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement);
}
else
{
return obj.Cast<object>().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject);
}
}
return obj;
}
[DebuggerNonUserCode()]
[System.Runtime.CompilerServices.CompilerGenerated()]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
private sealed class RemoveNamespaceAttributesClosure
{
private readonly string[] m_inScopePrefixes;
private readonly XNamespace[] m_inScopeNs;
private readonly List<XAttribute> m_attributes;
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes)
{
m_inScopePrefixes = inScopePrefixes;
m_inScopeNs = inScopeNs;
m_attributes = attributes;
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
internal XElement ProcessXElement(XElement elem)
{
return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem);
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
internal object ProcessObject(object obj)
{
XElement elem = obj as XElement;
if (elem is object)
{
return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem);
}
else
{
return obj;
}
}
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, XElement e)
{
if (e is object)
{
var a = e.FirstAttribute;
while (a is object)
{
var nextA = a.NextAttribute;
if (a.IsNamespaceDeclaration)
{
var ns = a.Annotation<XNamespace>();
string prefix = a.Name.LocalName;
if (ns is object)
{
if (inScopePrefixes is object && inScopeNs is object)
{
int lastIndex = inScopePrefixes.Length - 1;
for (int i = 0, loopTo = lastIndex; i <= loopTo; i++)
{
string currentInScopePrefix = inScopePrefixes[i];
var currentInScopeNs = inScopeNs[i];
if (prefix.Equals(currentInScopePrefix))
{
if (ns == currentInScopeNs)
{
// prefix and namespace match. Remove the unneeded ns attribute
a.Remove();
}
// prefix is in scope but refers to something else. Leave the ns attribute.
a = null;
break;
}
}
}
if (a is object)
{
// Prefix is not in scope
// Now check whether it's going to be in scope because it is in the attributes list
if (attributes is object)
{
int lastIndex = attributes.Count - 1;
for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++)
{
var currentA = attributes[i];
string currentInScopePrefix = currentA.Name.LocalName;
var currentInScopeNs = currentA.Annotation<XNamespace>();
if (currentInScopeNs is object)
{
if (prefix.Equals(currentInScopePrefix))
{
if (ns == currentInScopeNs)
{
// prefix and namespace match. Remove the unneeded ns attribute
a.Remove();
}
// prefix is in scope but refers to something else. Leave the ns attribute.
a = null;
break;
}
}
}
}
if (a is object)
{
// Prefix is definitely not in scope
a.Remove();
// namespace is not defined either. Add this attributes list
attributes.Add(a);
}
}
}
}
a = nextA;
}
}
return e;
}
}
}

View File

@@ -0,0 +1,14 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.VisualBasic
{
[Embedded()]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.CompilerServices.CompilerGenerated()]
internal sealed class Embedded : Attribute
{
}
}

View File

@@ -1,63 +0,0 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System
Namespace My.Resources
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
'''<summary>
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Drawing.Drawing3D.OpenGLFactory.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set
resourceCulture = value
End Set
End Property
End Module
End Namespace

View File

@@ -1,73 +0,0 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
#Region "Automatische My.Settings-Speicherfunktion"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings
Get
Return Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings.Default
End Get
End Property
End Module
End Namespace

View File

@@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}</ProjectGuid>
<ProjectGuid>{ECBB8A61-3BE0-0658-02A4-A7806FD3F824}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory</RootNamespace>
<AssemblyName>Pilz.Drawing.Drawing3D.OpenGLFactory</AssemblyName>
@@ -12,6 +12,8 @@
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkProfile />
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -44,6 +46,7 @@
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
@@ -67,62 +70,65 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Camera\Camera.vb" />
<Compile Include="Camera\CameraMode.vb" />
<Compile Include="Camera\LookDirection.vb" />
<Compile Include="Preview\ModelPreview.Designer.vb">
<DependentUpon>ModelPreview.vb</DependentUpon>
<Compile Include="My Project\MyNamespace.Static.1.Designer.cs" />
<Compile Include="My Project\MyNamespace.Static.2.Designer.cs" />
<Compile Include="My Project\MyNamespace.Static.3.Designer.cs" />
<Compile Include="Camera\Camera.cs" />
<Compile Include="Camera\CameraMode.cs" />
<Compile Include="Camera\LookDirection.cs" />
<Compile Include="Preview\ModelPreview.Designer.cs">
<DependentUpon>ModelPreview.cs</DependentUpon>
</Compile>
<Compile Include="Preview\ModelPreview.vb">
<Compile Include="Preview\ModelPreview.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Rendering\BoundingBox.vb" />
<Compile Include="Camera\ICameraPoint.vb" />
<Compile Include="Rendering\ContentPipe.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<Compile Include="Rendering\BoundingBox.cs" />
<Compile Include="Camera\ICameraPoint.cs" />
<Compile Include="Rendering\ContentPipe.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="My Project\Application.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Rendering\Renderer.vb" />
<Compile Include="Rendering\RenderMode.vb" />
<Compile Include="Rendering\Renderer.cs" />
<Compile Include="Rendering\RenderMode.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<EmbeddedResource Include="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<CustomToolNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory.My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Preview\ModelPreview.resx">
<DependentUpon>ModelPreview.vb</DependentUpon>
<DependentUpon>ModelPreview.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
<LastGenOutput>Application.Designer.cs</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
<CustomToolNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory.My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj">
<Project>{ac955819-7910-450c-940c-7c1989483d4b}</Project>
<ProjectReference Include="..\Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.csproj">
<Project>{1EB1D972-B548-0AFD-1654-B667EBDF09EB}</Project>
<Name>Pilz.Simple3DFileParser</Name>
</ProjectReference>
</ItemGroup>
@@ -137,5 +143,5 @@
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,52 @@
using System;
using System.Diagnostics;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.PreviewN
{
[Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
public partial class ModelPreview : System.Windows.Forms.Form
{
// Form overrides dispose to clean up the component list.
[DebuggerNonUserCode()]
protected override void Dispose(bool disposing)
{
try
{
if (disposing && components is object)
{
components.Dispose();
}
}
finally
{
base.Dispose(disposing);
}
}
// Required by the Windows Form Designer
private System.ComponentModel.IContainer components;
// NOTE: The following procedure is required by the Windows Form Designer
// It can be modified using the Windows Form Designer.
// Do not modify it using the code editor.
[DebuggerStepThrough()]
private void InitializeComponent()
{
var resources = new System.ComponentModel.ComponentResourceManager(typeof(ModelPreview));
SuspendLayout();
//
// ModelPreview
//
ClientSize = new System.Drawing.Size(880, 538);
DoubleBuffered = true;
Name = "ModelPreview";
Text = "ModelPreview";
Shown += new EventHandler(HandlesOnShown);
Activated += new EventHandler(HandlesOnActivated);
Deactivate += new EventHandler(HandlesOnDeactivate);
Disposed += new EventHandler(ModelPreview_FormDisposed);
ResumeLayout(false);
}
}
}

View File

@@ -1,42 +0,0 @@
Namespace PreviewN
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ModelPreview
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview))
Me.SuspendLayout()
'
'ModelPreview
'
Me.ClientSize = New System.Drawing.Size(880, 538)
Me.DoubleBuffered = True
Me.Name = "ModelPreview"
Me.Text = "ModelPreview"
Me.ResumeLayout(False)
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,487 @@
using System;
using System.Collections.Generic;
using global::System.Drawing;
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
using System.Linq;
using System.Runtime.CompilerServices;
using global::System.Windows.Forms;
using global::OpenTK;
using global::OpenTK.Graphics.OpenGL;
using Key = OpenTK.Input.Key;
using Keyboard = OpenTK.Input.Keyboard;
using global::Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN;
using global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN;
using global::Pilz.S3DFileParser;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.PreviewN
{
public partial class ModelPreview
{
public ModelPreview(Object3D[] objs, float scale)
{
MyCamera = new Camera();
RenderTimer = new System.Timers.Timer(25d) { AutoReset = true };
SuspendLayout();
InitializeComponent();
DoubleBuffered = true;
// glControl1
glControl1 = new GLControl();
glControl1.BackColor = Color.Black;
glControl1.Location = new Point(0, 0);
glControl1.MinimumSize = new Size(600, 120);
glControl1.Name = "glControl1";
glControl1.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
glControl1.Location = new Point(0, 0);
glControl1.Size = ClientSize;
glControl1.TabIndex = 0;
glControl1.TabStop = false;
glControl1.VSync = false;
Controls.Add(glControl1);
ResumeLayout(false);
// RenderTimer.SynchronizingObject = Nothing
Scaling = scale;
// Toolkit.Init()
glControl1.CreateControl();
glControl1.MouseWheel += glControl1_Wheel;
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, (float)(glControl1.Width / (double)glControl1.Height), 100.0f, 100000.0f);
glControl1.Enabled = false;
MyCamera.SetCameraMode(CameraMode.FLY, ref camMtx);
MyCamera.UpdateMatrix(ref camMtx);
ResumeLayout();
foreach (Object3D obj in objs)
AddModel(obj);
}
private GLControl _glControl1;
private GLControl glControl1
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _glControl1;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_glControl1 != null)
{
_glControl1.Load -= glControl1_Load;
_glControl1.Paint -= HandlesOnPaint;
_glControl1.Resize -= glControl1_Resize;
_glControl1.MouseDown -= glControl1_MouseDown;
_glControl1.MouseLeave -= glControl1_MouseLeave;
_glControl1.MouseUp -= glControl1_MouseLeave;
_glControl1.MouseMove -= glControl1_MouseMove;
}
_glControl1 = value;
if (_glControl1 != null)
{
_glControl1.Load += glControl1_Load;
_glControl1.Paint += HandlesOnPaint;
_glControl1.Resize += glControl1_Resize;
_glControl1.MouseDown += glControl1_MouseDown;
_glControl1.MouseLeave += glControl1_MouseLeave;
_glControl1.MouseUp += glControl1_MouseLeave;
_glControl1.MouseMove += glControl1_MouseMove;
}
}
}
private Camera _MyCamera;
private Camera MyCamera
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _MyCamera;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_MyCamera != null)
{
_MyCamera.NeedSelectedObject -= Camera_NeedSelectedObject;
_MyCamera.PerspectiveChanged -= MyCamera_PerspectiveChanged;
}
_MyCamera = value;
if (_MyCamera != null)
{
_MyCamera.NeedSelectedObject += Camera_NeedSelectedObject;
_MyCamera.PerspectiveChanged += MyCamera_PerspectiveChanged;
}
}
}
private Matrix4 ProjMatrix = default;
private float FOV = 1.048f;
private Matrix4 camMtx = Matrix4.Identity;
private Vector3 savedCamPos = new Vector3();
private bool _isMouseDown = false;
private bool isDeactivated = false;
private readonly Dictionary<Object3D, Renderer> myModels = new Dictionary<Object3D, Renderer>();
private System.Timers.Timer _RenderTimer;
private System.Timers.Timer RenderTimer
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _RenderTimer;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_RenderTimer != null)
{
_RenderTimer.Elapsed -= RenderTimer_Elapsed;
}
_RenderTimer = value;
if (_RenderTimer != null)
{
_RenderTimer.Elapsed += RenderTimer_Elapsed;
}
}
}
private bool _EnableCameraControlling = false;
public float Scaling { get; set; } = 500.0f;
public Color ClearColor { get; set; } = Color.CornflowerBlue;
public bool EnableCameraControlling
{
get
{
return _EnableCameraControlling;
}
set
{
_EnableCameraControlling = value;
if (value)
{
if (!RenderTimer.Enabled)
{
RenderTimer.Start();
}
}
else if (RenderTimer.Enabled)
{
RenderTimer.Stop();
}
}
}
public double RenderInterval
{
get
{
return RenderTimer.Interval;
}
set
{
RenderTimer.Interval = value;
}
}
public Camera Camera
{
get
{
return MyCamera;
}
}
public Matrix4 CameraMatrix
{
get
{
return camMtx;
}
}
public IReadOnlyDictionary<Object3D, Renderer> Models
{
get
{
return myModels;
}
}
public Control GLControl
{
get
{
return glControl1;
}
}
private bool IsStrgPressed
{
get
{
var state = Keyboard.GetState();
return state[Key.ControlLeft] || state[Key.ControlRight];
}
}
private bool IsShiftPressed
{
get
{
var state = Keyboard.GetState();
return state[Key.ShiftLeft] || state[Key.ShiftRight];
}
}
public bool IsMouseDown
{
get
{
return _isMouseDown;
}
set
{
_isMouseDown = value;
glControl1.Refresh();
}
}
public ModelPreview() : this(Array.Empty<Object3D>(), 1.0f)
{
}
public ModelPreview(Object3D obj) : this(obj, 1.0f)
{
}
public ModelPreview(Object3D obj, float scale) : this(new[] { obj }, scale)
{
}
public void UpdateOrbitCamera()
{
if (Camera.IsOrbitCamera())
{
Camera.UpdateOrbitCamera(ref camMtx);
}
}
public void UpdateView()
{
if (glControl1.Enabled)
{
glControl1.Invoke(new Action(() => glControl1.Invalidate()));
}
}
public Renderer AddModel(Object3D obj)
{
var rndr = new Renderer(obj);
AddModel(rndr);
return rndr;
}
public void AddModel(Renderer rndr)
{
myModels.Add(rndr.Model, rndr);
}
public void HandlesOnShown(object sender, EventArgs e)
{
glControl1.Enabled = true;
RenderModels();
glControl1.Invalidate();
}
public void RenderModels()
{
foreach (Renderer rndr in myModels.Values)
RenderModel(rndr);
}
public void RenderModel(Renderer rndr)
{
if (myModels.Values.Contains(rndr))
{
rndr.ModelScaling = Scaling;
rndr.RenderModel();
}
}
private void glControl1_Load(object sender, EventArgs e)
{
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Lequal);
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.AlphaTest);
GL.AlphaFunc(AlphaFunction.Gequal, 0.5f);
GL.Enable(EnableCap.CullFace);
}
public void HandlesOnActivated(object sender, EventArgs e)
{
if (isDeactivated)
{
isDeactivated = false;
}
}
public void HandlesOnDeactivate(object sender, EventArgs e)
{
isDeactivated = true;
}
private void RenderTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (!isDeactivated)
{
MoveCameraViaWASDQE();
}
}
public void HandlesOnPaint(object sender, PaintEventArgs e)
{
GL.ClearColor(ClearColor);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref ProjMatrix);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref camMtx);
foreach (Renderer rndr in myModels.Values)
{
if (rndr.HasRendered)
{
rndr.DrawModel(RenderMode.FillOutline);
}
}
glControl1.SwapBuffers();
}
private void glControl1_Resize(object sender, EventArgs e)
{
glControl1.Context.Update(glControl1.WindowInfo);
GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, (float)(glControl1.Width / (double)glControl1.Height), 100.0f, 100000.0f);
glControl1.Invalidate();
}
private void glControl1_Wheel(object sender, MouseEventArgs e)
{
MyCamera.ResetMouseStuff();
MyCamera.UpdateCameraMatrixWithScrollWheel((int)Math.Truncate(e.Delta * (IsShiftPressed ? 3.5f : 1.5f)), ref camMtx);
savedCamPos = MyCamera.Position;
glControl1.Invalidate();
}
private void glControl1_MouseDown(object sender, MouseEventArgs e)
{
IsMouseDown = true;
savedCamPos = MyCamera.Position;
}
private void glControl1_MouseLeave(object sender, EventArgs e)
{
MyCamera.ResetMouseStuff();
IsMouseDown = false;
}
private void glControl1_MouseMove(object sender, MouseEventArgs e)
{
if (IsMouseDown && e.Button == MouseButtons.Left)
{
if (IsShiftPressed)
{
MyCamera.UpdateCameraOffsetWithMouse(savedCamPos, e.X, e.Y, glControl1.Width, glControl1.Height, ref camMtx);
}
else
{
MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, ref camMtx);
}
glControl1.Invalidate();
}
}
public void MoveCameraViaWASDQE()
{
int moveSpeed = Convert.ToInt32(Math.Round((IsShiftPressed ? 60 : 30) * MyCamera.CamSpeedMultiplier, 0));
bool allowCamMove = !(IsMouseDown && IsShiftPressed);
if (allowCamMove)
{
var state = Keyboard.GetState();
if (state[Key.W])
{
// camera.Move(moveSpeed, moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, ref camMtx);
savedCamPos = MyCamera.Position;
}
if (state[Key.S])
{
// camera.Move(-moveSpeed, -moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, ref camMtx);
savedCamPos = MyCamera.Position;
}
if (state[Key.A])
{
// camera.Move(-moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, ref camMtx);
}
if (state[Key.D])
{
// camera.Move(moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, ref camMtx);
}
if (state[Key.E])
{
// camera.Move(0, -moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, ref camMtx);
}
if (state[Key.Q])
{
// camera.Move(0, moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, ref camMtx);
}
}
}
private void Camera_NeedSelectedObject(object sender, Camera.NeedSelectedObjectEventArgs e)
{
e.Points = null;
}
private void MyCamera_PerspectiveChanged(object sender, EventArgs e)
{
UpdateView();
}
private void ModelPreview_FormDisposed(object sender, EventArgs e)
{
foreach (Renderer rndr in myModels.Values)
rndr.ReleaseBuffers();
}
}
}

View File

@@ -1,336 +0,0 @@
Imports System.Drawing
Imports System.Windows.Forms
Imports Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
Imports Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports Pilz.S3DFileParser
Imports Point = System.Drawing.Point
Imports KeyboardState = OpenTK.Input.KeyboardState
Imports Keyboard = OpenTK.Input.Keyboard
Imports Key = OpenTK.Input.Key
Imports Color = System.Drawing.Color
Namespace PreviewN
Public Class ModelPreview
Private WithEvents glControl1 As GLControl
Private WithEvents MyCamera As New Camera
Private ProjMatrix As Matrix4 = Nothing
Private FOV As Single = 1.048F
Private camMtx As Matrix4 = Matrix4.Identity
Private savedCamPos As New Vector3
Private _isMouseDown As Boolean = False
Private isDeactivated As Boolean = False
Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer)
Private WithEvents RenderTimer As New Timers.Timer(25) With {.AutoReset = True}
Private _EnableCameraControlling As Boolean = False
Public Property Scaling As Single = 500.0F
Public Property ClearColor As Color = Color.CornflowerBlue
Public Property EnableCameraControlling As Boolean
Get
Return _EnableCameraControlling
End Get
Set
_EnableCameraControlling = Value
If Value Then
If Not RenderTimer.Enabled Then
RenderTimer.Start()
End If
ElseIf RenderTimer.Enabled Then
RenderTimer.Stop()
End If
End Set
End Property
Public Property RenderInterval As Double
Get
Return RenderTimer.Interval
End Get
Set
RenderTimer.Interval = Value
End Set
End Property
Public ReadOnly Property Camera As Camera
Get
Return MyCamera
End Get
End Property
Public ReadOnly Property CameraMatrix As Matrix4
Get
Return camMtx
End Get
End Property
Public ReadOnly Property Models As IReadOnlyDictionary(Of Object3D, Renderer)
Get
Return myModels
End Get
End Property
Public ReadOnly Property GLControl As Control
Get
Return glControl1
End Get
End Property
Private ReadOnly Property IsStrgPressed As Boolean
Get
Dim state As KeyboardState = Keyboard.GetState()
Return state(Key.ControlLeft) OrElse state(Key.ControlRight)
End Get
End Property
Private ReadOnly Property IsShiftPressed As Boolean
Get
Dim state As KeyboardState = Keyboard.GetState()
Return state(Key.ShiftLeft) OrElse state(Key.ShiftRight)
End Get
End Property
Public Property IsMouseDown As Boolean
Get
Return _isMouseDown
End Get
Set(value As Boolean)
_isMouseDown = value
glControl1.Refresh()
End Set
End Property
Public Sub New()
Me.New({}, 1.0F)
End Sub
Public Sub New(obj As Object3D)
Me.New(obj, 1.0F)
End Sub
Public Sub New(obj As Object3D, scale As Single)
Me.New({obj}, scale)
End Sub
Public Sub New(objs As Object3D(), scale As Single)
Me.SuspendLayout()
InitializeComponent()
DoubleBuffered = True
'glControl1
Me.glControl1 = New GLControl
Me.glControl1.BackColor = Color.Black
Me.glControl1.Location = New Point(0, 0)
Me.glControl1.MinimumSize = New Size(600, 120)
Me.glControl1.Name = "glControl1"
Me.glControl1.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom
Me.glControl1.Location = New Point(0, 0)
Me.glControl1.Size = Me.ClientSize
Me.glControl1.TabIndex = 0
Me.glControl1.TabStop = False
Me.glControl1.VSync = False
Me.Controls.Add(Me.glControl1)
Me.ResumeLayout(False)
'RenderTimer.SynchronizingObject = Nothing
Scaling = scale
'Toolkit.Init()
glControl1.CreateControl()
AddHandler glControl1.MouseWheel, AddressOf glControl1_Wheel
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F)
glControl1.Enabled = False
MyCamera.SetCameraMode(CameraMode.FLY, camMtx)
MyCamera.UpdateMatrix(camMtx)
Me.ResumeLayout()
For Each obj As Object3D In objs
AddModel(obj)
Next
End Sub
Public Sub UpdateOrbitCamera()
If Camera.IsOrbitCamera Then
Camera.UpdateOrbitCamera(camMtx)
End If
End Sub
Public Sub UpdateView()
If glControl1.Enabled Then
glControl1.Invoke(Sub() glControl1.Invalidate())
End If
End Sub
Public Function AddModel(obj As Object3D) As Renderer
Dim rndr As New Renderer(obj)
AddModel(rndr)
Return rndr
End Function
Public Sub AddModel(rndr As Renderer)
myModels.Add(rndr.Model, rndr)
End Sub
Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown
glControl1.Enabled = True
RenderModels()
glControl1.Invalidate()
End Sub
Public Sub RenderModels()
For Each rndr As Renderer In myModels.Values
RenderModel(rndr)
Next
End Sub
Public Sub RenderModel(rndr As Renderer)
If myModels.Values.Contains(rndr) Then
rndr.ModelScaling = Scaling
rndr.RenderModel()
End If
End Sub
Private Sub glControl1_Load(sender As Object, e As EventArgs) Handles glControl1.Load
GL.Enable(EnableCap.Blend)
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha)
GL.Enable(EnableCap.DepthTest)
GL.DepthFunc(DepthFunction.Lequal)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
GL.AlphaFunc(AlphaFunction.Gequal, 0.5F)
GL.Enable(EnableCap.CullFace)
End Sub
Public Sub HandlesOnActivated(sender As Object, e As EventArgs) Handles Me.Activated
If isDeactivated Then
isDeactivated = False
End If
End Sub
Public Sub HandlesOnDeactivate(sender As Object, e As EventArgs) Handles Me.Deactivate
isDeactivated = True
End Sub
Private Sub RenderTimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles RenderTimer.Elapsed
If Not isDeactivated Then
MoveCameraViaWASDQE()
End If
End Sub
Public Sub HandlesOnPaint(sender As Object, e As PaintEventArgs) Handles glControl1.Paint
GL.ClearColor(ClearColor)
GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
GL.MatrixMode(MatrixMode.Projection)
GL.LoadMatrix(ProjMatrix)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadMatrix(camMtx)
For Each rndr As Renderer In myModels.Values
If rndr.HasRendered Then
rndr.DrawModel(RenderMode.FillOutline)
End If
Next
glControl1.SwapBuffers()
End Sub
Private Sub glControl1_Resize(sender As Object, e As EventArgs) Handles glControl1.Resize
glControl1.Context.Update(glControl1.WindowInfo)
GL.Viewport(0, 0, glControl1.Width, glControl1.Height)
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F)
glControl1.Invalidate()
End Sub
Private Sub glControl1_Wheel(sender As Object, e As MouseEventArgs)
MyCamera.ResetMouseStuff()
MyCamera.UpdateCameraMatrixWithScrollWheel(CInt(Math.Truncate(e.Delta * (If(IsShiftPressed, 3.5F, 1.5F)))), camMtx)
savedCamPos = MyCamera.Position
glControl1.Invalidate()
End Sub
Private Sub glControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseDown
IsMouseDown = True
savedCamPos = MyCamera.Position
End Sub
Private Sub glControl1_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles glControl1.MouseLeave, glControl1.MouseUp
MyCamera.ResetMouseStuff()
IsMouseDown = False
End Sub
Private Sub glControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseMove
If IsMouseDown AndAlso e.Button = MouseButtons.Left Then
If IsShiftPressed Then
MyCamera.UpdateCameraOffsetWithMouse(savedCamPos, e.X, e.Y, glControl1.Width, glControl1.Height, camMtx)
Else
MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, camMtx)
End If
glControl1.Invalidate()
End If
End Sub
Public Sub MoveCameraViaWASDQE()
Dim moveSpeed As Integer = Convert.ToInt32(Math.Round((If(IsShiftPressed, 60, 30)) * (MyCamera.CamSpeedMultiplier), 0))
Dim allowCamMove As Boolean = Not (IsMouseDown AndAlso IsShiftPressed)
If allowCamMove Then
Dim state As KeyboardState = Keyboard.GetState
If state(Key.W) Then
'camera.Move(moveSpeed, moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx)
savedCamPos = MyCamera.Position
End If
If state(Key.S) Then
'camera.Move(-moveSpeed, -moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx)
savedCamPos = MyCamera.Position
End If
If state(Key.A) Then
'camera.Move(-moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx)
End If
If state(Key.D) Then
'camera.Move(moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx)
End If
If state(Key.E) Then
'camera.Move(0, -moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx)
End If
If state(Key.Q) Then
'camera.Move(0, moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx)
End If
End If
End Sub
Private Sub Camera_NeedSelectedObject(sender As Object, e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject
e.Points = Nothing
End Sub
Private Sub MyCamera_PerspectiveChanged(sender As Object, e As EventArgs) Handles MyCamera.PerspectiveChanged
UpdateView()
End Sub
Private Sub ModelPreview_FormDisposed(sender As Object, e As EventArgs) Handles Me.Disposed
For Each rndr As Renderer In myModels.Values
rndr.ReleaseBuffers()
Next
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,35 @@
using global::System;
using global::System.Reflection;
using global::System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
// Werte der Assemblyattribute überprüfen
[assembly: AssemblyTitle("OpenGLRenderer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Pilzinsel64")]
[assembly: AssemblyProduct("OpenGLRenderer")]
[assembly: AssemblyCopyright("Copyright © Pilzinsel64 2018")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
[assembly: Guid("03d57392-1aac-468d-b5c9-30d927e685b5")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// <Assembly: AssemblyVersion("1.0.*")>
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,92 @@
using global::System.Drawing;
using global::OpenTK.Graphics.OpenGL;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
{
public class BoundingBox
{
public static void DrawSolid(System.Numerics.Vector3 scale, System.Numerics.Quaternion rot, System.Numerics.Vector3 pos, Color color, System.Numerics.Vector3 upper, System.Numerics.Vector3 lower)
{
GL.Disable(EnableCap.Blend);
GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.AlphaTest);
GL.PushMatrix();
GL.Translate(pos.X, pos.Y, pos.Z);
GL.Rotate(rot.X, 1f, 0f, 0f);
GL.Rotate(rot.Y, 0f, 1f, 0f);
GL.Rotate(rot.Z, 0f, 0f, 1f);
GL.Scale(scale.X, scale.Y, scale.Z);
GL.Begin(PrimitiveType.Quads);
GL.Color4(color);
GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-right of top face
GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-left of top face
GL.Vertex3(lower.X, upper.Y, upper.Z); // Bottom-left of top face
GL.Vertex3(upper.X, upper.Y, upper.Z); // Bottom-right of top face
GL.Vertex3(upper.X, lower.Y, lower.Z); // Top-right of bottom face
GL.Vertex3(lower.X, lower.Y, lower.Z); // Top-left of bottom face
GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-left of bottom face
GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-right of bottom face
GL.Vertex3(upper.X, upper.Y, upper.Z); // Top-Right of front face
GL.Vertex3(lower.X, upper.Y, upper.Z); // Top-left of front face
GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-left of front face
GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-right of front face
GL.Vertex3(upper.X, lower.Y, lower.Z); // Bottom-Left of back face
GL.Vertex3(lower.X, lower.Y, lower.Z); // Bottom-Right of back face
GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-Right of back face
GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-Left of back face
GL.Vertex3(lower.X, upper.Y, upper.Z); // Top-Right of left face
GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-Left of left face
GL.Vertex3(lower.X, lower.Y, lower.Z); // Bottom-Left of left face
GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-Right of left face
GL.Vertex3(upper.X, upper.Y, upper.Z); // Top-Right of left face
GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-Left of left face
GL.Vertex3(upper.X, lower.Y, lower.Z); // Bottom-Left of left face
GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-Right of left face
GL.Color4(Color.White);
GL.End();
GL.PopMatrix();
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.AlphaTest);
}
public static void Draw(System.Numerics.Vector3 scale, System.Numerics.Quaternion rot, System.Numerics.Vector3 pos, Color color, System.Numerics.Vector3 upper, System.Numerics.Vector3 lower)
{
GL.Disable(EnableCap.Blend);
GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.AlphaTest);
GL.PushMatrix();
GL.Translate(pos.X, pos.Y, pos.Z);
GL.Rotate(rot.X, 1f, 0f, 0f);
GL.Rotate(rot.Y, 0f, 1f, 0f);
GL.Rotate(rot.Z, 0f, 0f, 1f);
GL.Scale(scale.X, scale.Y, scale.Z);
GL.Begin(PrimitiveType.LineLoop);
GL.Color4(color);
GL.Vertex3(upper.X, upper.Y, lower.Z); // 1
GL.Vertex3(lower.X, upper.Y, lower.Z); // 2
GL.Vertex3(lower.X, upper.Y, upper.Z); // 3
GL.Vertex3(upper.X, upper.Y, lower.Z); // 1
GL.Vertex3(upper.X, upper.Y, upper.Z); // 4
GL.Vertex3(lower.X, upper.Y, upper.Z); // 3
GL.Vertex3(lower.X, lower.Y, upper.Z); // 7
GL.Vertex3(lower.X, lower.Y, lower.Z); // 6
GL.Vertex3(upper.X, lower.Y, lower.Z); // 5
GL.Vertex3(lower.X, lower.Y, upper.Z); // 7
GL.Vertex3(upper.X, lower.Y, upper.Z); // 8
GL.Vertex3(upper.X, lower.Y, lower.Z); // 5
GL.Vertex3(lower.X, upper.Y, lower.Z); // 2
GL.Vertex3(lower.X, lower.Y, lower.Z); // 6
GL.Vertex3(lower.X, upper.Y, upper.Z); // 3
GL.Vertex3(upper.X, lower.Y, upper.Z); // 8
GL.Vertex3(upper.X, upper.Y, upper.Z); // 4
GL.Vertex3(upper.X, lower.Y, lower.Z); // 5
GL.Color4(Color.White);
GL.End();
GL.PopMatrix();
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.AlphaTest);
}
}
}

View File

@@ -1,105 +0,0 @@
Imports System.Drawing
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Namespace RenderingN
Public Class BoundingBox
Public Shared Sub DrawSolid(scale As System.Numerics.Vector3, rot As System.Numerics.Quaternion, pos As System.Numerics.Vector3, color As Color, upper As System.Numerics.Vector3, lower As System.Numerics.Vector3)
GL.Disable(EnableCap.Blend)
GL.Disable(EnableCap.Texture2D)
GL.Disable(EnableCap.AlphaTest)
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale.X, scale.Y, scale.Z)
GL.Begin(PrimitiveType.Quads)
GL.Color4(color)
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-right of top face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-left of top face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Bottom-left of top face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Bottom-right of top face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Top-right of bottom face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Top-left of bottom face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of bottom face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of bottom face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of front face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-left of front face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of front face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of front face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of back face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Right of back face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Right of back face
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of back face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-Right of left face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Left of left face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Left of left face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-Right of left face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of left face
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of left face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of left face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-Right of left face
GL.Color4(Color.White)
GL.End()
GL.PopMatrix()
GL.Enable(EnableCap.Blend)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
End Sub
Public Shared Sub Draw(scale As Numerics.Vector3, rot As Numerics.Quaternion, pos As Numerics.Vector3, color As Color, upper As Numerics.Vector3, lower As Numerics.Vector3)
GL.Disable(EnableCap.Blend)
GL.Disable(EnableCap.Texture2D)
GL.Disable(EnableCap.AlphaTest)
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale.X, scale.Y, scale.Z)
GL.Begin(PrimitiveType.LineLoop)
GL.Color4(color)
GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1
GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1
GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7
GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7
GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2
GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8
GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Color4(Color.White)
GL.End()
GL.PopMatrix()
GL.Enable(EnableCap.Blend)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,34 @@
using global::System;
using global::System.Drawing;
using Bitmap = System.Drawing.Bitmap;
using global::System.Drawing.Imaging;
using global::OpenTK.Graphics.OpenGL;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
{
public class ContentPipe
{
public static int LoadTexture(string filepath)
{
var bitmap = new Bitmap(filepath);
return LoadTexture(bitmap);
}
public static int LoadTexture(Bitmap bitmap)
{
int id = GL.GenTexture();
LoadTexture(bitmap, id);
return id;
}
public static void LoadTexture(Bitmap bitmap, int id)
{
var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.BindTexture(TextureTarget.Texture2D, id);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);
bitmap.UnlockBits(bmpData);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Math.Truncate((decimal)TextureMinFilter.Linear));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Math.Truncate((decimal)TextureMagFilter.Linear));
}
}
}

View File

@@ -1,34 +0,0 @@
Imports System
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Bitmap = System.Drawing.Bitmap
Namespace RenderingN
Public Class ContentPipe
Public Shared Function LoadTexture(filepath As String) As Integer
Dim bitmap As New Bitmap(filepath)
Return LoadTexture(bitmap)
End Function
Public Shared Function LoadTexture(bitmap As Bitmap) As Integer
Dim id As Integer = GL.GenTexture()
LoadTexture(bitmap, id)
Return id
End Function
Public Shared Sub LoadTexture(bitmap As Bitmap, id As Integer)
Dim bmpData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)
GL.BindTexture(TextureTarget.Texture2D, id)
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0)
bitmap.UnlockBits(bmpData)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, CInt(Math.Truncate(TextureMinFilter.Linear)))
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, CInt(Math.Truncate(TextureMagFilter.Linear)))
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,11 @@
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
{
public enum RenderMode : byte
{
None = 0x0,
Fill = 0x1,
Outline = 0x2,
FillOutline = Fill | Outline
}
}

View File

@@ -1,10 +0,0 @@
Namespace RenderingN
Public Enum RenderMode As Byte
None = &H0
Fill = &H1
Outline = &H2
FillOutline = Fill Or Outline
End Enum
End Namespace

View File

@@ -0,0 +1,485 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using global::System.Drawing;
using Bitmap = global::System.Drawing.Bitmap;
using Color = global::System.Drawing.Color;
using Image = global::System.Drawing.Image;
using System.Linq;
using global::System.Threading;
using System.Threading.Tasks;
using global::System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using global::OpenTK;
using global::OpenTK.Graphics.OpenGL;
using global::Pilz.S3DFileParser;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
{
public class Renderer
{
private global::Pilz.S3DFileParser.Object3D obj3d;
private Dictionary<Image, int> dicTextureIDs = new global::System.Collections.Generic.Dictionary<global::System.Drawing.Image, global::System.Int32>();
private global::System.Collections.Generic.Dictionary<global::System.Drawing.Color, global::System.Int32> dicColorIDs = new global::System.Collections.Generic.Dictionary<global::System.Drawing.Color, global::System.Int32>();
private global::System.Drawing.Bitmap emptyTexture = null;
private global::System.Drawing.Bitmap lineTexture = null;
private global::System.Drawing.Bitmap selectedLineTexture = null;
public float ModelScaling { get; set; } = 1.0f;
public bool HasRendered { get; private set; } = false;
public global::System.Collections.Generic.List<global::System.Object> SelectedElements { get; private set; }
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> VertexBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>> IndicesBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>>();
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> UVBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> VertexColorBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> NormalBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
public global::Pilz.S3DFileParser.Object3D Model
{
get
{
return this.obj3d;
}
}
public Renderer(global::Pilz.S3DFileParser.Object3D obj3d)
{
this.obj3d = obj3d.ToOneMesh();
// Set Texture used for faces without texture
this.emptyTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.LightGray);
// Set Texture used for lines
this.lineTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.Black);
// Set Texture used for lines of selected faces
this.selectedLineTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.Orange);
}
private global::System.Drawing.Image ColorToTexture(global::System.Drawing.Color color)
{
var tex = new global::System.Drawing.Bitmap(1, 1);
tex.SetPixel(0, 0, color);
return tex;
}
/// <summary>
/// Updates the Data of a Vertex in the buffer.
/// </summary>
/// <param name="m">The Mesh where the Vertex is listed.</param>
/// <param name="v">The Vertex to update.</param>
public void UpdateVertexData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Vertex v)
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[m]);
var argdata = new global::OpenTK.Vector3((global::System.Single)v.X, (global::System.Single)v.Y, (global::System.Single)v.Z);
global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.Vertices.IndexOf(v)) * (global::OpenTK.Vector3.SizeInBytes)), global::OpenTK.Vector3.SizeInBytes, ref argdata);
}
/// <summary>
/// Updates the Data of a Normal in the buffer.
/// </summary>
/// <param name="m">The Mesh where the Vertex is listed.</param>
/// <param name="n">The Normal to update.</param>
public void UpdateNormalData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Normal n)
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.NormalBuffers[m]);
var argdata = new global::OpenTK.Vector3(n.X, n.Y, n.Z);
global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.Normals.IndexOf(n)) * (global::OpenTK.Vector3.SizeInBytes)), global::OpenTK.Vector3.SizeInBytes, ref argdata);
}
/// <summary>
/// Updates the Data of a Vertex Color in the buffer.
/// </summary>
/// <param name="m">The Mesh where the Vertex is listed.</param>
/// <param name="vc">The Vertex Color to update.</param>
public void UpdateVertexColorData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.VertexColor vc)
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexColorBuffers[m]);
var argdata = new global::OpenTK.Vector4(vc.R, vc.G, vc.B, vc.A);
global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.VertexColors.IndexOf(vc)) * (global::OpenTK.Vector4.SizeInBytes)), global::OpenTK.Vector4.SizeInBytes, ref argdata);
}
/// <summary>
/// Updates the Data of a UV in the buffer.
/// </summary>
/// <param name="m">The Mesh where the Vertex is listed.</param>
/// <param name="uv">The UV to update.</param>
public void UpdateUVData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.UV uv)
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.UVBuffers[m]);
var argdata = new global::OpenTK.Vector2(uv.U, uv.V);
global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.UVs.IndexOf(uv)) * (global::OpenTK.Vector2.SizeInBytes)), global::OpenTK.Vector2.SizeInBytes, ref argdata);
}
/// <summary>
/// Updates the indicies of a face in the buffer.
/// </summary>
/// <param name="m">The Mesh where the Vertex is listed.</param>
/// <param name="f">The Face to update.</param>
public void UpdateFaceIndicies(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Face f)
{
global::System.Int32 faceIndex = m.Faces.IndexOf(f);
global::System.Byte uintlen = (global::System.Byte)global::Microsoft.VisualBasic.Strings.Len(new uint());
var indicies = new global::OpenTK.Vector3((global::System.Single)m.Vertices.IndexOf(f.Points[0].Vertex), (global::System.Single)m.Vertices.IndexOf(f.Points[1].Vertex), (global::System.Single)m.Vertices.IndexOf(f.Points[2].Vertex));
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.IndicesBuffers[m][faceIndex]);
global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::System.Int32)(uintlen) * (faceIndex)), (global::System.Int32)uintlen, ref indicies);
}
/// <summary>
/// Replace an Image with a new one.
/// </summary>
/// <param name="oldImage"></param>
/// <param name="newImage"></param>
public void UpdateTexture(global::System.Drawing.Image oldImage, global::System.Drawing.Image newImage)
{
if (this.dicTextureIDs.ContainsKey(oldImage))
{
global::System.Int32 id = this.dicTextureIDs[oldImage];
this.dicTextureIDs.Remove(oldImage);
this.dicTextureIDs.Add(newImage, id);
global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)newImage, id);
}
}
/// <summary>
/// Updates an Image.
/// </summary>
/// <param name="image"></param>
public void UpdateTexture(global::System.Drawing.Image image)
{
if (this.dicTextureIDs.ContainsKey(image))
{
global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((this.dicTextureIDs[image]).ToString());
}
}
/// <summary>
/// Creates the Buffers and store the requied Data.
/// </summary>
public void RenderModel()
{
this.ReleaseBuffers();
foreach (global::Pilz.S3DFileParser.Mesh mesh in this.obj3d.Meshes)
{
var nibo = new global::System.Collections.Generic.List<global::System.Int32>();
global::System.Boolean enablecols = ((mesh.VertexColors.Count) > (0));
global::System.Boolean enablenorms = (((!(enablecols))) && ((mesh.Normals.Count) > (0)));
var verts = new global::System.Collections.Generic.List<global::OpenTK.Vector3>();
var uvs = new global::System.Collections.Generic.List<global::OpenTK.Vector2>();
var cols = new global::System.Collections.Generic.List<global::OpenTK.Vector4>();
var norms = new global::System.Collections.Generic.List<global::OpenTK.Vector3>();
global::System.UInt64 curvi = 0UL;
this.IndicesBuffers.Add(mesh, nibo);
for (global::System.Int32 i = 0, loopTo = (mesh.Faces.Count) - (1); i <= loopTo; i++)
{
{
var currentFace = mesh.Faces[i];
var indices = new List<UInt32>();
foreach (S3DFileParser.Point p in currentFace.Points)
{
indices.Add((global::System.UInt32)curvi);
curvi = (global::System.UInt64)(curvi + 1m);
if (p.Vertex is object)
{
verts.Add(new Vector3((Single)p.Vertex.X, (Single)p.Vertex.Y, (Single)p.Vertex.Z));
}
else
{
verts.Add(new Vector3(0f, 0f, 0f));
}
if (p.UV is object)
{
uvs.Add(new Vector2(p.UV.U, p.UV.V));
}
else
{
uvs.Add(new Vector2(0f, 0f));
}
if (((enablecols) && p.VertexColor is object))
{
cols.Add(new Vector4(p.VertexColor.R, p.VertexColor.G, p.VertexColor.B, p.VertexColor.A));
}
else
{
cols.Add(new Vector4(1f, 1f, 1f, 1f));
}
if (((enablenorms) && p.Normal is object))
{
norms.Add(new global::OpenTK.Vector3(p.Normal.X, p.Normal.Y, p.Normal.Z));
}
else
{
norms.Add(new global::OpenTK.Vector3(1f, 1f, 1f));
}
}
nibo.Add(GL.GenBuffer());
GL.BindBuffer(BufferTarget.ElementArrayBuffer, nibo[i]);
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)((Strings.Len(new uint())) * (indices.Count)), indices.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw);
if (currentFace.Material?.Image is object)
{
if (!(this.dicTextureIDs.ContainsKey(currentFace.Material.Image)))
{
this.dicTextureIDs.Add(currentFace.Material.Image, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)currentFace.Material.Image));
}
}
else if (currentFace.Material?.Color is object)
{
if (!(this.dicColorIDs.ContainsKey((global::System.Drawing.Color)currentFace.Material.Color)))
{
this.dicColorIDs.Add((global::System.Drawing.Color)currentFace.Material.Color, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)this.ColorToTexture((global::System.Drawing.Color)currentFace.Material.Color)));
}
}
else if (!(this.dicTextureIDs.ContainsKey(this.emptyTexture)))
{
this.dicTextureIDs.Add(this.emptyTexture, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture(this.emptyTexture));
}
}
}
global::System.Int32 nvbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer();
this.VertexBuffers.Add(mesh, nvbo);
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, nvbo);
global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector3.SizeInBytes) * (verts.Count)), verts.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw);
global::System.Int32 ntbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer();
this.UVBuffers.Add(mesh, ntbo);
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, ntbo);
global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector2.SizeInBytes) * (uvs.Count)), uvs.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw);
if (enablecols)
{
global::System.Int32 ncbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer();
this.VertexColorBuffers.Add(mesh, ncbo);
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, ncbo);
global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector4.SizeInBytes) * (cols.Count)), cols.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw);
}
if (enablenorms)
{
global::System.Int32 nnbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer();
this.NormalBuffers.Add(mesh, nnbo);
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, nnbo);
global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector3.SizeInBytes) * (norms.Count)), norms.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw);
}
}
if (!(this.dicTextureIDs.ContainsKey(this.lineTexture)))
{
this.dicTextureIDs.Add(this.lineTexture, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture(this.lineTexture));
}
this.HasRendered = true;
}
public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode)
{
this.DrawModel(mode, global::OpenTK.Vector3.Zero, global::OpenTK.Quaternion.Identity, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling));
}
public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode, global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot)
{
this.DrawModel(mode, pos, rot, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling));
}
public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode, global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot, global::OpenTK.Vector3 scale)
{
if ((mode == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.None))
return;
if (!(this.HasRendered))
return;
global::OpenTK.Graphics.OpenGL.GL.PushMatrix();
global::OpenTK.Graphics.OpenGL.GL.Translate(pos.X, pos.Y, pos.Z);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.X, 1f, 0f, 0f);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Y, 0f, 1f, 0f);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Z, 0f, 0f, 1f);
global::OpenTK.Graphics.OpenGL.GL.Scale(scale); // GL.Scale(scale.X, scale.Y, scale.Z)
global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray);
global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.TextureCoordArray);
foreach (global::Pilz.S3DFileParser.Mesh mesh in this.obj3d.Meshes)
{
if (this.VertexColorBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.ColorArray);
}
else if (this.NormalBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.NormalArray);
}
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[mesh]);
global::OpenTK.Graphics.OpenGL.GL.VertexPointer(3, global::OpenTK.Graphics.OpenGL.VertexPointerType.Float, 0, global::System.IntPtr.Zero);
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.UVBuffers[mesh]);
global::OpenTK.Graphics.OpenGL.GL.TexCoordPointer(2, global::OpenTK.Graphics.OpenGL.TexCoordPointerType.Float, 0, global::System.IntPtr.Zero);
if (this.VertexColorBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexColorBuffers[mesh]);
global::OpenTK.Graphics.OpenGL.GL.ColorPointer(4, global::OpenTK.Graphics.OpenGL.ColorPointerType.Float, 0, global::System.IntPtr.Zero);
}
else if (this.NormalBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.NormalBuffers[mesh]);
global::OpenTK.Graphics.OpenGL.GL.NormalPointer(global::OpenTK.Graphics.OpenGL.NormalPointerType.Float, 0, global::System.IntPtr.Zero);
}
for (global::System.Int32 i = 0, loopTo = (mesh.Faces.Count) - (1); i <= loopTo; i++)
{
var l = mesh.Faces[i];
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ElementArrayBuffer, this.IndicesBuffers[mesh][i]);
global::System.Boolean isEmptyTexture = l.Material?.Image is null;
global::System.Boolean isEmptyColor = l.Material?.Color is null;
void setMaterialTextureOrColor()
{
global::System.Int32 texID;
if (!(isEmptyTexture))
{
texID = this.dicTextureIDs[l.Material.Image];
}
else if (!(isEmptyColor))
{
texID = this.dicColorIDs[(global::System.Drawing.Color)l.Material.Color];
}
else
{
texID = this.dicTextureIDs[this.emptyTexture];
}
global::OpenTK.Graphics.OpenGL.GL.BindTexture(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, texID);
};
if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill))
{
setMaterialTextureOrColor();
if (!(isEmptyTexture))
{
global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapT, l.Material.Wrap.X);
global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapS, l.Material.Wrap.Y);
}
global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill);
global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero);
}
if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Outline)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Outline))
{
if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill))
{
global::OpenTK.Graphics.OpenGL.GL.BindTexture(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, this.dicTextureIDs[this.lineTexture]);
}
else
{
setMaterialTextureOrColor();
if (!(isEmptyTexture))
{
global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapT, l.Material.Wrap.X);
global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapS, l.Material.Wrap.Y);
}
}
global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Line);
global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero);
}
}
global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill); // Reset for RenderEngineOld
if (this.VertexColorBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.ColorArray);
}
else if (this.NormalBuffers.ContainsKey(mesh))
{
global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.NormalArray);
}
}
global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray);
global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.TextureCoordArray);
global::OpenTK.Graphics.OpenGL.GL.PopMatrix();
}
public void DrawFacePicking()
{
this.DrawFacePicking(global::OpenTK.Vector3.Zero, global::OpenTK.Quaternion.Identity, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling));
}
public void DrawFacePicking(global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot)
{
this.DrawFacePicking(pos, rot, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling));
}
public void DrawFacePicking(global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot, global::OpenTK.Vector3 scale)
{
if (!(this.HasRendered))
return;
global::OpenTK.Graphics.OpenGL.GL.PushMatrix();
global::OpenTK.Graphics.OpenGL.GL.Translate(pos.X, pos.Y, pos.Z);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.X, 1f, 0f, 0f);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Y, 0f, 1f, 0f);
global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Z, 0f, 0f, 1f);
global::OpenTK.Graphics.OpenGL.GL.Scale(scale);
global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray);
for (global::System.Int32 iMesh = 0, loopTo = (this.obj3d.Meshes.Count) - (1); iMesh <= loopTo; iMesh++)
{
var mesh = this.obj3d.Meshes[iMesh];
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[mesh]);
global::OpenTK.Graphics.OpenGL.GL.VertexPointer(3, global::OpenTK.Graphics.OpenGL.VertexPointerType.Float, 0, global::System.IntPtr.Zero);
for (global::System.Int32 iFace = 0, loopTo1 = (mesh.Faces.Count) - (1); iFace <= loopTo1; iFace++)
{
var l = mesh.Faces[iFace];
global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ElementArrayBuffer, this.IndicesBuffers[mesh][iFace]);
global::System.Int32 colorCode = (((0x20000000) + ((((iMesh) << (16))))) + (iFace));
global::OpenTK.Graphics.OpenGL.GL.Color4(global::System.Drawing.Color.FromArgb(colorCode)); // Color: "2f ff xx xx" -> where 'f' = mesh index and where 'x' is face index
global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill);
global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero);
}
global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill);
}
global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray);
global::OpenTK.Graphics.OpenGL.GL.PopMatrix();
}
public void ReleaseBuffers()
{
if (!(this.HasRendered))
return;
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.VertexBuffers)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.VertexBuffers.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.UVBuffers)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.UVBuffers.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.VertexColorBuffers)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.VertexColorBuffers.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.NormalBuffers)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.NormalBuffers.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>> kvp in this.IndicesBuffers)
{
foreach (global::System.Int32 i in kvp.Value)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(i);
kvp.Value.Clear();
}
this.IndicesBuffers.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::System.Drawing.Image, global::System.Int32> kvp in this.dicTextureIDs)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.dicTextureIDs.Clear();
foreach (global::System.Collections.Generic.KeyValuePair<global::System.Drawing.Color, global::System.Int32> kvp in this.dicColorIDs)
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
this.dicColorIDs.Clear();
this.HasRendered = false;
}
~Renderer()
{
// ReleaseBuffers()
}
}
}

View File

@@ -1,471 +0,0 @@
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports Pilz.S3DFileParser
Imports Bitmap = System.Drawing.Bitmap
Imports Color = System.Drawing.Color
Imports Image = System.Drawing.Image
Namespace RenderingN
Public Class Renderer
Private obj3d As Object3D
Private dicTextureIDs As New Dictionary(Of Image, Integer)
Private dicColorIDs As New Dictionary(Of Color, Integer)
Private emptyTexture As Bitmap = Nothing
Private lineTexture As Bitmap = Nothing
Private selectedLineTexture As Bitmap = Nothing
Public Property ModelScaling As Single = 1.0F
Public ReadOnly Property HasRendered As Boolean = False
Public ReadOnly Property SelectedElements As List(Of Object)
Private ReadOnly Property VertexBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property IndicesBuffers As New Dictionary(Of Mesh, List(Of Integer))
Private ReadOnly Property UVBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property VertexColorBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property NormalBuffers As New Dictionary(Of Mesh, Integer)
Public ReadOnly Property Model As Object3D
Get
Return obj3d
End Get
End Property
Public Sub New(obj3d As Object3D)
Me.obj3d = obj3d.ToOneMesh
'Set Texture used for faces without texture
emptyTexture = ColorToTexture(Color.LightGray)
'Set Texture used for lines
lineTexture = ColorToTexture(Color.Black)
'Set Texture used for lines of selected faces
selectedLineTexture = ColorToTexture(Color.Orange)
End Sub
Private Function ColorToTexture(color As Color) As Image
Dim tex As New Bitmap(1, 1)
tex.SetPixel(0, 0, color)
Return tex
End Function
''' <summary>
''' Updates the Data of a Vertex in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="v">The Vertex to update.</param>
Public Sub UpdateVertexData(m As Mesh, v As Vertex)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Vertices.IndexOf(v) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(v.X, v.Y, v.Z))
End Sub
''' <summary>
''' Updates the Data of a Normal in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="n">The Normal to update.</param>
Public Sub UpdateNormalData(m As Mesh, n As Normal)
GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Normals.IndexOf(n) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(n.X, n.Y, n.Z))
End Sub
''' <summary>
''' Updates the Data of a Vertex Color in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="vc">The Vertex Color to update.</param>
Public Sub UpdateVertexColorData(m As Mesh, vc As VertexColor)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.VertexColors.IndexOf(vc) * Vector4.SizeInBytes, IntPtr), Vector4.SizeInBytes, New Vector4(vc.R, vc.G, vc.B, vc.A))
End Sub
''' <summary>
''' Updates the Data of a UV in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="uv">The UV to update.</param>
Public Sub UpdateUVData(m As Mesh, uv As UV)
GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.UVs.IndexOf(uv) * Vector2.SizeInBytes, IntPtr), Vector2.SizeInBytes, New Vector2(uv.U, uv.V))
End Sub
''' <summary>
''' Updates the indicies of a face in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="f">The Face to update.</param>
Public Sub UpdateFaceIndicies(m As Mesh, f As Face)
Dim faceIndex As Integer = m.Faces.IndexOf(f)
Dim uintlen As Byte = Len(New UInteger)
Dim indicies As New Vector3(m.Vertices.IndexOf(f.Points(0).Vertex),
m.Vertices.IndexOf(f.Points(1).Vertex),
m.Vertices.IndexOf(f.Points(2).Vertex))
GL.BindBuffer(BufferTarget.ArrayBuffer, IndicesBuffers(m)(faceIndex))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(uintlen * faceIndex, IntPtr), uintlen, indicies)
End Sub
''' <summary>
''' Replace an Image with a new one.
''' </summary>
''' <param name="oldImage"></param>
''' <param name="newImage"></param>
Public Sub UpdateTexture(oldImage As Image, newImage As Image)
If dicTextureIDs.ContainsKey(oldImage) Then
Dim id As Integer = dicTextureIDs(oldImage)
dicTextureIDs.Remove(oldImage)
dicTextureIDs.Add(newImage, id)
ContentPipe.LoadTexture(newImage, id)
End If
End Sub
''' <summary>
''' Updates an Image.
''' </summary>
''' <param name="image"></param>
Public Sub UpdateTexture(image As Image)
If dicTextureIDs.ContainsKey(image) Then
ContentPipe.LoadTexture(dicTextureIDs(image))
End If
End Sub
''' <summary>
''' Creates the Buffers and store the requied Data.
''' </summary>
Public Sub RenderModel()
ReleaseBuffers()
For Each mesh As Mesh In obj3d.Meshes
Dim nibo As New List(Of Integer)
Dim enablecols As Boolean = mesh.VertexColors.Count > 0
Dim enablenorms As Boolean = (Not enablecols) AndAlso mesh.Normals.Count > 0
Dim verts As New List(Of Vector3)
Dim uvs As New List(Of Vector2)
Dim cols As New List(Of Vector4)
Dim norms As New List(Of Vector3)
Dim curvi As ULong = 0
IndicesBuffers.Add(mesh, nibo)
For i As Integer = 0 To mesh.Faces.Count - 1
With mesh.Faces(i)
Dim indices As New List(Of UInteger)
For Each p As S3DFileParser.Point In .Points
indices.Add(curvi)
curvi += 1
If p.Vertex IsNot Nothing Then
verts.Add(New Vector3(p.Vertex.X, p.Vertex.Y, p.Vertex.Z))
Else
verts.Add(New Vector3(0, 0, 0))
End If
If p.UV IsNot Nothing Then
uvs.Add(New Vector2(p.UV.U, p.UV.V))
Else
uvs.Add(New Vector2(0, 0))
End If
If enablecols AndAlso p.VertexColor IsNot Nothing Then
cols.Add(New Vector4(p.VertexColor.R, p.VertexColor.G, p.VertexColor.B, p.VertexColor.A))
Else
cols.Add(New Vector4(1, 1, 1, 1))
End If
If enablenorms AndAlso p.Normal IsNot Nothing Then
norms.Add(New Vector3(p.Normal.X, p.Normal.Y, p.Normal.Z))
Else
norms.Add(New Vector3(1, 1, 1))
End If
Next
nibo.Add(GL.GenBuffer)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, nibo(i))
GL.BufferData(
BufferTarget.ElementArrayBuffer,
CType(Len(New UInteger) * indices.Count, IntPtr),
indices.ToArray,
BufferUsageHint.StaticDraw)
If .Material?.Image IsNot Nothing Then
If Not dicTextureIDs.ContainsKey(.Material.Image) Then
dicTextureIDs.Add(.Material.Image, ContentPipe.LoadTexture(.Material.Image))
End If
ElseIf .Material?.Color IsNot Nothing Then
If Not dicColorIDs.ContainsKey(.Material.Color) Then
dicColorIDs.Add(.Material.Color, ContentPipe.LoadTexture(ColorToTexture(.Material.Color)))
End If
Else
If Not dicTextureIDs.ContainsKey(emptyTexture) Then
dicTextureIDs.Add(emptyTexture, ContentPipe.LoadTexture(emptyTexture))
End If
End If
End With
Next
Dim nvbo As Integer = GL.GenBuffer
VertexBuffers.Add(mesh, nvbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, nvbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector3.SizeInBytes * verts.Count, IntPtr),
verts.ToArray,
BufferUsageHint.StaticDraw
)
Dim ntbo As Integer = GL.GenBuffer
UVBuffers.Add(mesh, ntbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, ntbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector2.SizeInBytes * uvs.Count, IntPtr),
uvs.ToArray,
BufferUsageHint.StaticDraw
)
If enablecols Then
Dim ncbo As Integer = GL.GenBuffer
VertexColorBuffers.Add(mesh, ncbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, ncbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector4.SizeInBytes * cols.Count, IntPtr),
cols.ToArray,
BufferUsageHint.StaticDraw
)
End If
If enablenorms Then
Dim nnbo As Integer = GL.GenBuffer
NormalBuffers.Add(mesh, nnbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, nnbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector3.SizeInBytes * norms.Count, IntPtr),
norms.ToArray,
BufferUsageHint.StaticDraw
)
End If
Next
If Not dicTextureIDs.ContainsKey(lineTexture) Then
dicTextureIDs.Add(lineTexture, ContentPipe.LoadTexture(lineTexture))
End If
_HasRendered = True
End Sub
Public Sub DrawModel(mode As RenderMode)
DrawModel(mode, Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion)
DrawModel(mode, pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion, scale As Vector3)
If mode = RenderMode.None Then Return
If Not _HasRendered Then Return
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale) 'GL.Scale(scale.X, scale.Y, scale.Z)
GL.EnableClientState(ArrayCap.VertexArray)
GL.EnableClientState(ArrayCap.TextureCoordArray)
For Each mesh As Mesh In obj3d.Meshes
If VertexColorBuffers.ContainsKey(mesh) Then
GL.EnableClientState(ArrayCap.ColorArray)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.EnableClientState(ArrayCap.NormalArray)
End If
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh))
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero)
GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(mesh))
GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero)
If VertexColorBuffers.ContainsKey(mesh) Then
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(mesh))
GL.ColorPointer(4, ColorPointerType.Float, 0, IntPtr.Zero)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(mesh))
GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero)
End If
For i As Integer = 0 To mesh.Faces.Count - 1
Dim l As Face = mesh.Faces(i)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(i))
Dim isEmptyTexture As Boolean = l.Material?.Image Is Nothing
Dim isEmptyColor As Boolean = l.Material?.Color Is Nothing
Dim setMaterialTextureOrColor =
Sub()
Dim texID As Integer
If Not isEmptyTexture Then
texID = dicTextureIDs(l.Material.Image)
ElseIf Not isEmptyColor Then
texID = dicColorIDs(l.Material.Color)
Else
texID = dicTextureIDs(emptyTexture)
End If
GL.BindTexture(TextureTarget.Texture2D, texID)
End Sub
If (mode And RenderMode.Fill) = RenderMode.Fill Then
setMaterialTextureOrColor()
If Not isEmptyTexture Then
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y)
End If
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
End If
If (mode And RenderMode.Outline) = RenderMode.Outline Then
If (mode And RenderMode.Fill) = RenderMode.Fill Then
GL.BindTexture(TextureTarget.Texture2D, dicTextureIDs(lineTexture))
Else
setMaterialTextureOrColor()
If Not isEmptyTexture Then
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y)
End If
End If
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
End If
Next
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) 'Reset for RenderEngineOld
If VertexColorBuffers.ContainsKey(mesh) Then
GL.DisableClientState(ArrayCap.ColorArray)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.DisableClientState(ArrayCap.NormalArray)
End If
Next
GL.DisableClientState(ArrayCap.VertexArray)
GL.DisableClientState(ArrayCap.TextureCoordArray)
GL.PopMatrix()
End Sub
Public Sub DrawFacePicking()
DrawFacePicking(Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion)
DrawFacePicking(pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion, scale As Vector3)
If Not _HasRendered Then Return
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale)
GL.EnableClientState(ArrayCap.VertexArray)
For iMesh As Integer = 0 To obj3d.Meshes.Count - 1
Dim mesh As Mesh = obj3d.Meshes(iMesh)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh))
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero)
For iFace As Integer = 0 To mesh.Faces.Count - 1
Dim l As Face = mesh.Faces(iFace)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(iFace))
Dim colorCode As Integer = &H20000000 + (iMesh << 16) + iFace
GL.Color4(Color.FromArgb(colorCode)) 'Color: "2f ff xx xx" -> where 'f' = mesh index and where 'x' is face index
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
Next
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
Next
GL.DisableClientState(ArrayCap.VertexArray)
GL.PopMatrix()
End Sub
Public Sub ReleaseBuffers()
If Not HasRendered Then Return
For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexBuffers
GL.DeleteBuffer(kvp.Value)
Next
VertexBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In UVBuffers
GL.DeleteBuffer(kvp.Value)
Next
UVBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexColorBuffers
GL.DeleteBuffer(kvp.Value)
Next
VertexColorBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In NormalBuffers
GL.DeleteBuffer(kvp.Value)
Next
NormalBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, List(Of Integer)) In IndicesBuffers
For Each i As Integer In kvp.Value
GL.DeleteBuffer(i)
Next
kvp.Value.Clear()
Next
IndicesBuffers.Clear()
For Each kvp As KeyValuePair(Of Image, Integer) In dicTextureIDs
GL.DeleteBuffer(kvp.Value)
Next
dicTextureIDs.Clear()
For Each kvp As KeyValuePair(Of Color, Integer) In dicColorIDs
GL.DeleteBuffer(kvp.Value)
Next
dicColorIDs.Clear()
_HasRendered = False
End Sub
Protected Overrides Sub Finalize()
'ReleaseBuffers()
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,69 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
// ------------------------------------------------------------------------------
using System.Diagnostics;
using Microsoft.VisualBasic;
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My.Resources
{
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
/// <summary>
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[DebuggerNonUserCode()]
[System.Runtime.CompilerServices.CompilerGenerated()]
[HideModuleName()]
internal static class Resources
{
private static System.Resources.ResourceManager resourceMan;
private static System.Globalization.CultureInfo resourceCulture;
/// <summary>
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
/// </summary>
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Resources.ResourceManager ResourceManager
{
get
{
if (ReferenceEquals(resourceMan, null))
{
var temp = new System.Resources.ResourceManager("Pilz.Drawing.Drawing3D.OpenGLFactory.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
/// </summary>
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>