C# pořád chyby i když dělám podle knížky – .NET – Fórum – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

C# pořád chyby i když dělám podle knížky  – .NET – Fórum – Programujte.comC# pořád chyby i když dělám podle knížky – .NET – Fórum – Programujte.com

 

Zuben0
Stálý člen
17. 2. 2010   #1
-
0
-

knižka: Programujeme 3D hry v jazyce C#

Error   11      The name 'zarizeni' does not exist in the current context

C:\Documents and Settings\Zuben\My Documents\Visual Studio
Projects\Konvicka\Konvicka.cs
152 13 Konvicka_2005

Error 12 'Microsoft.Samples.DirectX.UtilityToolkit.DeviceEventArgs.Device'
is a 'field' but is used like a 'method'
C:\Documents and Settings\Zuben\My Documents\Visual Studio
Projects\Konvicka\Konvicka.cs
152 26 Konvicka_2005

Error 13 The name 'zarizeni' does not exist in the current context
C:\Documents and Settings\Zuben\My Documents\Visual Studio P
rojects\Konvicka\Konvicka.cs
153 40 Konvicka_2005

...


a dál všechny stejného typu, nevím co s tím může být. Prosím pomoc, mockrát díky.

Nahlásit jako SPAM
IP: 90.176.213.–
z_moravec
~ Redaktor
+3
Posthunter
17. 2. 2010   #2
-
0
-

Bez kódu ti asi těžko někdo pomůže.

Nahlásit jako SPAM
IP: 83.240.110.–
Spát lze čtyři hodiny denně, spát déle je nemístný přepych.
Thomas Alva Edison
Zuben0
Stálý člen
17. 2. 2010   #3
-
0
-

Omlouvám se, tady je konvicka.cs

//-----------------------------------------------------------------------------

// File: Konvicka.cs
//
// Starting point for new Direct3D applications
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


//#define DEBUG_VS // Uncomment this line to debug vertex shaders
//#define DEBUG_PS // Uncomment this line to debug pixel shaders

using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.Samples.DirectX.UtilityToolkit;



namespace KonvickaSample
{
/// <summary>Konvicka Sample Class</summary>
public class Konvicka : IFrameworkCallback, IDeviceCreation
{
#region Creation
/// <summary>Create a new instance of the class</summary>
public Konvicka(Framework f)
{
// Store framework
sampleFramework = f;
// Create dialogs
hud = new Dialog(sampleFramework);
sampleUi = new Dialog(sampleFramework);
}
#endregion
private Mesh konvickaMesh = null;
private Material konvickaMaterial;
// Variables
private Framework sampleFramework = null; // Framework for samples
private Font statsFont = null; // Font for drawing text
private Sprite textSprite = null; // Sprite for batching text calls
private Effect effect = null; // D3DX Effect Interface
private ModelViewerCamera camera = new ModelViewerCamera(); // A model viewing camera
private bool isHelpShowing = true; // If true, renders the UI help text
private Dialog hud = null; // dialog for standard controls
private Dialog sampleUi = null; // dialog for sample specific controls

// HUD Ui Control constants
private const int ToggleFullscreen = 1;
private const int ToggleReference = 3;
private const int ChangeDevice = 4;

/// <summary>
/// Called during device initialization, this code checks the device for some
/// minimum set of capabilities, and rejects those that don't pass by returning false.
/// </summary>
public bool IsDeviceAcceptable(Caps caps, Format adapterFormat, Format backBufferFormat, bool windowed)
{
// Skip back buffer formats that don't support alpha blending
if (!Manager.CheckDeviceFormat(caps.AdapterOrdinal, caps.DeviceType, adapterFormat,
Usage.QueryPostPixelShaderBlending, ResourceType.Textures, backBufferFormat))
return false;

return true;
}

/// <summary>
/// This callback function is called immediately before a device is created to allow the
/// application to modify the device settings. The supplied settings parameter
/// contains the settings that the framework has selected for the new device, and the
/// application can make any desired changes directly to this structure. Note however that
/// the sample framework will not correct invalid device settings so care must be taken
/// to return valid device settings, otherwise creating the Device will fail.
/// </summary>
public void ModifyDeviceSettings(DeviceSettings settings, Caps caps)
{
// If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW
// then switch to SWVP.
if ( (!caps.DeviceCaps.SupportsHardwareTransformAndLight) ||
(caps.VertexShaderVersion < new Version(1,1)) )
{
settings.BehaviorFlags = CreateFlags.SoftwareVertexProcessing;
}
else
{
settings.BehaviorFlags = CreateFlags.HardwareVertexProcessing;
}

// This application is designed to work on a pure device by not using
// any get methods, so create a pure device if supported and using HWVP.
if ( (caps.DeviceCaps.SupportsPureDevice) &&
((settings.BehaviorFlags & CreateFlags.HardwareVertexProcessing) != 0 ) )
settings.BehaviorFlags |= CreateFlags.PureDevice;

// Debugging vertex shaders requires either REF or software vertex processing
// and debugging pixel shaders requires REF.
#if(DEBUG_VS)
if (settings.DeviceType != DeviceType.Reference )
{
settings.BehaviorFlags &= ~CreateFlags.HardwareVertexProcessing;
settings.BehaviorFlags |= CreateFlags.SoftwareVertexProcessing;
}
#endif
#if(DEBUG_PS)
settings.DeviceType = DeviceType.Reference;
#endif
// For the first device created if its a REF device, optionally display a warning dialog box
if (settings.DeviceType == DeviceType.Reference)
{
Utility.DisplaySwitchingToRefWarning(sampleFramework, "Konvicka");
}

}

/// <summary>
/// This event will be fired immediately after the Direct3D device has been
/// created, which will happen during application initialization and windowed/full screen
/// toggles. This is the best location to create Pool.Managed resources since these
/// resources need to be reloaded whenever the device is destroyed. Resources created
/// here should be released in the Disposing event.
/// </summary>
private void OnCreateDevice(object sender, DeviceEventArgs e)
{
// Initialize the stats font
statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
, "Arial");

// Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the
// shader debugger. Debugging vertex shaders requires either REF or software vertex
// processing, and debugging pixel shaders requires REF. The
// ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the
// shader debugger. It enables source level debugging, prevents instruction
// reordering, prevents dead code elimination, and forces the compiler to compile
// against the next higher available software target, which ensures that the
// unoptimized shaders do not exceed the shader model limitations. Setting these
// flags will cause slower rendering since the shaders will be unoptimized and
// forced into software. See the DirectX documentation for more information about
// using the shader debugger.
ShaderFlags shaderFlags = ShaderFlags.NotCloneable;
#if(DEBUG_VS)
shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
#endif
#if(DEBUG_PS)
shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
#endif
// Read the D3DX effect file
string path = Utility.FindMediaFile("Konvicka.fx");
effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device,
path, null, null, shaderFlags, null);
//Mesh a material
zarizeni = e.Device();
konvickaMesh = Mesh.Teapot(zarizeni);
konvickaMaterial = new Material();
konvickaMaterial.DiffuseColor = new ColorValue(1.0f, 1.0f, 1.0f, 10f);
// Setup the camera's view parameters
camera.SetViewParameters(new Vector3(0.0f, 0.0f, -5.0f), Vector3.Empty);
}

/// <summary>
/// This event will be fired immediately after the Direct3D device has been
/// reset, which will happen after a lost device scenario. This is the best location to
/// create Pool.Default resources since these resources need to be reloaded whenever
/// the device is lost. Resources created here should be released in the OnLostDevice
/// event.
/// </summary>
private void OnResetDevice(object sender, DeviceEventArgs e)
{
SurfaceDescription desc = e.BackBufferDescription;
// Create a sprite to help batch calls when drawing many lines of text
textSprite = new Sprite(e.Device);

// Setup the camera's projection parameters
float aspectRatio = (float)desc.Width / (float)desc.Height;
camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
camera.SetWindow(desc.Width, desc.Height);

// Setup UI locations
hud.SetLocation(desc.Width-170, 0);
hud.SetSize(170,170);
sampleUi.SetLocation(desc.Width - 170, desc.Height - 350);
sampleUi.SetSize(170,300);
}

/// <summary>
/// This event function will be called fired after the Direct3D device has
/// entered a lost state and before Device.Reset() is called. Resources created
/// in the OnResetDevice callback should be released here, which generally includes all
/// Pool.Default resources. See the "Lost Devices" section of the documentation for
/// information about lost devices.
/// </summary>
private void OnLostDevice(object sender, EventArgs e)
{
if (textSprite != null)
{
textSprite.Dispose();
textSprite = null;
}
}

/// <summary>
/// This callback function will be called immediately after the Direct3D device has
/// been destroyed, which generally happens as a result of application termination or
/// windowed/full screen toggles. Resources created in the OnCreateDevice callback
/// should be released here, which generally includes all Pool.Managed resources.
/// </summary>
private void OnDestroyDevice(object sender, EventArgs e)
{
}

/// <summary>
/// This callback function will be called once at the beginning of every frame. This is the
/// best location for your application to handle updates to the scene, but is not
/// intended to contain actual rendering calls, which should instead be placed in the
/// OnFrameRender callback.
/// </summary>
public void OnFrameMove(Device device, double appTime, float elapsedTime)
{
// Update the camera's position based on user input
camera.FrameMove(elapsedTime);
}

/// <summary>
/// This callback function will be called at the end of every frame to perform all the
/// rendering calls for the scene, and it will also be called if the window needs to be
/// repainted. After this function has returned, the sample framework will call
/// Device.Present to display the contents of the next buffer in the swap chain
/// </summary>
public void OnFrameRender(Device device, double appTime, float elapsedTime)
{
bool beginSceneCalled = false;

// Clear the render target and the zbuffer
device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, 0x002D32AA, 1.0f, 0);
try
{
device.BeginScene();
beginSceneCalled = true;

// Update the effect's variables. Instead of using strings, it would
// be more efficient to cache a handle to the parameter by calling
// Effect.GetParameter
effect.SetValue("worldViewProjection", camera.WorldMatrix * camera.ViewMatrix * camera.ProjectionMatrix);
effect.SetValue("worldMatrix", camera.WorldMatrix);
effect.SetValue("appTime", (float)appTime);

// Show frame rate
RenderText();

// Show UI
hud.OnRender(elapsedTime);
sampleUi.OnRender(elapsedTime);
}
finally
{
if (beginSceneCalled)
device.EndScene();
}
}

/// <summary>
/// Render the help and statistics text. This function uses the Font object for
/// efficient text rendering.
/// </summary>
private void RenderText()
{
TextHelper txtHelper = new TextHelper(statsFont, textSprite, 15);

// Output statistics
txtHelper.Begin();
txtHelper.SetInsertionPoint(5,5);
txtHelper.SetForegroundColor(System.Drawing.Color.Yellow);
txtHelper.DrawTextLine(sampleFramework.FrameStats);
txtHelper.DrawTextLine(sampleFramework.DeviceStats);

txtHelper.SetForegroundColor(System.Drawing.Color.White);
txtHelper.DrawTextLine("Put some status text here.");

// Draw help
if (isHelpShowing)
{
txtHelper.SetInsertionPoint(10, sampleFramework.BackBufferSurfaceDescription.Height-15*6);
txtHelper.SetForegroundColor(System.Drawing.Color.DarkOrange);
txtHelper.DrawTextLine("Controls (F1 to hide):");

txtHelper.SetInsertionPoint(40, sampleFramework.BackBufferSurfaceDescription.Height-15*5);
txtHelper.DrawTextLine("Help Item Misc: X");
txtHelper.DrawTextLine("Quit: Esc");
txtHelper.DrawTextLine("Hide help: F1");
}
else
{
txtHelper.SetInsertionPoint(10, sampleFramework.BackBufferSurfaceDescription.Height-15*2);
txtHelper.SetForegroundColor(System.Drawing.Color.White);
txtHelper.DrawTextLine("Press F1 for help");
}

txtHelper.End();
}

/// <summary>
/// As a convenience, the sample framework inspects the incoming windows messages for
/// keystroke messages and decodes the message parameters to pass relevant keyboard
/// messages to the application. The framework does not remove the underlying keystroke
/// messages, which are still passed to the application's MsgProc callback.
/// </summary>
private void OnKeyEvent(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case System.Windows.Forms.Keys.F1:
isHelpShowing = !isHelpShowing;
break;
}
}

/// <summary>
/// Before handling window messages, the sample framework passes incoming windows
/// messages to the application through this callback function. If the application sets
/// noFurtherProcessing to true, the sample framework will not process the message
/// </summary>
public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
{
// Give the dialog a chance to handle the message first
noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
if (noFurtherProcessing)
return IntPtr.Zero;

noFurtherProcessing = sampleUi.MessageProc(hWnd, msg, wParam, lParam);
if (noFurtherProcessing)
return IntPtr.Zero;

// Pass all remaining windows messages to camera so it can respond to user input
camera.HandleMessages(hWnd, msg, wParam, lParam);

return IntPtr.Zero;
}

/// <summary>
/// Initializes the application
/// </summary>
public void InitializeApplication()
{
int y = 10;
// Initialize the HUD
Button fullScreen = hud.AddButton(ToggleFullscreen,"Toggle full screen", 35, y, 125,22);
Button toggleRef = hud.AddButton(ToggleReference,"Toggle reference (F3)", 35, y += 24, 125,22);
Button changeDevice = hud.AddButton(ChangeDevice,"Change Device (F2)", 35, y += 24, 125,22);
// Hook the button events for when these items are clicked
fullScreen.Click += new EventHandler(OnFullscreenClicked);
toggleRef.Click += new EventHandler(OnRefClicked);
changeDevice.Click += new EventHandler(OnChangeDeviceClicked);

// Now add the sample specific UI
y = 10;
const int ComboBox1 = ChangeDevice + 1;
const int CheckBox1 = ChangeDevice + 2;
const int CheckBox2 = ChangeDevice + 3;
const int Radiobutton1 = ChangeDevice + 4;
const int Radiobutton2 = ChangeDevice + 5;
const int Radiobutton3 = ChangeDevice + 6;
const int Button1 = ChangeDevice + 7;
const int Button2 = ChangeDevice + 8;
const int Radiobutton4 = ChangeDevice + 9;
const int Radiobutton5 = ChangeDevice + 10;
const int SliderControl = ChangeDevice + 11;

ComboBox cb1 = sampleUi.AddComboBox(ComboBox1, 35, y +=24, 125, 22);
for (int i = 0; i < 50; i++) cb1.AddItem("Item#" + i.ToString(), null);
sampleUi.AddCheckBox(CheckBox1, "Checkbox1", 35, y+=24, 125,22, false);
sampleUi.AddCheckBox(CheckBox2, "Checkbox2", 35, y+=24, 125,22, false);
sampleUi.AddRadioButton(Radiobutton1, 1, "Radio1G1", 35, y+=24, 125, 22, true);
sampleUi.AddRadioButton(Radiobutton2, 1, "Radio2G1", 35, y+=24, 125, 22, false);
sampleUi.AddRadioButton(Radiobutton3, 1, "Radio3G1", 35, y+=24, 125, 22, false);
sampleUi.AddButton(Button1, "Button1", 35, y+=24, 125, 22);
sampleUi.AddButton(Button2, "Button2", 35, y+=24, 125, 22);
sampleUi.AddRadioButton(Radiobutton4, 2, "Radio1G2", 35, y+=24, 125, 22, true);
sampleUi.AddRadioButton(Radiobutton5, 2, "Radio2G2", 35, y+=24, 125, 22, false);
sampleUi.AddSlider(SliderControl, 50,y+=24, 100, 22);

// If you wanted to respond to any of these you would need to add an event hook here
}

/// <summary>Called when the change device button is clicked</summary>
private void OnChangeDeviceClicked(object sender, EventArgs e)
{
sampleFramework.ShowSettingsDialog(!sampleFramework.IsD3DSettingsDialogShowing);
}

/// <summary>Called when the full screen button is clicked</summary>
private void OnFullscreenClicked(object sender, EventArgs e)
{
sampleFramework.ToggleFullscreen();
}

/// <summary>Called when the ref button is clicked</summary>
private void OnRefClicked(object sender, EventArgs e)
{
sampleFramework.ToggleReference();
}

/// <summary>
/// Entry point to the program. Initializes everything and goes into a message processing
/// loop. Idle time is used to render the scene.
/// </summary>
static int Main()
{
System.Windows.Forms.Application.EnableVisualStyles();
using(Framework sampleFramework = new Framework())
{
Konvicka sample = new Konvicka(sampleFramework);
// Set the callback functions. These functions allow the sample framework to notify
// the application about device changes, user input, and windows messages. The
// callbacks are optional so you need only set callbacks for events you're interested
// in. However, if you don't handle the device reset/lost callbacks then the sample
// framework won't be able to reset your device since the application must first
// release all device resources before resetting. Likewise, if you don't handle the
// device created/destroyed callbacks then the sample framework won't be able to
// recreate your device resources.
sampleFramework.Disposing += new EventHandler(sample.OnDestroyDevice);
sampleFramework.DeviceLost += new EventHandler(sample.OnLostDevice);
sampleFramework.DeviceCreated += new DeviceEventHandler(sample.OnCreateDevice);
sampleFramework.DeviceReset += new DeviceEventHandler(sample.OnResetDevice);

sampleFramework.SetWndProcCallback(new WndProcCallback(sample.OnMsgProc));

sampleFramework.SetCallbackInterface(sample);
try
{

// Show the cursor and clip it when in full screen
sampleFramework.SetCursorSettings(true, true);

// Initialize
sample.InitializeApplication();

// Initialize the sample framework and create the desired window and Direct3D
// device for the application. Calling each of these functions is optional, but they
// allow you to set several options which control the behavior of the sampleFramework.
sampleFramework.Initialize( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
sampleFramework.CreateWindow("Konvicka");
// Hook the keyboard event
sampleFramework.Window.KeyDown += new System.Windows.Forms.KeyEventHandler(sample.OnKeyEvent);
sampleFramework.CreateDevice( 0, true, Framework.DefaultSizeWidth, Framework.DefaultSizeHeight,
sample);

// Pass control to the sample framework for handling the message pump and
// dispatching render calls. The sample framework will call your FrameMove
// and FrameRender callback when there is idle time between handling window messages.
sampleFramework.MainLoop();

}
#if(DEBUG)
catch (Exception e)
{
// In debug mode show this error (maybe - depending on settings)
sampleFramework.DisplayErrorMessage(e);
#else
catch
{
// In release mode fail silently
#endif
// Ignore any exceptions here, they would have been handled by other areas
return (sampleFramework.ExitCode == 0) ? 1 : sampleFramework.ExitCode; // Return an error code here
}

// Perform any application-level cleanup here. Direct3D device resources are released within the
// appropriate callback functions and therefore don't require any cleanup code here.
return sampleFramework.ExitCode;
}
}
}
}

Nahlásit jako SPAM
IP: 90.176.213.–
Zuben0
Stálý člen
17. 2. 2010   #4
-
0
-

zapoměl jsem dodat, už jak to otevřu je tam hromada varování :(

a tady je screen - http://czechmasakr.hys.cz/chyba.JPG

Nahlásit jako SPAM
IP: 90.176.213.–
Chrasty
~ Redaktor
+4
Posthunter
17. 2. 2010   #5
-
0
-

Co se naučit nejdřív základy C# a práce a pochopenení Visual Studia, než se pouštět do tvorby hry? Zkoušel sis alespoň ta varování od Visual Studia přečíst? To co je na tom screenu vše říká, že se určité soubory nepodařilo přidat do projektu.

Nahlásit jako SPAM
IP: 193.179.196.–
Zuben0
Stálý člen
17. 2. 2010   #6
-
0
-

No ta knížka je bez předchozích znalosti :(

Tak deklaraci už mám :) ( private Device zarizeni; ) , ale stále mi zůstává problém

Error   12      'Microsoft.Samples.DirectX.UtilityToolkit.DeviceEventArgs.Device'

is a 'field' but is used like a 'method' C:\Documents and Settings\Zuben\My
Documents\Visual Studio Projects\Konvicka\Konvicka.cs
152 26 Konvicka_2005


EDIT: Vyřešeno až na ty varování :)

Nahlásit jako SPAM
IP: 90.176.213.–
dannyk0
Věrný člen
18. 2. 2010   #7
-
0
-

Jo, bez predchozich znalosti 3D programovani. Ale pocita se se znalosti c# nebo aspon programovani :)

Nahlásit jako SPAM
IP: 85.135.97.–
Jedu v c++,c#,assembler,ASP.NET,PHP,databaze,bezpecnost softwaru[br] -----------------------------------------------------------[br] Muj blog o programovani,hudbe a vsem moznem,co najdu na netu :) [br] http://dannyk.aspone.cz[br] -----------------------------------------------------------[br] Na foru mam nejake prispevky pod nickem Master,tak jen pro upresneni :)
avoka
~ Anonymní uživatel
2 příspěvky
18. 10. 2011   #8
-
0
-

Také jsem naletěl a koupil tuto učebnici, používající zastaralý Managed v DirectX

Nahlásit jako SPAM
IP: 78.136.168.–
Peter
~ Anonymní uživatel
4016 příspěvků
18. 10. 2011   #9
-
0
-

Dávnejšie aj ja. Ale bola to pre mňa zbytočná kúpa.

Nahlásit jako SPAM
IP: 87.197.139.–
Zjistit počet nových příspěvků

Přidej příspěvek

Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!

Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku

×Vložení zdrojáku

×Vložení obrázku

Vložit URL obrázku Vybrat obrázek na disku
Vlož URL adresu obrázku:
Klikni a vyber obrázek z počítače:

×Vložení videa

Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×
 
Podporujeme Gravatara.
Zadej URL adresu Avatara (40 x 40 px) nebo emailovou adresu pro použití Gravatara.
Email nikam neukládáme, po získání Gravatara je zahozen.
-
Pravidla pro psaní příspěvků, používej diakritiku. ENTER pro nový odstavec, SHIFT + ENTER pro nový řádek.
Sledovat nové příspěvky (pouze pro přihlášené)
Sleduj vlákno a v případě přidání nového příspěvku o tom budeš vědět mezi prvními.
Reaguješ na příspěvek:

Uživatelé prohlížející si toto vlákno

Uživatelé on-line: 0 registrovaných, 16 hostů

Podobná vlákna

Co dělám špatně? — založil Chrasty

Kde dělám chybu? — založil martinb1984

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý