وبلاگ رسمی علیرضا شهامت در بلاگ اسکای



ترجمه ی فارسی گوگل ترجمه :


5000/5000
Character limit: 5000
سرریز پشته

    1
    5

    خانه
        عمومی
        سرریز پشته
        برچسب ها
        کاربران
        شغل ها
        تیم ها
        پرسش و پاسخ برای کار
        بیشتر بدانید

خطا C1083: امکان باز شدن شامل فایل: 'stdafx.h'
سوال بپرس
10

وقتی این برنامه را کامپایل کردم (از نسخه 4 زبان برنامه نویسی C ++):

main.cpp

#include <stdafx.h>
#include <iostream>
#include <cmath>
#include "vector.h"
استفاده از namespace std؛

sqrt_sum دو (بردار و)؛

int _tmain (int argc، _TCHAR * argv [])
{
    بردار v (6)؛
    sqrt_sum (v)؛
    بازگشت 0؛
}

double sqrt_sum (vector & v)
{
    دو برابر = 0؛
    برای (int i = 0؛ i! = v.size ()؛ ++ i)
        مجموع + = sqrt (v [i])؛
    مبلغ بازگشت؛
}

vector.cpp

#include <stdafx.h>
#include "vector.h"

بردار (بردار) (int s)
: elem {new double [s]}، sz {s}
{
}
دو برابر و بردار :: اپراتور [] (int i)
{
    بازگشت elem [i]؛
}
متن int :: size ()
{
    بازگشت sz؛
}

vector.h

#include <stdafx.h>
بردار کلاس {
عمومی:
    بردار (int s)؛
    دو طرف و اپراتور [] (int i)؛
    اندازه int ()؛
خصوصی:
    دو * elem؛
    int sz؛


این خطاها را به من داد:

اشتباهات

من آن را در مایکروسافت ویژوال استودیو 2013، در ویندوز 7 اجرا کردم. چگونه آن را تعمیر کنم؟
سی ++ ویژوال استودیو ویژوال استودیو 2013 stdafx.h
اشتراک گذاری
ویرایش مارس 1 '17 در 18:59
سنسی جیمز
1،7002030
خواسته اکتبر 12 '14 در 21:28
کولیس
5131819

    6
    شروع پروژه شما راه راست اغلب 99٪ از نبرد است. فایل + جدید + پروژه، ویژوال سی + +، Win32، انتخاب کنید "برنامه Win32 کنسول". شما در حال حاضر فایل stdafx.h با تمام تنظیمات کامپایلر را فقط به عنوان راهی برای استفاده از ویژگی های هدر های پیش کامپایل کرده اید. اگر کتاب شما را به این راه هدایت نکرد، پس باید به دنبال دیگری باشید. اما احتمالا این کار را کرد. - هانس پاسانت 12 اکتبر '14 در 21:53

یک نظر اضافه کن
6 پاسخ
فعال
قدیمی ترین
رای
15

شما باید به درستی درک کنید که "stdafx.h" چیست، به عنوان مثال هدر پیش کامپایل شده است. سوالات دیگر یا ویکی پدیا به آن پاسخ خواهند داد. در بسیاری از موارد هدر پیش کامپایل شده را می توان اجتناب کرد، به ویژه اگر پروژه شما کوچک و با چندین وابستگی باشد. در مورد شما، همانطور که احتمالا از یک پروژه قالب شروع شد، استفاده از آن برای Windows.h فقط برای ماکرو _TCHAR استفاده شد.

سپس، هدر پیش کامپایل شده معمولا یک فایل پروژه در پروژه در دنیای ویژوال استودیو است، بنابراین:

    اطمینان حاصل کنید که فایل "stdafx.h" در پروژه شما وجود دارد. اگر شما (به عنوان مثال آن را حذف نکردید)، فقط یک پروژه موقت جدید ایجاد کنید و از آن به طور پیشفرض کپی کنید؛
    #include <stdafx.h> را به #include "stdafx.h" تغییر دهید. قرار است که یک فایل محلی پروژه باشد، که در فهرست دایرکتوری ها قابل حل نیست.

ثانیا: غیر قابل توصیف است که هدر پیش کامپایل را در هدرهای خود اضافه کنید تا فضای نامی دیگری از منبع را که می تواند از کد شما به عنوان یک کتابخانه استفاده کند، نادیده بگیرد، بنابراین کاملی را در vector.h حذف می کند.
اشتراک گذاری
پاسخ 12 اکتبر '14 در 21:42
ceztko
8،67723649

    بعد از این تغییرات imgur.com/2lgOJht - Kulis Oct 13 '14 at 13:38
    1
    تمام روشهایی که درون vector.h هدر تعریف کردید نماد املت شده در اجرایی اصلی پیدا نشد. اطمینان حاصل کنید که شما واقعا کامپایل vector.cpp هستید. در ویژوال استودیو: مطمئن شوید vector.cpp در فیلترهای "Source Files" (شما آن را به عنوان یک پوشه مشاهده می کنید). یا آن را حذف کنید و به پروژه بخوانید. - ceztko Oct 13 '14 در 15:08
    1
    ecztko "غیر قابل توصیف است که هدر پیش کامپایل را در هدرهای خود اضافه کنید تا فضای نامی دیگری از منبع دیگری که می تواند از کد شما استفاده کند، مخفی نشود" . آیا مطمئن هستید؟ هر هدر قبل از کامپایلل دارای #pragma یک بار است، بنابراین تنها برای اولین بار استفاده می شود و دیگر (مانند vector.h) نادیده گرفته می شوند، آیا آنها نیستند؟ - مارتین پککا Jun 10 '16 در 0:48
    1
    هوم، من به یک وضعیتی رسیدم که در stdafx.h در فایل های هدر من باعث مشکلات می شود. این زمانی است که یک کتابخانه از stdafx.h استفاده می کند، اما برنامه با استفاده از آن نمی کند، و فایل stdafx.h توسط کتابخانه نمایش داده نمی شود. - مارتین پککا Jun 11 '16 در 0:27
    1
    بله این باید یک مسئله باشد. به طور کلی، من نگران این واقعیت است که stdafx.h بیش از آن چیزی است که نیاز به پیوند کتابخانه دارد، بنابراین با اضافه کردن آن به طور غیر ضروری، شما نام دیگران را آلوده می کنید. - ceztko Jun 11 '16 در 8:02

نمایش 1 نظر دیگر
8

فقط به جای stdfax windows.h را وارد کنید یا یک پروژه تمیز بدون قالب ایجاد کنید.
اشتراک گذاری
پاسخ 12 اکتبر '14 در 22:05
user3718058
13829
یک نظر اضافه کن
6

دو راه حل برای آن وجود دارد.

راه حل شماره یک: 1. ایجاد پروژه. هنگام ایجاد یک پروژه مطمئن شوید هدر پیش کامپایل شده بررسی می شود (تنظیمات برنامه . *** پروژه خالی را بررسی نکنید)

راه حل شماره دو: 1. ایجاد stdafx.h و stdafx.cpp در پروژه خود. 2 بر روی پروژه کلیک راست کنید. -> خواص -> C / C ++ -> سربرگ پیش کامپایل شده. 3. header قبل از کامپایل را برای ایجاد (/ Yc) 4.Rebuild solution

اگر با هر مسئله روبرو شدید، یک پیام را به من ببند.
اشتراک گذاری
پاسخ داد 11 ژوئن '16 در 6:51
دیلورگورگ
8051318

    1
    من این فایل های خالی را در "راه حل شماره دو" ایجاد کردم و در Properties Properties-> Precompiled Header خالی باقی مانده بود- Create (/ Yc) را انتخاب نکردم. من آن را دوباره ساختم و همه چیز خوب است - Junior M Jul 21 '17 در 21:16

یک نظر اضافه کن
2

اضافه کنید #include "afx




انگلیسی: 


Stack Overflow

    1
    5

    Home
        Public
        Stack Overflow
        Tags
        Users
        Jobs
        Teams
        Q&A for work
        Learn More

Error C1083: Cannot open include file: 'stdafx.h'
Ask Question
10

When I compiled this program (from C++ Programming Language 4th edition):

main.cpp

#include <stdafx.h>
#include <iostream>
#include <cmath>
#include "vector.h"
using namespace std;

double sqrt_sum(vector&);

int _tmain(int argc, _TCHAR* argv[])
{
    vector v(6);
    sqrt_sum(v);
    return 0;
}

double sqrt_sum(vector& v)
{
    double sum = 0;
    for (int i = 0; i != v.size(); ++i)
        sum += sqrt(v[i]);
    return sum;
}

vector.cpp

#include <stdafx.h>
#include "vector.h"

vector::vector(int s)
:elem{ new double[s] }, sz{ s }
{
}
double& vector::operator[](int i)
{
    return elem[i];
}
int vector::size()
{
    return sz;
}

vector.h

#include <stdafx.h>
class vector{
public:
    vector(int s);
    double& operator[](int i);
    int size();
private:
    double* elem;
    int sz;
};

It gave me these errors:

errors

I run it on Microsoft Visual Studio 2013, on Windows 7. How to fix it?
c++ visual-studio visual-studio-2013 stdafx.h
shareedit
edited Mar 1 '17 at 18:59
Sensei James
1,7002030
asked Oct 12 '14 at 21:28
Kulis
5131819

    6
    Starting your project the Right Way is often 99% of the battle. File + New + Project, Visual C++, Win32, select "Win32 Console Application". You now have an stdafx.h file with all the compiler settings just the way they should be to use the precompiled headers feature. If the book didn't guide you that way then you ought to look for another one. But it probably did. – Hans Passant Oct 12 '14 at 21:53

add a comment
6 Answers
active
oldest
votes
15

You have to properly understand what is a "stdafx.h", aka precompiled header. Other questions or Wikipedia will answer that. In many cases a precompiled header can be avoided, especially if your project is small and with few dependencies. In your case, as you probably started from a template project, it was used to include Windows.h only for the _TCHAR macro.

Then, precompiled header is usually a per-project file in Visual Studio world, so:

    Ensure you have the file "stdafx.h" in your project. If you don't (e.g. you removed it) just create a new temporary project and copy the default one from there;
    Change the #include <stdafx.h> to #include "stdafx.h". It is supposed to be a project local file, not to be resolved in include directories.

Secondly: it's inadvisable to include the precompiled header in your own headers, to not clutter namespace of other source that can use your code as a library, so completely remove its inclusion in vector.h.
shareedit
answered Oct 12 '14 at 21:42
ceztko
8,67723649

    After these changes imgur.com/2lgOJht – Kulis Oct 13 '14 at 13:38
    1
    All the methods you defined in the header vector.h didn't find an imlemented symbol in the main executable. Ensure you are really compiling vector.cpp. In visual studio: ensure vector.cpp is in the "Source Files" filter (you see it as a folder). Or remove and readd it to the project. – ceztko Oct 13 '14 at 15:08
    1
    @ceztko "it's inadvisable to include the precompiled header in your own headers, to not clutter namespace of other source that can use your code" . are you sure with that? Every precompiled header has #pragma once, so only the first one is used and the other (like in vector.h) are ignored, aren't they? – Martin Pecka Jun 10 '16 at 0:48
    1
    Hmm, I've arrived at a situation where having stdafx.h in my header files causes problems. That's when a library uses stdafx.h, but the program using it does not, and the stdafx.h file is not exposed by the library. – Martin Pecka Jun 11 '16 at 0:27
    1
    Yes. That should be also an issue. In general, I am concerned by the fact that stdafx.h exposes more than actually needed to link the library, so by including it unnecessarily you're polluting someone's else namespace. – ceztko Jun 11 '16 at 8:02

show 1 more comment
8

Just include windows.h instead of stdfax or create a clean project without template.
shareedit
answered Oct 12 '14 at 22:05
user3718058
13829
add a comment
6

There are two solutions for it.

Solution number one: 1.Recreate the project. While creating a project ensure that precompiled header is checked(Application settings. *** Do not check empty project)

Solution Number two: 1.Create stdafx.h and stdafx.cpp in your project 2 Right click on project -> properties -> C/C++ -> Precompiled Headers 3.select precompiled header to create(/Yc) 4.Rebuild the solution

Drop me a message if you encounter any issue.
shareedit
answered Jun 11 '16 at 6:51
Dila Gurung
8051318

    1
    I created those empty files in "solution number two" and in Project Properties-> Precompiled Header is left blank - I did not select Create (/Yc). I rebuilt it and everything is ok. – Junior M Jul 21 '17 at 21:16

add a comment
2

Add #include "afx




package com.company;

//public class Main {

//

// public static void main(String[] args) {

//
// write your code here
// }
//}


import javax.swing.*;
import java.awt.*;

public class Main {

public static void main(String s[]) {

JFrame frame = new JFrame("JFrame Example");

frame.setVisible(true);

JPanel panel = new JPanel();

//panel.setLayout(new FlowLayout());

LayoutManager aa;
aa = new FlowLayout();
panel.setLayout(aa);


JLabel label = new JLabel("JFrame By Example");

JButton button = new JButton();

button.setText("Button");

panel.add(label);

panel.add(button);

frame.add(panel);

frame.setSize(200, 300);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//frame.setVisible(true);
}

}

فارسی:
بخش اول:
5000/5000
Character limit: 5000
اگر شما AdBlock را اجرا می کنید، لطفا اگر مایل به حمایت از LearnOpenGL هستید، لطفا این سایت را سفید کنید. و نگران نباش

    معرفی
    شروع شدن
        OpenGL
        ایجاد یک پنجره
        سلام پنجره
        سلام مثلث
        سایه ها
        بافت
        تغییرات
        دستگاه های مختصات
        دوربین
        مرور
    روشنایی
    مدل بارگیری
    پیشرفته OpenGL
    روشنایی پیشرفته
    PBR
    در تمرین
    کتاب آفلاین
    مخزن کد
    ترجمه ها
    در باره

دوربین

در آموزش قبلی ما درباره ماتریس دید و نحوه استفاده از ماتریس دید برای حرکت در اطراف صحنه (ما کمی عقب رفتیم) بحث کردیم. OpenGL به خودی خود با مفهوم دوربین آشنا نیست، اما ما می توانیم با حرکت همه اشیاء در صحنه در جهت مع، سعی کنیم شبیه سازی کنیم، و این توهم را که ما در حال حرکت است، شبیه سازی کنیم.

در این آموزش ما بحث خواهیم کرد که چگونه می توان یک دوربین را در OpenGL تنظیم کرد. ما در مورد یک دوربین FPS سبک که اجازه می دهد شما را به صورت آزاد در یک صحنه 3D حرکت می کند. در این آموزش ما نیز درباره ورودی صفحه کلید و ماوس صحبت خواهیم کرد و با یک کلاس دوربین سفارشی به پایان برسیم.
دوربین / فضای نمایش

هنگامی که ما در مورد فضای دوربین / فضای صحبت می کنیم، ما در مورد همه مختصات ریشه صحبت می کنیم که از دیدگاه دوربین به عنوان منشاء صحنه دیده می شود: ماتریس مشاهده همه مختصات جهان را به مختصات دید که نسبت به موقعیت دوربین و جهت برای تعریف یک دوربین ما نیاز به موقعیت آن در فضای جهانی، جهت آن را به دنبال، یک بردار اشاره به سمت راست و یک بردار اشاره شده به سمت بالا از دوربین. یک خواننده دقیق ممکن است متوجه شود که ما در واقع می خواهیم یک سیستم مختصات با 3 محور واحد عمودی با موقعیت دوربین به عنوان مبدا ایجاد کنیم.
1. موقعیت دوربین

گرفتن موقعیت دوربین آسان است. موقعیت دوربین اساسا یک بردار در فضای جهانی است که به موقعیت دوربین اشاره دارد. ما دوربین را در موقعیتی قرار دادیم که دوربین را در آموزش قبلی تنظیم کرده ایم:


glm :: vec3 cameraPos = glm :: vec3 (0.0f، 0.0f، 3.0f)؛

فراموش نکنید که محور z مثبت از روی صفحه نمایش به سمت شما حرکت می کند، بنابراین اگر ما بخواهیم دوربین را به عقب حرکت دهیم، ما در امتداد محور z مثبت حرکت می کنیم.
2. جهت دوربین

بردار بعدی مورد نیاز جهت دوربین است e.g. در چه مسیری قرار دارد؟ در حال حاضر ما اجازه می دهیم که دوربین نقطه مناسبی از صحنه ما باشد: (0،0،0). به یاد داشته باشید که اگر ما دو بردار را از یکدیگر جدا کنیم، یک بردار را که تفاوت این دو بردار است، دریافت می کنیم؟ در نتیجه بردار موقعیت دوربین را از بردار منشوری صحنه بردارید و به این ترتیب بردار جهت می دهد. از آنجایی که ما میدانیم که دوربین به سمت جهت منفی z اشاره می کند، ما جهت vector را به سمت محور z مثبت دوربین می خواهیم. اگر ما دستور تقسیم را در اطراف ما تغییر دهیم، اکنون یک بردار را به سمت محور z مثبت دوربین منتقل می کنیم:


glm :: vec3 cameraTarget = glm :: vec3 (0.0f، 0.0f، 0.0f)؛
glm :: vec3 cameraDirection = glm :: normalize (cameraPos - cameraTarget)؛

نام بردار نام و نام خانوادگی بهترین انتخاب نیست، زیرا در واقع در جهت مع آنچه که هدف قرار دارد، اشاره دارد.
3. محور راست

بردار بعدی که ما نیاز داریم یک بردار راست است که نشان دهنده محور x مثبت فضای دوربین است. برای دریافت بردار راست ما با استفاده از یک ترفند کوچک با استفاده از یک بردار بالا که نقطه به سمت بالا (در فضای جهان) است، از یک ترفند کوچک استفاده می کنیم. سپس یک محصول متقابل بر روی بردار بالا و بردار جهت از مرحله 2 انجام می دهیم. از آنجا که نتیجه یک محصول متقابل یک بردار عمود بر هر دو بردار است، ما یک بردار را در جهت محور مثبت (اگر ما بردارهایی را که می خواهیم یک بردار را که در محور x منفی قرار دارد را تغییر دهیم):


glm :: vec3 بالا = glm :: vec3 (0.0f، 1.0f، 0.0f)؛
glm :: vec3 cameraRight = glm :: normalize (glm :: cross (up، cameraDirection))؛

4. محور بالا

حالا که هر دو بردار x محور و بردار محور z را داشته باشیم، بازیابی بردار که در محدوده ی مثبت y دوربین محاسبه می شود، نسبتا آسان است: محصول متقابل راست و بردار جهت:


glm :: vec3 cameraUp = glm :: cross (cameraDirection، cameraRight)؛

با کمک محصول متقابل و چند ترفند، ما توانستیم تمام بردارهایی را ایجاد کنیم که فضای view / camera را تشکیل می دهند. برای خوانندگان ریاضی بیشتر، این فرایند به عنوان فرآیند گرام Schmidt در جبر خطی شناخته می شود. با استفاده از این بردارهای دوربین ما می توانیم یک ماتریس LookAt ایجاد کنیم که برای ایجاد یک دوربین بسیار مفید است.
نگاه کن

چیز بزرگ در مورد ماتریس این است که اگر فضای مختصتی را با استفاده از 3 محور عمود بر (یا غیر خطی) تعریف کنید، می توانید یک ماتریس با آن 3 محور و یک بردار ترجمه ایجاد کنید و شما می توانید هر بردار را به آن فضای مختصات را با ضرب کردن آن با این ماتریس این دقیقا همان چیزی است که Matrix LookAt انجام می دهد و در حال حاضر 3 محور عمود بر محور و یک بردار موقعیت برای تعریف فضای دوربین ما می توانیم ماتریس LookAt خودمان را ایجاد کنیم: \ [LookAt = \ begin {bmatrix} \ color {red} {R_x} & \ color {قرمز} {R_y} & \ colo


English:
Part 01:


If you're running AdBlock, please consider whitelisting this site if you'd like to support LearnOpenGL; and no worries, I won't be mad if you don't :)

    Introduction
    Getting started
        OpenGL
        Creating a window
        Hello Window
        Hello Triangle
        Shaders
        Textures
        Transformations
        Coordinate Systems
        Camera
        Review
    Lighting
    Model Loading
    Advanced OpenGL
    Advanced Lighting
    PBR
    In Practice
    Offline book
    Code repository
    Translations
    About

Camera

In the previous tutorial we discussed the view matrix and how we can use the view matrix to move around the scene (we moved backwards a little). OpenGL by itself is not familiar with the concept of a camera, but we can try to simulate one by moving all objects in the scene in the reverse direction, giving the illusion that we are moving.

In this tutorial we'll discuss how we can set up a camera in OpenGL. We will discuss an FPS-style camera that allows you to freely move around in a 3D scene. In this tutorial we'll also discuss keyboard and mouse input and finish with a custom camera class.
Camera/View space

When we're talking about camera/view space we're talking about all the vertex coordinates as seen from the camera's perspective as the origin of the scene: the view matrix transforms all the world coordinates into view coordinates that are relative to the camera's position and direction. To define a camera we need its position in world space, the direction it's looking at, a vector pointing to the right and a vector pointing upwards from the camera. A careful reader might notice that we're actually going to create a coordinate system with 3 perpendicular unit axes with the camera's position as the origin.
1. Camera position

Getting a camera position is easy. The camera position is basically a vector in world space that points to the camera's position. We set the camera at the same position we've set the camera in the previous tutorial:


glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f); 

Don't forget that the positive z-axis is going through your screen towards you so if we want the camera to move backwards, we move along the positive z-axis.
2. Camera direction

The next vector required is the camera's direction e.g. at what direction it is pointing at. For now we let the camera point to the origin of our scene: (0,0,0). Remember that if we subtract two vectors from each other we get a vector that's the difference of these two vectors? Subtracting the camera position vector from the scene's origin vector thus results in the direction vector. Since we know that the camera points towards the negative z direction we want the direction vector to point towards the camera's positive z-axis. If we switch the subtraction order around we now get a vector pointing towards the camera's positive z-axis:


glm::vec3 cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 cameraDirection = glm::normalize(cameraPos - cameraTarget);

The name direction vector is not the best chosen name, since it is actually pointing in the reverse direction of what it is targeting.
3. Right axis

The next vector that we need is a right vector that represents the positive x-axis of the camera space. To get the right vector we use a little trick by first specifying an up vector that points upwards (in world space). Then we do a cross product on the up vector and the direction vector from step 2. Since the result of a cross product is a vector perpendicular to both vectors, we will get a vector that points in the positive x-axis's direction (if we would switch the vectors we'd get a vector that points in the negative x-axis):


glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraRight = glm::normalize(glm::cross(up, cameraDirection));

4. Up axis

Now that we have both the x-axis vector and the z-axis vector, retrieving the vector that points in the camera's positive y-axis is relatively easy: we take the cross product of the right and direction vector:


glm::vec3 cameraUp = glm::cross(cameraDirection, cameraRight);

With the help of the cross product and a few tricks we were able to create all the vectors that form the view/camera space. For the more mathematically inclined readers, this process is known as the Gram-Schmidt process in linear algebra. Using these camera vectors we can now create a LookAt matrix that proves very useful for creating a camera.
Look At

A great thing about matrices is that if you define a coordinate space using 3 perpendicular (or non-linear) axes you can create a matrix with those 3 axes plus a translation vector and you can transform any vector to that coordinate space by multiplying it with this matrix. This is exactly what the LookAt matrix does and now that we have 3 perpendiclar axes and a position vector to define the camera space we can create our own LookAt matrix: \[LookAt = \begin{bmatrix} \color{red}{R_x} & \color{red}{R_y} & \colo


تبلیغات

محل تبلیغات شما
محل تبلیغات شما محل تبلیغات شما

آخرین وبلاگ ها

آخرین جستجو ها

Alireza Hashemi یادداشتهای زهرا قربانی طراحی سایت، سئو، طراحی فروشگاه اینترنتی پهنه ی کویر Liz filmkhahan خدمات نوین درخت نارون AmirCode دل‌نوشته‌های حسین صیامی