ورود

View Full Version : سوال: برنامهdirect x



learned
دوشنبه 09 اردیبهشت 1392, 08:03 صبح
سلام

یه برنامه می خواستم با دایرکت و زبان C++

که مثلا 2_3 تا خط به هم برخورد کنند و تبدیل به ALIشود یا حتی تبدیل به یه حرف مثل A

لطفا کمکم کنید خیلی وقت ندارم

لطفا

amin1softco
چهارشنبه 11 اردیبهشت 1392, 16:17 عصر
والا یک سرچ بزن یک زمانی بچه ها گروهی کار کردند و از این پروژه های ساده چندتا دزست کرده بودند :دی

learned
پنج شنبه 12 اردیبهشت 1392, 07:17 صبح
والا یک سرچ بزن یک زمانی بچه ها گروهی کار کردند و از این پروژه های ساده چندتا دزست کرده بودند :دی

کدام بچه ها؟؟؟
این مطلب را قبول دارم که آسان است
اما چرا هیچکس جوابی ندارد؟؟
این بچه ها کجارفته اند؟؟
صدایشان کنید نظری دهند:چشمک:
من که هرچه گشتم چیزی یافت نکردم:ناراحت:

amin1softco
پنج شنبه 12 اردیبهشت 1392, 12:27 عصر
این بچه ها هم اکنون سر کار خویش هستند و در اولین فرصت که بیکار شدند شاید به مشکل شما توجه کنند :دییییییییییییییییییی
http://barnamenevis.org/showthread.php?179271

learned
جمعه 13 اردیبهشت 1392, 09:58 صبح
این بچه ها با توجه به mail addressای که گذاشته اند
به 2 نفرشان ایمیل دادم اما دریغ از یک پاسخ کوتاه

گویا اینجا اسمش برنامه نویس هست اما هیچکس از برنامه نویسی چیزی نمیداند:متفکر:

حال جای شکرش باقیست که یکی از دوستان سایت بازی ساز را به من پیشنهاد کردند این سایت عالی بود اما نمیدانم به چه علت دیگر وارد سایت نمیتوان شد

orache
جمعه 13 اردیبهشت 1392, 20:52 عصر
چی اخه سر خود حرف میزنی بهترین برنامه نویسیا اینجا هستن اصلا تمامی برنامه نویسا اینجا هستن من از همون اول بهت گفتم که کسی با دایرکت ایکس کار نمیکنه شما میتونین به سورنا گیم مراجعه کنید و ازشون بپریسید البته اونجا که باید بپرسید جای سوال کردن نیست نوشته درباره ی ما www.sourenagames.com/fa/درباره

saied_hacker
جمعه 13 اردیبهشت 1392, 22:28 عصر
اصلا این تاپیک شما کلا ایراد داره چون کد خواستید و نبایدم کسی بهش توجه کنه...

learned
شنبه 14 اردیبهشت 1392, 14:41 عصر
چرا همه فورا به خود گرفتید؟

باید بدین گونه برخورد میکردم تا این برخورد ها را میدیدم و خیالم از این بابت راحت میشد که صدایم را میشنوند

این سوال را پرسیدم تاببینم کسی در این زمینه اصلا تخصصی دارد یا خیر بعد وارد جزئیات شوم

خب ای کسانی که تعیین تکلیف میکنید
جواب سوالم روبدید:
اینکه:

void monitor()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glPointSize(3);
GLfloat x,y;
glBegin(GL_POINTS);
for (x = -MAX ; x <= MAX ; x++)
for (y = -MAX ; y <= MAX ; y++)
glVertex2f(x,y);
glEnd();
////////////////////////////
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex2f(-MAX,0);
glVertex2f(MAX,0);
glVertex2f(0,-MAX);
glVertex2f(0, MAX);
glEnd();
///////////////////////////////
glColor3f(0.0,1.0,0.0);
glBegin(GL_POINTS);
GLfloat g, f, p,x_S, x_E, y_S,y_E, y_real;
x_S = 5 ; x_E = 25; y_S = 5 ; y_E = 10;
p = 2*(y_E - y_S) - (x_E - x_S);
f = 2*(y_E - y_S) - 2*(x_E - x_S);
g = 2*(y_E - y_S);
x = x_S;
y = y_S;
y_real = y;
GLfloat m = (y_E - y_S) / (x_E - x_S);
GLfloat b = y_S - m* x_S;
for(x = x_S ; x <= x_E ; x++)
{
y_real = m * x +b;

glColor3f(1.0,0.0,0.0);
glVertex2f(x,y_real);

glColor3f(0.0,1.0,0.0);
glVertex2f(x,y);

if(p >= 0)
{
y = y+1;
p = p + f;
}
else
p = p + g;
}
glEnd();

glFlush();
}

به جای اینها برای اجرای پنجره در دایرکت چی باید نوشت؟

و اینکه نمیخوام از دستورات زیر استفاده کنم
ایا امکانش هست؟

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);



int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
L"WindowClass",
L"Our First Direct3D Program",
WS_OVERLAPPEDWINDOW,
300, 300,
800, 600,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWnd, nCmdShow);

initD3D(hWnd);



MSG msg;

while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if(msg.message == WM_QUIT)
break;

render_frame();
}

cleanD3D();

return msg.wParam;
}


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}

return DefWindowProc (hWnd, message, wParam, lParam);
}

این جمله به چه معناست:OpenGL بر خلاف APIهای دیگر به جای توسعه مبتی بر ویرایش از توسعه مبتی بر افزودنی (extension) پشتیبانی می کند.
از این نظربا دایرکت چه فرقی داره

OpenGL 2.0: اضافه شدن کانال قابل برنامه ریزی و زبان
GLSLOpenGL 3.0: حذف کانال پردازش ثابت
(fixed function)OpenGL 4.0: سیستم پردازشی جدید و تغییر ساختار شیدرها .اینها به چه معناست؟

کلی سوال دارم فعلا ایبن ها را جواب دهید بدید ببینم چند مرده حلاجید؟

سرخود حرف زدن به چه معناست؟
سرچ کردن هم متاسفانه یاد نگرفتم:متعجب:سرچ چیست؟

با دیدن سمپل بدون توضیح و تفسیر یاد میگیرید؟
شما چقدر باهوش هستید:کف:



خواستم اگر کسی میداند برایم توضیح دهد
دیدن سمپل به تنهایی بسیار آسان است اما چه فایده که ما باهوش نیستیم

با تشکر و احترام
متاسفم که تا این حد ناراحتتون کردم

اما سعی کنید به گونه ای برخورد نمایید که دیگران در پی عصبانی کردن شما راه های زیادی را امتحان کنند و به نتیجه نرسند نه اینکه عصبانی کردن شما برایشان بسیار آسان باشد

UfnCod3r
شنبه 14 اردیبهشت 1392, 15:35 عصر
یکم انگار طلبکاری ؟بخشید ک جواب ندادیم دیگه تکرار نمیشه خیلی خیلی ببخشید:عصبانی:


و اینکه نمیخوام از دستورات زیر استفاده کنم
ایا امکانش هست؟

نه همونا رو بنویس .



این جمله به چه معناست:OpenGL بر خلاف APIهای دیگر به جای توسعه مبتی بر ویرایش از توسعه مبتی بر افزودنی (extension) پشتیبانی می کند.
از این نظربا دایرکت چه فرقی داره

OpenGL 2.0: اضافه شدن کانال قابل برنامه ریزی و زبان
GLSLOpenGL 3.0: حذف کانال پردازش ثابت
(fixed function)OpenGL 4.0: سیستم پردازشی جدید و تغییر ساختار شیدرها .اینها به چه معناست؟



تو دایرکت ایکس هر دفعه که نسخه جدید میاد کلا اکثر چیزا تغییر کرده و کلا ی دایرکت ایکس دیگه هست .
اما تو اپن جی ال عوض نسخه جدید هی الحاقی اضافه میشه . مثل همین الحاقی ها که نوشتی . از اینه اپن جی ال خیلی بدم میاد .

orache
شنبه 14 اردیبهشت 1392, 16:11 عصر
دایرکت ایکس که سال 2004 ساخته شده بود واقعا خوب بود و آدم حالیش میشد ولی این 2010 sdk رو باید بابیلو کلنک وارد مغزمون کرد خیلی سخته + اینکه هر خط کد opengl برابر است با 12 خط کد دایرکت ایکس فقط بخای یک صفحه باز کنی باید از 10 تا دستورشرطی استفاده کنی :متعجب:

learned
جمعه 20 اردیبهشت 1392, 09:27 صبح
مشکل این برنامه چیه و چرا هیچی نشون نمیده؟
علمل جواب بدید

// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 800

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")

// global declarations
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // the pointer to the vertex buffer
D3DPRIMITIVETYPE D3DPT_PointLIST;
// function prototypes
void initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory
void init_graphics(void); // 3D declarations

struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = L"WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
L"WindowClass",
L"Our Direct3D Program",
WS_OVERLAPPEDWINDOW,
0, 0,
SCREEN_WIDTH, SCREEN_HEIGHT,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWnd, nCmdShow);

// set up and initialize Direct3D
initD3D(hWnd);

// enter the main loop:

MSG msg;

while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if(msg.message == WM_QUIT)
break;

render_frame();
}

// clean up DirectX and COM
cleanD3D();

return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}

return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;

// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

init_graphics(); // call the function to initialize the triangle
}


// this is the function used to render a single frame
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

d3ddev->BeginScene();

// select which vertex format we are using
d3ddev->SetFVF(CUSTOMFVF);

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

// copy the vertex buffer to the back buffer
d3ddev->DrawPrimitive(D3DPT_PointLIST, 0, 1);

d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
v_buffer->Release(); // close and release the vertex buffer
d3ddev->Release(); // close and release the 3D device
d3d->Release(); // close and release Direct3D
}


// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
// create the vertices using the CUSTOMVERTEX struct
CUSTOMVERTEX vertices[] =
{
{ 20.0f, 20.f, 10.f,.05f, D3DCOLOR_XRGB(0, 0, 255), },
{ 20.0f,20.0f, 0.5f, .05f, D3DCOLOR_XRGB(0, 255, 0), },
};

// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);

VOID* pVoid; // a void pointer

// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
}

UfnCod3r
جمعه 20 اردیبهشت 1392, 15:36 عصر
این علما کجا رفتن؟

انهم يدمرون البلاد. :قهقهه:



چرا کسی جواب نمیده؟

من یکی ک DX بلد نیستم
الان کلا پنجره رو نمایش نمیده یا نمایش میده ولی همش سیاه . دقت کن باید دو تا نقطه نشون بده :متفکر:
کدها رو نگا کردم فکر کنم یا باید ماتریس ها رو ست کنی
یا نقطه ها کوچیک هستن و معلوم نیست
دیگه کمک دیگه از دستم بر نمیاد :خجالت:

UfnCod3r
جمعه 20 اردیبهشت 1392, 18:12 عصر
فکر کنم فقط این کدها رو کپی کردی اصلا نگا هم نکردی :قهقهه:
به احتمال زیاد 2 تا نقطه چون نوشتی D3DPT_PointLIST

d3ddev->DrawPrimitive(D3DPT_PointLIST, 0, 1);





400 خط کد direct میشه 5 _ 6 خط کد جی ال :قهقهه: میخاستی بیایم دایرکت ایکس یاد بگیریم من فقط برای بعضی از رندر ها از دایرکت ایکس استفاده میکنم اونم خودم نمینویسم از msdn میارم :لبخند:

می تونی این حرفتو ثابت کنی ؟ 40 خطم شد من قبول می کنم ها :قهقهه:
فقط امدی تو این جا می گی کسی بلد نیست ن پ ن خودت خیلی بلدی عوض پست های بیخودت جواب بده

orache
جمعه 20 اردیبهشت 1392, 23:13 عصر
هیچ کسی بلد نیست شامل خودم هم میشه 40 خط هم نمیشه یعنی ؟؟ این کد برای ساخت یک انجین هست فقط برای مدیریت تکسچر این کد یک مکعب میسازه و روش تکسچر میندازه (بازم میگیم توسط موتور ساخته شده یعنی کلاس هایه متفاوتی داره ) در حالی که دقیقا همینو بخای تو opengl بسازی خیلی خیلی کمتر و راخت تره تازه کد های جی ال همشون 2 کلمه ای هستن این یکی خطش 1.5 متره :قهقهه: خیلی هم سخته نگا


-1.0 1.0 -1.0 0.0 0.0 0.0 0.0 -1.0
1.0 1.0 -1.0 1.0 0.0 0.0 0.0 -1.0
-1.0 -1.0 -1.0 0.0 1.0 0.0 0.0 -1.0
-1.0 -1.0 -1.0 0.0 1.0 0.0 0.0 -1.0
1.0 1.0 -1.0 1.0 0.0 0.0 0.0 -1.0
1.0 -1.0 -1.0 1.0 1.0 0.0 0.0 -1.0
1.0 1.0 -1.0 0.0 0.0 1.0 0.0 0.0
1.0 1.0 1.0 1.0 0.0 1.0 0.0 0.0
1.0 -1.0 -1.0 0.0 1.0 1.0 0.0 0.0
1.0 -1.0 -1.0 0.0 1.0 1.0 0.0 0.0
1.0 1.0 1.0 1.0 0.0 1.0 0.0 0.0
1.0 -1.0 1.0 1.0 1.0 1.0 0.0 0.0
1.0 1.0 1.0 0.0 0.0 0.0 0.0 1.0
-1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0
1.0 -1.0 1.0 0.0 1.0 0.0 0.0 1.0
1.0 -1.0 1.0 0.0 1.0 0.0 0.0 1.0
-1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0
-1.0 -1.0 1.0 1.0 1.0 0.0 0.0 1.0
-1.0 1.0 1.0 0.0 0.0 -1.0 0.0 0.0
-1.0 1.0 -1.0 1.0 0.0 -1.0 0.0 0.0
-1.0 -1.0 1.0 0.0 1.0 -1.0 0.0 0.0
-1.0 -1.0 1.0 0.0 1.0 -1.0 0.0 0.0
-1.0 1.0 -1.0 1.0 0.0 -1.0 0.0 0.0
-1.0 -1.0 -1.0 1.0 1.0 -1.0 0.0 0.0
-1.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0
1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0
-1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0
-1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0
1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0
1.0 1.0 -1.0 1.0 1.0 0.0 1.0 0.0
-1.0 -1.0 -1.0 0.0 0.0 0.0 -1.0 0.0
1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0
-1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0
-1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0
1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0
1.0 -1.0 1.0 1.0 1.0 0.0 -1.0 0.0
////////////////////////////////////////////////////////////////////////////////
// Filename: modelclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _MODELCLASS_H_
#define _MODELCLASS_H_
//////////////
// INCLUDES //
//////////////
#include <fstream>
using namespace std;


///////////////////////
// MY CLASS INCLUDES //
///////////////////////
#include "textureclass.h"


////////////////////////////////////////////////////////////////////////////////
// Class name: ModelClass
////////////////////////////////////////////////////////////////////////////////
class ModelClass
{
private:
struct VertexType
{
D3DXVECTOR3 position;
D3DXVECTOR2 texture;
D3DXVECTOR3 normal;
};

struct ModelType
{
float x, y, z;
float tu, tv;
float nx, ny, nz;
};

public:
ModelClass();
ModelClass(const ModelClass&);
~ModelClass();
bool Initialize(ID3D10Device*, char*, WCHAR*);
void Shutdown();
void Render(ID3D10Device*);

int GetIndexCount();
ID3D10ShaderResourceView* GetTexture();

private:
bool InitializeBuffers(ID3D10Device*);
void ShutdownBuffers();
void RenderBuffers(ID3D10Device*);

bool LoadTexture(ID3D10Device*, WCHAR*);
void ReleaseTexture();
bool LoadModel(char*);
void ReleaseModel();

private:
ID3D10Buffer *m_vertexBuffer, *m_indexBuffer;
int m_vertexCount, m_indexCount;
TextureClass* m_Texture;
ModelType* m_model;
};

#endif
////////////////////////////////////////////////////////////////////////////////
// Filename: modelclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "modelclass.h"


ModelClass::ModelClass()
{
m_vertexBuffer = 0;
m_indexBuffer = 0;
m_Texture = 0;
m_model = 0;
}


ModelClass::ModelClass(const ModelClass& other)
{
}


ModelClass::~ModelClass()
{
}
bool ModelClass::Initialize(ID3D10Device* device, char* modelFilename, WCHAR* textureFilename)
{
bool result;
// Load in the model data.
result = LoadModel(modelFilename);
if(!result)
{
return false;
}

// Initialize the vertex and index buffers.
result = InitializeBuffers(device);
if(!result)
{
return false;
}

// Load the texture for this model.
result = LoadTexture(device, textureFilename);
if(!result)
{
return false;
}


return true;
}


void ModelClass::Shutdown()
{
// Release the model texture.
ReleaseTexture();

// Shutdown the vertex and index buffers.
ShutdownBuffers();
// Release the model data.
ReleaseModel();

return;
}


void ModelClass::Render(ID3D10Device* device)
{
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(device);

return;
}


int ModelClass::GetIndexCount()
{
return m_indexCount;
}


ID3D10ShaderResourceView* ModelClass::GetTexture()
{
return m_Texture->GetTexture();
}


bool ModelClass::InitializeBuffers(ID3D10Device* device)
{
VertexType* vertices;
unsigned long* indices;
D3D10_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
D3D10_SUBRESOURCE_DATA vertexData, indexData;
HRESULT result;
int i;
// Create the vertex array.
vertices = new VertexType[m_vertexCount];
if(!vertices)
{
return false;
}

// Create the index array.
indices = new unsigned long[m_indexCount];
if(!indices)
{
return false;
}
// Load the vertex array and index array with data.
for(i=0; i<m_vertexCount; i++)
{
vertices[i].position = D3DXVECTOR3(m_model[i].x, m_model[i].y, m_model[i].z);
vertices[i].texture = D3DXVECTOR2(m_model[i].tu, m_model[i].tv);
vertices[i].normal = D3DXVECTOR3(m_model[i].nx, m_model[i].ny, m_model[i].nz);

indices[i] = i;
}

// Set up the description of the static vertex buffer.
vertexBufferDesc.Usage = D3D10_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;

// Give the subresource structure a pointer to the vertex data.
vertexData.pSysMem = vertices;

// Now finally create the vertex buffer.
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if(FAILED(result))
{
return false;
}

// Set up the description of the index buffer.
indexBufferDesc.Usage = D3D10_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
indexBufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

// Give the subresource structure a pointer to the index data.
indexData.pSysMem = indices;

// Create the index buffer.
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if(FAILED(result))
{
return false;
}

// Release the arrays now that the vertex and index buffers have been created and loaded.
delete [] vertices;
vertices = 0;

delete [] indices;
indices = 0;

return true;
}


void ModelClass::ShutdownBuffers()
{
// Release the index buffer.
if(m_indexBuffer)
{
m_indexBuffer->Release();
m_indexBuffer = 0;
}

// Release the vertex buffer.
if(m_vertexBuffer)
{
m_vertexBuffer->Release();
m_vertexBuffer = 0;
}

return;
}


void ModelClass::RenderBuffers(ID3D10Device* device)
{
unsigned int stride;
unsigned int offset;


// Set vertex buffer stride and offset.
stride = sizeof(VertexType);
offset = 0;

// Set the vertex buffer to active in the input assembler so it can be rendered.
device->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);

// Set the index buffer to active in the input assembler so it can be rendered.
device->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);

// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TR IANGLELIST);

return;
}


bool ModelClass::LoadTexture(ID3D10Device* device, WCHAR* filename)
{
bool result;


// Create the texture object.
m_Texture = new TextureClass;
if(!m_Texture)
{
return false;
}

// Initialize the texture object.
result = m_Texture->Initialize(device, filename);
if(!result)
{
return false;
}

return true;
}


void ModelClass::ReleaseTexture()
{
// Release the texture object.
if(m_Texture)
{
m_Texture->Shutdown();
delete m_Texture;
m_Texture = 0;
}

return;
}
bool ModelClass::LoadModel(char* filename)
{
ifstream fin;
char input;
int i;


// Open the model file.
fin.open(filename);

// If it could not open the file then exit.
if(fin.fail())
{
return false;
}

// Read up to the value of vertex count.
fin.get(input);
while(input != ':')
{
fin.get(input);
}

// Read in the vertex count.
fin >> m_vertexCount;

// Set the number of indices to be the same as the vertex count.
m_indexCount = m_vertexCount;

// Create the model using the vertex count that was read in.
m_model = new ModelType[m_vertexCount];
if(!m_model)
{
return false;
}

// Read up to the beginning of the data.
fin.get(input);
while(input != ':')
{
fin.get(input);
}
fin.get(input);
fin.get(input);

// Read in the vertex data.
for(i=0; i<m_vertexCount; i++)
{
fin >> m_model[i].x >> m_model[i].y >> m_model[i].z;
fin >> m_model[i].tu >> m_model[i].tv;
fin >> m_model[i].nx >> m_model[i].ny >> m_model[i].nz;
}

// Close the model file.
fin.close();

return true;
}
void ModelClass::ReleaseModel()
{
if(m_model)
{
delete [] m_model;
m_model = 0;
}

return;
}
////////////////////////////////////////////////////////////////////////////////
// Filename: graphicsclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _GRAPHICSCLASS_H_
#define _GRAPHICSCLASS_H_


///////////////////////
// MY CLASS INCLUDES //
///////////////////////
#include "d3dclass.h"
#include "cameraclass.h"
#include "modelclass.h"
#include "lightshaderclass.h"
#include "lightclass.h"


/////////////
// GLOBALS //
/////////////
const bool FULL_SCREEN = true;
const bool VSYNC_ENABLED = true;
const float SCREEN_DEPTH = 1000.0f;
const float SCREEN_NEAR = 0.1f;


////////////////////////////////////////////////////////////////////////////////
// Class name: GraphicsClass
////////////////////////////////////////////////////////////////////////////////
class GraphicsClass
{
public:
GraphicsClass();
GraphicsClass(const GraphicsClass&);
~GraphicsClass();

bool Initialize(int, int, HWND);
void Shutdown();
bool Frame();

private:
bool Render(float);

private:
D3DClass* m_D3D;
CameraClass* m_Camera;
ModelClass* m_Model;
LightShaderClass* m_LightShader;
LightClass* m_Light;
};

#endif

////////////////////////////////////////////////////////////////////////////////
// Filename: graphicsclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "graphicsclass.h"


GraphicsClass::GraphicsClass()
{
m_D3D = 0;
m_Camera = 0;
m_Model = 0;
m_LightShader = 0;
m_Light = 0;
}


GraphicsClass::GraphicsClass(const GraphicsClass& other)
{
}


GraphicsClass::~GraphicsClass()
{
}


bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
bool result;


// Create the Direct3D object.
m_D3D = new D3DClass;
if(!m_D3D)
{
return false;
}

// Initialize the Direct3D object.
result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if(!result)
{
MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
return false;
}

// Create the camera object.
m_Camera = new CameraClass;
if(!m_Camera)
{
return false;
}

// Create the model object.
m_Model = new ModelClass;
if(!m_Model)
{
return false;
}
// Initialize the model object.
result = m_Model->Initialize(m_D3D->GetDevice(), "../Engine/data/cube.txt", L"../Engine/data/seafloor.dds");
if(!result)
{
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
return false;
}

// Create the light shader object.
m_LightShader = new LightShaderClass;
if(!m_LightShader)
{
return false;
}

// Initialize the light shader object.
result = m_LightShader->Initialize(m_D3D->GetDevice(), hwnd);
if(!result)
{
MessageBox(hwnd, L"Could not initialize the light shader object.", L"Error", MB_OK);
return false;
}

// Create the light object.
m_Light = new LightClass;
if(!m_Light)
{
return false;
}
// Initialize the light object.
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, 1.0f);

return true;
}


void GraphicsClass::Shutdown()
{
// Release the light object.
if(m_Light)
{
delete m_Light;
m_Light = 0;
}

// Release the light shader object.
if(m_LightShader)
{
m_LightShader->Shutdown();
delete m_LightShader;
m_LightShader = 0;
}

// Release the model object.
if(m_Model)
{
m_Model->Shutdown();
delete m_Model;
m_Model = 0;
}

// Release the camera object.
if(m_Camera)
{
delete m_Camera;
m_Camera = 0;
}

// Release the D3D object.
if(m_D3D)
{
m_D3D->Shutdown();
delete m_D3D;
m_D3D = 0;
}

return;
}


bool GraphicsClass::Frame()
{
bool result;
static float rotation = 0.0f;


// Update the rotation variable each frame.
rotation += (float)D3DX_PI * 0.01f;
if(rotation > 360.0f)
{
rotation -= 360.0f;
}

// Render the graphics scene.
result = Render(rotation);
if(!result)
{
return false;
}

return true;
}


bool GraphicsClass::Render(float rotation)
{
D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix;


// Clear the buffers to begin the scene.
m_D3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

// Generate the view matrix based on the camera's position.
m_Camera->Render();

// Get the world, view, and projection matrices from the camera and d3d objects.
m_Camera->GetViewMatrix(viewMatrix);
m_D3D->GetWorldMatrix(worldMatrix);
m_D3D->GetProjectionMatrix(projectionMatrix);

// Rotate the world matrix by the rotation value so that the triangle will spin.
D3DXMatrixRotationY(&worldMatrix, rotation);

// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_D3D->GetDevice());

// Render the model using the light shader.
m_LightShader->Render(m_D3D->GetDevice(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(),
m_Light->GetDirection(), m_Light->GetDiffuseColor());

// Present the rendered scene to the screen.
m_D3D->EndScene();

return true;
}

learned
جمعه 27 اردیبهشت 1392, 15:32 عصر
مشکلم حل شد حالا چه طوری 2 خط با هم رسم کنم؟

learned
چهارشنبه 01 خرداد 1392, 08:19 صبح
2تا خطم رو رسم کردم حالا موقعی که میخوام تکونش بدم ارور میده


Error 6 error LNK2019: unresolved external symbol _D3DXMatrixMultiply@12 referenced in function "public: struct D3DXMATRIX __thiscall D3DXMATRIX::operator*(struct D3DXMATRIX const &)const " (??DD3DXMATRIX@@QBE?AU0@ABU0@@Z) C:\Users\Mollasadra\Desktop\مثلث چرخش\مثلث چرخش\1.obj مثلث چرخش



Error 1 error LNK2019: unresolved external symbol _D3DXMatrixTranslation@16 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ) C:\Users\Mollasadra\Desktop\مثلث چرخش\مثلث چرخش\1.obj مثلث چرخش

pswin.pooya
پنج شنبه 02 خرداد 1392, 10:37 صبح
دوستان

learned:
اینجا کسی تمرین دانشجویی جوا نمی ده. بخاطر همین هم جواب نمی گیرید و اما چرا ایرداتون هم جواب داده نمیشه مربوط به اینه که میخوایین بدون کوچیکترین زحمتی جواب بگیرید. و مسلم هست که اینجا کسی حاضر نیست لقمه آماده بذاره توی دهن کسی.

__UFNHGGI_H__ (http://barnamenevis.org/member.php?279137-__UFNHGGI_H__)
orache و بقیه: (http://barnamenevis.org/member.php?262445-orache)

بارها تذکر داده شده که پستها باید حاوی مطالب فنی باشن و نه کل کل و امثال اونها. واقعا دیگه از چک کردن مرتب پستها برای اینکه یکی مثلا همچین پستهایی داده خسته شدم و واقعا از اخطار دادن هم خسته شدم. واقعا بازهم بچه بازی ها تاسطح زیادی بالا رفته یکی میاد به یکی دیگه میگه سوسول یکی دیگه میگه علما و .... و یکی دیگه میاد میگه من مثلا از valve بیشتر میدونم و اونها کلک زدن و اینا واقعا نمی دونم چی بگم. فقط بجای تلف کردن وقتتون برای این چیزا سعی کنید دو خط مطالعه کنید و مطمعن باشید این شکلی سریعتر می تونید جواب بگیرید

خیلی راحت میتونید با هم بحث کنید و نظرات و دلایل خودتون رو توی این تالار بگید اما تا جایی که کار به توهین نکشه.

و تذکر آخر:
از این به بعد هر کسی سعی کنه کاربر دیگه ای رو تحقیر کنه و یا بد و بیرا و امثال اون رو بگه به دون اخطار قبلی به مدیر سایت برای حذف اکانت کاربریش گزارش میشه و بقیه تصمیم ها با ایشون هست.