3 Replies - 2124 Views - Last Post: 21 September 2012 - 07:43 AM

#1 rex64  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 168
  • Joined: 31-January 12

nullable Vector3

Posted 20 September 2012 - 05:41 PM

What do you recommend? I thought the question mark (?) made it nullable?

Quote

Error 94 Type of conditional expression cannot be determined because there is no implicit conversion between 'Microsoft.Xna.Framework.Vector3' and '<null>' C 349 40 3DgameTest


        Vector3? GetRayPlaneIntersectionPoint(Ray ray, Plane plane)
        {
            float? distance = ray.Intersects(plane);
            return distance.HasValue ? ray.Position + ray.Direction * distance.Value : null;
        }



Is This A Good Question/Topic? 0
  • +

Replies To: nullable Vector3

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: nullable Vector3

Posted 21 September 2012 - 05:45 AM

I believe the problem occurs because you cannot make a method type declaration nullable. Can't say that I've ever tried, so if I am wrong here, I'd appreciate someone else letting me know. You will have to have a field that is nullable, and a Vector3 method that returns a Vector3:
Vector3? nullableVec;

Vector3 GetRayPlaneIntersectionPoint(Ray ray, Plane plane)
{
    float? distance = ray.Intersects(plane);
    return distance.HasValue ? ray.Position + ray.Direction * distance.Value : null;
}

nullableVec = GetRayPlaneIntersectionPoint(ray, plane);



Something similar to the above code should work. I don't have my IDE in front of me right this second, so I can't test it, but hopefully you can make sense of what I've written.

This post has been edited by Kilorn: 21 September 2012 - 05:46 AM

Was This Post Helpful? 0
  • +
  • -

#3 rex64  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 168
  • Joined: 31-January 12

Re: nullable Vector3

Posted 21 September 2012 - 07:10 AM

I get the same error on the function. I copied this function from online, so I am not very familiar with null able or shorthand.

Error 12 Type of conditional expression cannot be determined because there is no implicit conversion between 'Microsoft.Xna.Framework.Vector3' and '<null>' clsMath.cs 349 40 3DgameTest
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: nullable Vector3

Posted 21 September 2012 - 07:43 AM

Is there a specific reason that you need it to be null and not just (0, 0, 0)? Changing the last line of the return statement from 'null' to Vector3.Zero will get rid of your error, but the vector3 will definitely not be null.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1