DirectX Topics include: Managed DirectX (DX9)

Go Back  Xtreme .NET Talk > .NET > Graphics and Multimedia > DirectX > Debug error "Cannot convert from double to float...


Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2012, 09:53 AM
SleepingTroll SleepingTroll is offline
Newcomer
 
Join Date: Feb 2012
Posts: 12
SleepingTroll is on a distinguished road
Default Debug error "Cannot convert from double to float...



Velocity[a] is a Vector3 type (all doubles), Proximity is a double as is Influence. The highlighted code produces a cannot convert double to float error... I have tried (double)0 and that did not solve the problem. Any ideas?

Code:
Velocity[a] = (new Vector3(
    Proximity.X != 0 ? Velocity[a].X + (1/(Influence * Proximity.X)) : Velocity[a].X, 
    Proximity.Y != 0 ? Velocity[a].Y + (1/(Influence * Proximity.Y)) : Velocity[a].Y,
    Proximity.Z != 0 ? Velocity[a].Z + (1/(Influence * Proximity.Z)) : Velocity[a].Z
));

Last edited by snarfblam; 04-02-2012 at 05:52 PM. Reason: [Code] tags and formatting help *a lot*
Reply With Quote
  #2  
Old 04-02-2012, 06:01 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Ultimate Contributor

Preferred language:
C#, VB
 
Join Date: Jun 2003
Location: USA
Posts: 2,097
snarfblam will become famous soon enough
Default Re: Debug error "Cannot convert from double to float...

You're code is a bit hard to read. While that might sound nit-picky, and it's a subjective thing, when code is more readable, it is easier to understand and reason about it, especially at a glance. It also helps us help you.

The documentation for Vector3 states that the fields are floats, not doubles. You either need to cast to float, or make sure that all of your variables are floats rather than doubles. Something like this should work.

Code:
Velocity[a] = (new Vector3(
    Proximity.X != 0 ? 
        (float)(Velocity[a].X + (1/(Influence * Proximity.X))) : 
        Velocity[a].X, 
    Proximity.Y != 0 ? 
        (float)(Velocity[a].Y + (1/(Influence * Proximity.Y))) :
        Velocity[a].Y,
    Proximity.Z != 0 ? 
        (float)(Velocity[a].Z + (1/(Influence * Proximity.Z))) :
        Velocity[a].Z
));
__________________
e
Reply With Quote
  #3  
Old 04-03-2012, 10:16 AM
SleepingTroll SleepingTroll is offline
Newcomer
 
Join Date: Feb 2012
Posts: 12
SleepingTroll is on a distinguished road
Default Re: Debug error "Cannot convert from double to float...

I had assumed that a Vector3 type used double values... bad assumption!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Float Double problem. Jelmer General 2 03-02-2006 09:29 AM
Double run code behind if table has attribute background="#00000" karlhaak ASP.NET 1 08-10-2004 02:27 PM
convert string to float c# cathiec General 4 03-11-2004 10:21 AM
Cast from string "VelvetBoo" to type 'Double' is not valid cmaras Database / XML / Reporting 7 11-03-2003 11:23 AM
erorr saying Cast from string "67 85 90 " to type 'Double' is not valid. I don't even bobmack37 General 2 04-22-2003 10:52 PM

Advertisement:







Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe