Sign in to follow this  
Icos

[.net] Normal.Normalize() problem (C#)

Recommended Posts

Icos    100
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?

Share this post


Link to post
Share on other sites
Promit    13246
It's been a long time since I've used Managed DirectX (which is deprecated, long gone trash, by the way) but I'm guessing that Normal is a property, which means you have to set it. You can't just alter it in place like that.

Share this post


Link to post
Share on other sites
Icos    100
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.

Share this post


Link to post
Share on other sites
Icos    100
Yeah, i know about SlimDX too, but i'm beginner and i couldn't find enough sample projects for it, only basic documentation. What do you recommend to use in my case? XNA or SlimDX?

Share this post


Link to post
Share on other sites
Flimflam    665
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.

Share this post


Link to post
Share on other sites
jpetrie    13161
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.

Share this post


Link to post
Share on other sites
SirViver    136
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);

Share this post


Link to post
Share on other sites
Icos    100
[quote]Original post by Flimflam
Quote:
there's am easy sample on the XNA homepage

You mean this one?
http://creators.xna.com/en-US/sample/winforms_series1

Share this post


Link to post
Share on other sites
Flimflam    665
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this