🔒 Locked
🎮 Unity
[.net] Normal.Normalize() problem (C#)
Advertisement
Original Post
I have a problem with Normal.Normalize() method in CustomVertex.PositionNormal structure. It doesn't work for me at all. Here is a simple code which i use for testing: CustomVertex.PositionNormal[] verts; verts = new CustomVertex.PositionNormal[1]; verts[0].Normal = new Vector3(5, 0, 0); verts[0].Normal.Normalize(); In my case last line of the code does nothing at all. verts[0].Normal vector is stays unchanged (5, 0, 0). But if i try like this: Vector3 test = new Vector3(5, 0, 0); test.Normalize(); test vector becomes normalized as it should (1,0,0). So the question is am i doing something wrong or Normalize() method is broken in CustomVertex structures?
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?
P.S. As for Managed DirectX being a trash, i'm aware of that. I'm beginner in C#. I chose Managed DirectX because i have an Windows Form application and i need to have a small control with 3D graphics inside the main window. I've found a couple of ready to use Managed DirectX controls which i could use, and began to learn Managed DirectX.
I thought that XNA is not suitable for such application, because it's targeted for games, which usually use whole window. If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.
P.S. As for Managed DirectX being a trash, i'm aware of that. I'm beginner in C#. I chose Managed DirectX because i have an Windows Form application and i need to have a small control with 3D graphics inside the main window. I've found a couple of ready to use Managed DirectX controls which i could use, and began to learn Managed DirectX.
I thought that XNA is not suitable for such application, because it's targeted for games, which usually use whole window. If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.
Quote:
Original post by Icos
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?
P.S. As for Managed DirectX being a trash, i'm aware of that. I'm beginner in C#. I chose Managed DirectX because i have an Windows Form application and i need to have a small control with 3D graphics inside the main window. I've found a couple of ready to use Managed DirectX controls which i could use, and began to learn Managed DirectX.
I thought that XNA is not suitable for such application, because it's targeted for games, which usually use whole window. If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.
It takes a bit of work (not too much, there's am easy sample on the XNA homepage) but it is easy to host XNA inside a control on a form. XNA is also much easier to develop for than SlimDX since it was designed with managed languages in mind, where as SlimDX is more just a wrapper for native C++.
Both of those options are far better than using Managed DirectX though.
Quote:
XNA is also much easier to develop for than SlimDX since it was designed with managed languages in mind, where as SlimDX is more just a wrapper for native C++.
That's not particularly accurate. XNA is easier to develop for/with because it's significantly higher level than SlimDX, and was designed with that in mind. SlimDX goes to great lengths to be an elegant managed library, and with a few minor exceptions does so very well. It's just by nature a lower level construct.
Quote:
Original post by Icos
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?
Yes, this is caused by Vector3 being a struct, ergo it being a value type. When you read the property, you actually get a copy of the original Vector3 struct (not a reference to it), and by calling Normalize you just modify your copy, not the original.
What you'd need to do in this case is something like this:
verts[0].Normal = Vector3.Normalize(verts[0].Normal);
Quote:
Original post by jpetrie
That's not particularly accurate. XNA is easier to develop for/with because it's significantly higher level than SlimDX, and was designed with that in mind. SlimDX goes to great lengths to be an elegant managed library, and with a few minor exceptions does so very well. It's just by nature a lower level construct.
You're right. Sorry, I suppose I was generalizing a bit too much.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement